The idea for what would become Annie Hall was developed as Allen walked around New York City with co-writer Marshall Brickman. The pair discussed the project on alternate days, sometimes becoming frustrated and rejecting the idea. Allen wrote a first draft of a screenplay within a four-day period, sending it to Brickman to make alterations. According to Brickman, this draft centered on a man in his forties, someone whose life consisted "of several strands. One was a relationship with a young woman, another was a concern about the banality of life we all live, and a third an obsession with proving himself and testing himself to find out what kind of character he had." Allen himself turned forty in 1975, and Brickman suggests that "advancing age" and "worries about his death" had influenced Allen's philosophical, personal approach to complement his "commercial side". Allen made the conscious decision to "sacrifice some of the laughs for a story about human beings". He recognized that for the first time he had the courage to abandon the safety of complete broad comedy and had the will to produce a film of deeper meaning which would be a nourishing experience for the audience. He was also influenced by Federico Fellini's 1963 comedy-drama 8½, created at a similar personal turning point, and similarly colored by each director's psychoanalysis.
Brickman and Allen sent the screenplay back and forth until they were ready to ask United Artists for $4 million. Many elements from the early drafts did not survive. It was originally a drama centered on a murder mystery with a comic and romantic subplot. According to Allen, the murder occurred after a scene that remains in the film, the sequence in which Annie and Alvy miss the Ingmar Bergman film Face to Face. Although they decided to drop the murder plot, Allen and Brickman made a murder mystery many years later: 1993's Manhattan Murder Mystery, also starring Diane Keaton. The draft that Allen presented to the film's editor, Ralph Rosenblum, concluded with the words, "ending to be shot." It was "like a first draft of a novel ... from which two or three films could possibly be assembled," Rosenblum says. Allen suggested Anhedonia, a term for the inability to experience pleasure, as a working title, but United Artists considered this and Brickman's suggested alternatives: It Had to Be Jew, Rollercoaster Named Desire and Me and My Goy unmarketable. An advertising agency, hired by UA, embraced Allen's choice of an obscure word by suggesting advertising in tabloid newspapers using vague slogans such as "Anhedonia Strikes Cleveland". However, Allen experimented with several titles over five test screenings, including Anxiety and Alvy and Me, before settling on Annie Hall.
Several references in the film to Allen's own life have invited speculation that it is autobiographical. Both Alvy and Allen were comedians. His birthday appears on the blackboard in a school scene; certain features of his childhood are found in Alvy Singer's; Allen went to New York University and so did Alvy. Diane Keaton's real surname is "Hall" and "Annie" was her nickname, and she and Allen were once romantically involved. However, Allen is quick to dispel these suggestions. "The stuff that people insist is autobiographical is almost invariably not," Allen said. "It's so exaggerated that it's virtually meaningless to the people upon whom these little nuances are based. People got it into their heads that Annie Hall was autobiographical, and I couldn't convince them it wasn't". Contrary to various interviewers and commentators, he says, Alvy is not the character that is closest to himself; he identified more with the mother (Eve, played by Geraldine Page) in his next film, Interiors. Despite this, Keaton has stated that the relationship between Alvy and Annie was partly based on her relationship with the director.
The role of Annie Hall was written specifically for Keaton, who had worked with Allen on Play It Again, Sam (1972), Sleeper (1973) and Love and Death (1975). She considered the character an "affable version" of herself—both were "semi-articulate, dreamed of being a singer and suffered from insecurity"—and was surprised to win an Oscar for her performance. The film also marks the second film collaboration between Allen and Tony Roberts, their previous project being Play It Again, Sam.
Federico Fellini was Allen's first choice to appear in the cinema lobby scene because his films were under discussion, but Allen chose cultural academic Marshall McLuhan after both Fellini and Luis Buñuel declined the cameo. Some cast members, Baxter claims, were aggrieved at Allen's treatment of them. The director "acted coldly" towards McLuhan, who had to return from Canada for reshooting, and Mordecai Lawner, who played Alvy's father, claimed that Allen never spoke to him. However, during the production, Allen began a two-year relationship with Stacey Nelkin, who appears in a single scene.
Filming, editing and music
Principal photography began on 19 May 1976 on the South Fork of Long Island with the scene in which Alvy and Annie boil live lobsters; filming continued periodically for the next ten months, and deviated frequently from the screenplay. There was nothing written about Alvy's childhood home lying under a roller coaster, but when Allen was scouting locations in Brooklyn with Willis and art director Mel Bourne, he "saw this roller-coaster, and ... saw the house under it. And I thought, we have to use this." Similarly, there is the incident where Alvy scatters a trove of cocaine with an accidental sneeze: although not in the script, the joke emerged from a rehearsal happenstance and stayed in the movie. In audience testing, this laugh was so big that a re-edit had to add a hold so that the following dialogue was not lost.
Rosenblum's first assembly of the film in 1976 left Brickman disappointed. At two hours and twenty minutes, it dwelt "on issues just touched in passing in the version we know", featuring the "surrealistic and abstract adventures of a neurotic Jewish comedian who was reliving his highly flawed life and in the process satirizing much of our culture, ... a visual monologue, a more sophisticated and visual version of Take the Money and Run". Annie Hall herself didn't stand out, and Brickman found it "nondramatic and ultimately uninteresting, a kind of cerebral exercise." He suggested a more linear narrative. Fortunately, the shooting schedule was budgeted for two weeks of post-production photography, so even though the first cut had "some of the free-est, funniest and most sophisticated material that Woody had ever created, and it hurt him to lose it", late 1976 saw three separate shoots for the final segment, two of which appear in some form. One featured Annie Hall taking her new boyfriend to The Sorrow and the Pity, which she had reluctantly seen with Alvy; the other, Alvy's monologue featuring the joke about 'we all need the eggs', was conceived during a cab journey to an early preview.
The credits call the film "A Jack Rollins and Charles H. Joffe Production"; the two men were Allen's managers and received this same credit on his films from 1969 to 1993. However, for this film Joffe took producer credit and therefore received the Academy Award for Best Picture. The title sequence features a black background with white text in the Windsor Light Condensed typeface, a design that Allen would use on his subsequent films. Stig Björkman sees some similarity to Ingmar Bergman's simple and consistent title design, although Allen says that his own choice is a cost-saving device.
Very little background music is heard in the film, a departure for Allen influenced by Ingmar Bergman. Diane Keaton performs twice in the jazz club: "It Had to be You" and "Seems Like Old Times" (the latter reprises in voiceover on the closing scene). The other exceptions include a boy's choir "Christmas Medley" played while the characters drive through Los Angeles, the Molto allegro from Mozart's Jupiter Symphony (heard as Annie and Alvy drive through the countryside), Tommy Dorsey's performance of "Sleepy Lagoon", and the anodyne cover of the Savoy Brown song "A Hard Way to Go" playing at a party in the mansion of Paul Simon's character.