The Doctor asks Captain Kathryn Janeway to alter his program to allow him to captain the ship if an emergency occurs. Janeway refuses the request. Despite this, the Doctor alters his own sub-routines, allowing him to daydream, while Voyager is traveling through an apparently harmless nebula. Among other ego-fulfilling fantasies, the daydreams include one where he becomes the "Emergency Command Hologram" and defeats an attacking alien vessel using a fictional deadly photonic cannon. The Doctor finds that his daydreams are occurring when he doesn't want them to, a side effect of his faulty programming, and the crew disables the new routines.
Meanwhile, undetected by Voyager, the crew of an observation ship of the Hierarchy species has been monitoring Voyager's passage. As they have done with other ships that pass through the nebula, the Hierarchy determines whether there is any value on the ships, and if so, attacks them. They are unable to scan Voyager via normal means, and instead use a microscopic tunneling scan. This latches onto the Doctor's program, allowing them to witness events experienced by the hologram, though they are unaware of where reality stops and the Doctor's fantasies begin. Though the Hierarchy's crewman Phlox soon realizes their mistake, the Hierarchy has already issued the command to attack Voyager for their anti-matter reserves.
Phlox uses the tunneling scan to reactivate the Doctor's daydreaming programs to allow him to communicate with the hologram. Phlox explains the situation to the Doctor, who in turn reports this to Janeway. As Voyager's crew becomes aware of the approaching Hierarchy ships, Janeway arranges for the deception to be complete, temporarily turning the Doctor into the Emergency Command Hologram. The Doctor, less confident in reality than his daydreams, is still able to bluff regarding use of the photonic cannon and the Hierarchy quickly retreats. Janeway commends the Doctor for his performance and arranges a team to evaluate the prospects of putting the hologram in charge of the ship under emergency situations.
The episode was originally titled "The Secret Life of Neelix" and was intended to be a story about when Neelix's daydreams take on a life of their own when aliens become involved. However it was shifted around and rewritten to become a story involving the Doctor. The premise is based on the short story The Secret Life of Walter Mitty by James Thurber in which Walter Mitty daydreams heroic adventures while running an errand for his wife. The title of this episode is a reference to the 1974 spy novel Tinker, Tailor, Soldier, Spy by John le Carré.
Writer Joe Menosky describes the episode as "five days of scriptwriting paradise" because "the story itself becomes your friend and collaborator; it is rich enough to support you and keep feeding you ideas as you execute the script." During the writing of the script, Joe Menosky asked actor Robert Picardo for "a list of what the Doctor's fantasies might be. Needless to say, a life drawing of Seven of Nine was the first suggestion made."
Actor Robert Picardo described the filming of the episode as "the most fun I've had in shooting the entire series ... It was great fun and one of our most successful outings at humor on our show."
The episode is a significant departure from typical Voyager episodes due to the story's extensive use of comedic elements, making it a favorite among many viewers. It has been cited as "most entertaining episode of the season to date, and a Voyager classic."