Charlie Sheen will get full custody of his teenage twins if his ex-wife Brooke Mueller fails a drug test, according to court documents obtained by Page Six.

The “Two and a Half Men” star was granted an emergency request Thursday that states he will “immediately” assume “sole legal custody” of his 14-year-old sons, Bob and Max, “in the event Brooke tests positive for drugs or alcohol.”

“Brooke shall test for drugs and alcohol (1) as often as required by her probation officer, (2) within 24 hours of a written request (email or text) from Charlie or his attorney, and (3) at a minimum of once per week regardless,” the order reads.

The documents state that Mueller’s “custody/visitation will be terminated immediately following any positive test,” and any “missed test will be considered a positive test.”

Mueller also will have to hand over the “names, addresses and telephone numbers for all her regular, historic sources of controlled substances” to Sheen’s attorney.

Charlie Sheen posing for a photo

Charlie Sheen will get full custody of his kids if ex-wife Brooke Mueller fails a drug test.Dave Benett/Getty Images for Annabel’s

Charlie Sheen and Brooke Mueller posing

“In the event Brooke tests positive for drugs or alcohol,” Sheen will obtain “sole legal custody” of Bob and Max “immediately,” according to court documents.FilmMagic

Brooke Mueller and Charlie Sheen posing

Mueller will be tested at least once a week.WireImage

Sheen, 58, and Mueller, 46, previously agreed to the stipulations in formal documents in November 2022 and August 2023, but the actor was given permission to file an ex parte motion, which means it can be granted without his ex’s response.

Both Sheen and Mueller have battled addiction, but he recently celebrated six years of sobriety.

The “Anger Management” star did not specify in the documents why he chose to request the modifications Thursday.

Charlie Sheen posing with his two kids

The “Two and a Half Men” star revealed his ex relapsed in 2023.WireImage

However, the court papers reveal Sheen and Mueller signed the second August 2023 child custody modification just one month after she “relapsed and engaged in abusing alcohol and controlled substances.”

Mueller’s rep had no comment.

Sheen has not publicly addressed the filing, but he enforced the stipulations just one month after telling People that he considers himself a “single dad.”

“I’ve mostly been raising my 14-year-old boys,” he told the magazine on Dec. 11. “Their mom has been trying to figure some stuff out on her end, so she’s not in the picture too much right now.”

Charlie Sheen's sons sitting

Sheen recently described himself as a “single dad” to Bob and Max.Page Six

Brooke Mueller posing with her sons

Sources told Page Six in December that Mueller was in a 12-step program for addiction.Paul Bruinooge/Patrick McMullan via Getty Images. 

Shortly after, Page Six broke the news that Mueller was prioritizing a 12-step program to help her addiction.

“She really likes it,” a source told us at the time. “It seems to be working for her.”

Sheen and Mueller tied the knot in 2008, but he filed for divorce in 2010.