Pre-production
In January 2020, Marvel Studios and Derrickson announced that he would no longer direct the film due to creative differences. In separate statements, they both said they were thankful for their collaboration so far and Derrickson would remain an executive producer on the film. This was not expected to delay filming, which was set for May 2020. Cargill explained that he and Derrickson conceived a story that went in a different direction from what Marvel wanted, and the pair had not yet written a draft of the screenplay so the final film would not be derivative of their work. Derrickson said leaving the film was a difficult decision, but he did not want to compromise on a film that was different from what he wanted to make. His choice to leave was made easier by the fact that he was able to immediately begin work on The Black Phone (2022), another film he wanted to make. Cumberbatch was not consulted regarding the director change and said he was sad to hear about it, but he respected the decision and how it was handled. Some reports suggested that Derrickson left the film because he wanted to make a "no-holds-barred weird, gnarly, scary movie" similar to A24's films The Witch (2015) or Hereditary (2018), and Marvel Studios did not want to go in that direction, but Feige denied this and said the studio loved that idea. He explained that it was their intention for the film to serve as a guide into a "much creepier side" of the MCU, even after Derrickson's departure, and they wanted to explore the "mind-bending frightening side" of the multiverse.
Sam Raimi entered negotiations to take over as director by early February. At that time, Chiwetel Ejiofor was expected to reprise his role as Karl Mordo, McAdams was no longer expected to appear, and Michael Waldron was hired to rewrite the film's script after serving as the head writer of Loki's first season. Raimi signed on to direct the film a few weeks later. He had been reluctant to direct another Marvel superhero film after the mixed critical reaction to Spider-Man 3 (2007), feeling that he needed a break from that genre, but he accepted the job because of the challenge of getting the film into production right away and because he was a fan of the Doctor Strange character and Derrickson's work on the first film. Raimi was curious how making big-budgeted films had changed since his prior film, Oz the Great and Powerful (2013), and he also had to familiarize himself with the existing MCU storylines and characters for the film. Waldron had three weeks to write a new script draft based on the work done by Derrickson and Bartlett. He said this was "almost impossible", and Raimi felt "very rushed and panicked" trying to meet the May 2020 production start date. The COVID-19 pandemic began to impact film productions during those first three weeks, and pre-production started taking place remotely. Filming was initially still on track to begin in May 2020, until Disney shifted much of their Phase Four slate of films due to the pandemic, moving Multiverse of Madness's release date to November 5, 2021. Raimi was relieved by this delay, which allowed him and Waldron to start writing the script from scratch in a reasonable time, and make the film their own. Bartlett had written a draft before the COVID-19 pandemic and said that Raimi and Waldron's version was different from the one she developed with Derrickson.
Waldron watched the director's Spider-Man films (2002–2007) so he could identify Raimi's strengths and write toward them. He described Multiverse of Madness as Raimi's return to "big superhero movies", and said it would have every aspect of a Sam Raimi film, including a "slightly scarier direction" which he felt Raimi had a strong track record with. Palmer said Waldron's work introducing the multiverse in Loki allowed Marvel Studios to "jump into telling a good story" without having to re-explain those ideas for the audience, and helped bring "a lot of heart to [the science fiction] concepts". Waldron also used his experience from writing the series Rick and Morty (2013–present), which helped him "introduce these big sci-fi concepts in ways that were digestible, palatable to the audience and without getting them bogged down in the boring details". Rather than just expanding the stakes of the film, Waldron saw the multiverse as the "emotional heart" of the story that could be used in personal ways, such as using "what ifs" and alternate versions of characters to reflect on the film's protagonists, and exploring the characters' right or wrong choices through their alternate versions. Waldron watched Doctor Strange several times, saying he became a "student" of that film, to understand Strange's story in the original. He also looked at how the character had developed through his other MCU appearances, and Raimi praised how Waldron's imagination and knowledge of Marvel history contributed to the script. The creative team saw early production work for the Disney+ animated series What If...? (2021–2024) to learn how Strange was portrayed in that series.
Waldron described Wanda as "the biggest best bullet" that they had, and said she was destined to become a villain in the MCU, as she did in the comics, especially after the end of WandaVision revealed "to her that the family she's built is not real. Then she gets the Darkhold... and learns that there is a real version of her children out there. And if you've got the Book of the Damned whispering in your ear long enough that your kids are out there and you could go get 'em, maybe that can push you to do some terrible things." If she became a villain at the end of the film, he knew another project would get to have the "fun" of using her as a villain. He also wanted to avoid the film getting "overstuffed" by adding a different multiverse-related villain such as Jonathan Majors's Kang the Conqueror, and felt that this would create a "watered-down version of Wanda [who] wouldn't be the protagonist, and she wouldn't really be the antagonist". Olsen was hesitant about playing the villain after believing that she would just be "in an ensemble thing", but she came to feel that the combination of WandaVision and Multiverse of Madness allowed her to create a sympathetic character in the series who the audience would therefore have conflicted feelings about when seeing the film. Waldron worked closely with Olsen and WandaVision head writer Jac Schaeffer to ensure Wanda's story was a satisfying continuation of the series, which Waldron read the scripts for and watched in its entirety while writing the script. He wanted to mirror Wanda's struggles with control following the events of that series with Strange's own need for control following Infinity War and Endgame. Raimi also studied the series despite not fully seeing it, particularly key moments that directly impacted their plans for the film, to make sure the film maintained "a proper through line and character-growth dynamic" for her character. It was important to Olsen that the film not repeat what was done in WandaVision and instead be an evolution of the character, and she requested several adjustments to the script to avoid moments that she found too similar to the series. To justify the many killings that Wanda commits in the film, Olsen focused on the character's perspective of those people being in her way and not listening to her after the loss of her children in the series.
After a planned appearance by Cumberbatch in WandaVision was removed late in the development of the series, rewrites to the Multiverse of Madness script were required which Feige described as a "wonderful combination of very dedicated coordination, and chaos". These changes include how Strange and Wanda meet in the film. The story of Multiverse of Madness is still set up by WandaVision, but the film was developed to also work for viewers who did not watch the series. For consistency with the Darkhold's appearance, the film's props department designed the prop that was used for WandaVision and then reused it for the film. While writing his first draft, Waldron felt the film needed to "get drunk [and] find the madness in the multiverse" by introducing alternate universe versions of known Marvel characters. This led to the introduction of the Illuminati, a secret society from the comics. Waldron had been watching the film Aliens (1986) as inspiration for the script's thriller tone, and enjoyed how the "badass" space marines "just get slaughtered" by the titular aliens to set the latter up as scarier villains for the rest of that film. He wanted to do something similar with Wanda by introducing the Illuminati as a group of characters that fans would be excited to see and then have Wanda kill them all. The idea of Strange taking control of a dead body for the end of the film came from Waldron and Palmer discussing how he would be able to confront Wanda from a different universe, with the corpse of another version of Strange having been already established at the start of the film. Raimi, Feige, and Cumberbatch were all excited about the idea, despite Raimi initially wanting to avoid a zombie sequence to not repeat what he had done previously with zombie films.
The film's release was shifted again at the end of April 2020, this time to March 25, 2022, after Sony Pictures rescheduled No Way Home to the November 2021 date. Until then, Waldron had been writing the script expecting Multiverse of Madness to be released before No Way Home. He was in contact with No Way Home writers Chris McKenna and Erik Sommers throughout the writing process, and after the release date change they adjusted their respective scripts so instead of Multiverse of Madness "blowing the lid on the multiverse" it would pick up after No Way Home with Strange already having multiverse experience. This change had a "knock-down effect" on the rest of the script. There had been early plans to include Strange's new costume from Multiverse of Madness and America Chavez in No Way Home, while a brief cameo of Peter Parker / Spider-Man was planned for Multiverse of Madness, but the pandemic ultimately prevented those plans from coming to fruition. Raimi noted that where No Way Home saw characters from other universes enter the MCU, Multiverse of Madness features characters from the MCU entering the multiverse and exploring different universes. Ejiofor confirmed his involvement in June, and Xochitl Gomez joined the cast in October. Cumberbatch revealed that month that filming would start in London by the beginning of November, with the production not impacted by a national lockdown in England that was set for November 5 to December 2 due to increased COVID-19 cases.