READ MORE:In Face The Raven, the Doctor (Peter Capaldi), Clara and their old friend Rigsy (Joivan Wade) find themselves in a secret alien world, folded away among the streets of London.
After months of speculation, the BBC confirmed in September that 29-year-old Coleman would depart during this ninth series.
Executive producer Steven Moffat revealed: "She left several times."
He continued: "I wrote her out in Death In Heaven at the end of episode 12 last year. All that was meant to be the last time we saw her.
"And then at the last minute she said she'd like to do Christmas, which I'd already half written so I had to reverse rapidly and write it again with Clara in it and then write her out at the end of that episode."
However, he acknowledged series nine was written with her departure in mind.
The Time Lord's brave and resourceful Clara made her first appearance opposite Matt Smith's Doctor in 2012 episode Asylum Of The Daleks.
Coleman replaced Karen Gillan, who made her name as sidekick Amy Pond, and went on to star alongside Peter Capaldi's Doctor.
She bows out after three years as the longest-serving companion since the show was rebooted in 2005.
'Doctor Who' is broadcast at 8.10pm on BBC One.