The writing process for Miranda begins with a vast amount of material: Miranda comes up with scenes, jokes, themes and ideas for plots, and writes them all on flip chart paper which is pinned up on the walls of an office. Then the first cohort of her writing team - me and James Cary - spend several weeks drawing those elements together into coherent plots, and then fitting the plots together into detailed plans for episodes. It's a demanding, technical process that involves us going, 'hey, would it be funny if x happened?' and then laughing a lot at our own jokes before spending half an hour discussing lunch.
Episode five was always going to be different: it's our little experiment. It started out as an idea for a single scene: a psychiatrist's appointment that's not an appointment. In series one we'd talked about doing a single set real-time episode and we quickly realised that this was the idea that could make that happen.
Writing with a performer is different to co-writing with another writer. You can never forget that the person sitting in the room with you has (and has to have) an absolute veto on anything you come up with. There's no way that they're going to get in front of a camera and say something that they're not convinced is funny. And in Miranda that's doubly true: within the show we see the world through her character's eyes: she's in every scene and almost nothing happens that she doesn't witness. We also tend to pack episodes with as much story as possible at this initial stage, but an episode like this will always be pretty light on plot. So, when James and I said 'this scene could fill a whole episode', we had to convince Miranda (and ourselves!) that we had enough material to fill it.
We transferred everything that felt like it could go into Psychiatrist (as we cleverly named it) onto post-it notes and stuck them to a big board. 'Sending text to wrong person', for example, was something that could have gone anywhere but found a home here. We liked the idea that the psychiatrist didn't speak for ages, so that became a sort of anchor point around a third of the way through, and the movement from Miranda and Penny working together to them working against each other to them uniting against Anthony gave us a structure that we could then drop jokes into. The post-its got picked, attached, moved around, removed, discussed and returned into position until they felt like they progressed logically, and off it went for a first draft. After some lunch.
Miranda usually uses flashbacks and cutaways for jokes, but instinctively we felt that this would slow the pace of the episode. They got written just in case, but when heard the script for the first time at the readthrough we all realised that we didn't need them: the fantasy sequences with Gary keep the tone of the show consistent without taking us outside our set. So James and I spent an enjoyable couple of days giving the script a bit of a polish - more jokes and a bit of reordering - based on what we'd heard, before handing it back to Miranda for another draft before rehearsals.
I'm writing this before seeing the finished show: only when it goes out will the audience will be able to decide whether our little experiment has worked.
Watch Miranda: Series 2, Episode 5 back on BBC iPlayer.
Read an earlier interview from BBC writersroom with Miranda Hart.