The day she nervously told her boss that they needed to talk in the summer of 2012, the young intelligence analyst was mindful of the ordeal of the transgender woman at the Central Intelligence Agency who came before her. The story had become C.I.A. lore. In the late 1980s, a standout senior analyst who became the butt of jokes when she came out resigned after enduring months of cruel glances and crude remarks.

Jenny, the young officer, who is a Middle East expert, hadn’t heard yet about Diane Schroer, the former Army officer who set an important legal precedent for transgender federal employees by suing the Library of Congress in 2005. She didn’t know what, if any, legal protections and benefits transgender employees at the C.I.A. were entitled to.

All she knew with certainty was that going through life as a man had become unbearable.

“I was terrified,” she said in an interview, which the C.I.A. arranged on condition that she be identified as Jenny, an alias for the undercover officer. “I wasn’t sure if I transitioned, whether I would have a career. Maybe I would be here, but marginalized, and no one would take me seriously again.”