– Octavio Chaidez was walking out of a Pasadena courtroom with a client last month when four men jumped up from a hallway bench and rushed toward them.

The men asked his client’s name. Then they pulled out badges.

“They say, ‘You’re Mr. So and So?’ and he says, ‘Yes,’ ” Chaidez said. “They show him a badge, and they say, ‘We’re from Immigration and Customs,’ and they took him in.”

Chaidez, who has worked as a defense attorney in Los Angeles County for nearly 15 years, said he had never seen federal Immigration and Customs Enforcement agents make an arrest inside a courthouse.

But in the last few weeks, attorneys and prosecutors in California, Arizona, Texas and Colorado have all reported teams of ICE agents — some in uniform, some not — sweeping into courtrooms or lurking outside court complexes, waiting to arrest immigrants who are in the country illegally.

On Thursday, the California chief justice asked the Trump administration to stop immigration agents from “stalking” the state’s courthouses to make arrests.

“Courthouses should not be used as bait in the necessary enforcement of our country’s immigration laws,” Tani Cantil-Sakauye wrote in a letter to Attorney General Jeff Sessions and Homeland Security Secretary John Kelly. “Enforcement policies that include stalking courthouses and arresting undocumented immigrants, the vast majority of whom pose no risk to public safety, are neither safe nor fair.”

ICE officials have defended the tactic, saying they make arrests in courthouses only when all other options have been exhausted. But activists, attorneys and prosecutors fear ICE’s increased presence in courthouses could deter other immigrants without legal status from appearing in court to testify as witnesses or answer warrants, which ultimately could endanger prosecutions.

San Francisco District Attorney George Gascon called ICE’s forays into courthouses “very shortsighted” because some immigrants here illegally will simply avoid court for fear of being arrested.

“The chilling impact that has on an entire community is devastating,” he said.

ICE directs its agents to avoid making arrests in “sensitive locations,” including schools, places of worship and hospitals, whenever possible, said Virginia Kice, an agency spokeswoman. That policy does not cover courthouses, Kice said, although agents normally will try to detain people at other locations before entering a courtroom. ICE’s recent action in courthouses has been, in part, driven by an increase in the number of local law enforcement agencies that refuse to comply with ICE requests to detain suspects in county jails, she said.

“In years past, most of these individuals would have been turned over to ICE by local authorities upon their release from jail based on ICE detainers,” Kice said. “Now that many law enforcement agencies no longer honor ICE detainers, these individuals, who often have significant criminal histories, are released onto the street, presenting a potential public safety threat.”

ICE has made arrests in courthouses before, but the tactic drew strong rebukes in California after a series of raids led to the capture of women seeking restraining orders, people paying parking tickets and even one couple getting married inside a Kern County courthouse in 2013, according to the American Civil Liberties Union.

ICE eventually stopped the practice, but activists fear the recent courthouse arrests reflect the more aggressive stance taken by ICE and other immigration enforcement agents since President Trump’s election after a campaign that focused largely on illegal immigration.

There are tactical advantages for agents with courthouse arrests, Kice said.

Suspects have to pass through metal detectors before entering courthouses, meaning they are unlikely to be armed. In recent months, ICE has arrested several suspects in courthouses in Portland, Ore., and Southern California who had prior convictions for sex crimes, drug trafficking and drunken driving, she said. The suspect who was arrested in the Pasadena courthouse last month was a Mexican national with a prior drug conviction, Kice said.

Although some of the courthouse arrests were of people with violent pasts, others have focused on different segments of the immigrant population. On Feb. 9, a woman who had accused her husband of abuse was arrested while seeking a restraining order in an El Paso courthouse, said Lucila Flores Camarena, an assistant county attorney in El Paso who oversees the agency’s protective order unit. An undercover ICE agent was seated behind the woman, according to Flores Camarena, who said other women seeking protective orders also were in the courtroom. Agents ultimately arrested the woman, Irvin Gonzalez Torres, outside the courtroom.

This month, Denver City Attorney Kristin Bronson also told several media outlets that she had to dismiss prosecutions against four domestic violence suspects because the witnesses, all of whom are in the country illegally, were afraid ICE might thereby find them.