Updated

In the days before the Benghazi attacks, the Libyan militant now in U.S. custody voiced concern and opposition to the presence of an American compound in Benghazi, the government said Tuesday in a court filing.

Ahmed Abu Khattala was motivated to participate in the violence by his extremist ideology, according to a court filing by the U.S. Attorney's Office.

On Wednesday, Khattala is to appear at a detention hearing before Magistrate Judge Deborah Robinson in U.S. District Court.

In court papers, prosecutors spelled out why Khattala should remain in detention.

After U.S personnel evacuated the U.S. diplomatic mission in Benghazi, Libya, Khattala entered the compound and supervised the exploitation of material at the scene, the government said.

Khattala then returned to a camp in Benghazi controlled by Ansar al-Shariah, where a large armed group began assembling for an attack on the compound's annex, according to the court papers.

The State Department has designated Ansar al-Shariah as a foreign terrorist organization.

Khattala, the court papers added, is a commander of Abu Obaida bin Jarrah Brigade, an extremist group that was absorbed into Ansar al-Sharia after the recent Libyan revolution.

Ansar al-Shariah is an Islamic extremist militia in Libya that holds anti-Western views and advocates the establishment of Shariah law in Libya.

Fires that were set during the Sept. 11, 2012, attack on the U.S. mission in Benghazi led to the deaths of Ambassador J. Christopher Stevens and Information Management Officer Sean Patrick Smith.

Remaining State Department personnel were able to escape to a nearby U.S. facility known as the annex. It also came under attack and a precision mortar barrage resulted in the deaths of security officers Tyrone Snowden Woods and Glen Anthony Doherty.

Khattala is the first person to be prosecuted in the attack. His expected trial will take place alongside ongoing congressional and Justice Department investigations into the attack and the Obama administration's response to it shortly before the 2012 elections.