President Donald Trump wants transgender individuals to go back in the closet to join the military. In a long-awaited directive that followed up on a series of tweets he wrote last month on the issue, Trump ordered the military to stop accepting transgender men and women as recruits. He also prohibited the use of government funds for sex-reassignment surgeries for active duty personnel unless the process has already begun and stopping it would put the individual’s health at risk.

While issuing a complete ban on transgender individuals joining the military, the directive also gives Defense Secretary Jim Mattis the discretion to decide whether those who are already in the armed forces can continue serving in the military. Trump also left a bit of leeway, making clear he is open to changing his mind. The directive notes that the ban on new transgender troops will stay in place until Mattis, in consultation with the secretary of Homeland Security, “provides a recommendation to the contrary that I find convincing.”

Mattis now has six months to lay out a plan to implement Trump’s policy, weighing issues such as “military effectiveness and lethality, budgetary constraints, and applicable law.”

Sen. John McCain spoke up shortly after Trump’s directive, saying that pushing transgender individuals out of the military would be the wrong move. “It would be a step in the wrong direction to force currently serving transgender individuals to leave the military solely on the basis of their gender identity rather than medical and readiness standards that should always be at the heart of Department of Defense personnel policy,” McCain said.

Mattis had already delayed full implementation of President Obama’s June 2016 directive allowing transgender troops into the military, saying he was waiting for research on the issue. There are an estimated 2,000 to 11,000 active duty and reserve troops who are transgender, according to a RAND Corporation study. But Trump suggested his predecessor failed to think through the issue of whether allowing transgender individuals to serve opently would “hinder military effectiveness and lethality, disrupt unit cohesion, or tax military resources.”

RAND has said providing gender transition-related coverage would increase the military’s health care spending by somewhere between 0.04 percent and 0.13 percent, or anywhere between $2.4 million to $8.4 million a year. But discharging thousands of transgender troops could cost hundreds of millions of dollars, according to a study by the Palm Center, which lobbied to lift the ban on transgender troops.

Human rights advocates and active-duty transgender troops harshly criticized the president’ directive, saying he was using the argument about military readiness to push forward a discriminatory agenda.

“Imagine, if you would, if the president tried to pull the same prank on Jewish soldiers or gay and lesbian soldiers or Chinese soldiers or African-American soldiers,” said Aaron Belkin, the director of the Palm Center. “To pull the rug out from under a group of service members who have been defending our country is inconsistent with two centuries of American history.”