SPOILER WARNING: Do not read if you have not seen “The Batman,” currently playing in theaters. This story discusses a major spoiler at the end of the movie.

When director Matt Reeves sat down to conceive his vision for “The Batman,” he wanted to embrace the idea from the comics that as Bruce Wayne (Robert Pattinson) found his footing as a costumed vigilante, he would inspire his eventual rogues gallery to take on their equally larger-than-life personas. Over the course of the film, that transformation commences for both villains — Paul Dano’s Riddler and Colin Farrell’s Penguin — as well as Batman’s quasi-partner in crimefighting, Selina Kyle (Zoë Kravitz), as she becomes Catwoman.

While Dano’s Riddler especially takes center stage in driving the story, Reeves also wanted to give audiences the feeling that other possible Batman villains could be lurking in the periphery, just out of the camera’s gaze.

“I thought it’d be really neat if so much of the fabric of Gotham just already existed,” Reeves tells Variety. “And it was like an old Warner Bros. gangster movie and if you took a certain turn, you might see a character in his origins.”

That feeling is no better demonstrated than in the penultimate scene of the movie, after Dano’s Riddler has been locked up in Arkham Asylum, struck by despair that his grand plan to destroy Gotham has been foiled by Batman. As he wails in anguish, a voice from the cell next to his whispers from the door.

“What is it they say?” the inmate says. “One day you’re on top. The next, you’re a clown.” As the camera pulls back, Riddler and the inmate dissolve into laughter and a new, wicked friendship is born.

The character, played by Barry Keoghan (“Eternals,” “The Killing of a Sacred Deer”), is credited as “Unseen Arkham Inmate.” But any astute Batman fan — or, for that matter, Batman neophyte — will know who this inmate is meant to be.

“You’re right,” Reeves says. “It is the Joker.”

While it may seem obvious that Reeves placed this scene at the end of “The Batman” to set up Keoghan as the lead villain for the inevitable sequel, the director was quick to explain that not only was that not his intention, he is in no way convinced that Keoghan’s Joker will appear in any more “Batman” movies.

“It’s not an Easter egg scene,” he says. “It’s not one of those end credits Marvel or DC scenes where it’s going, like, ‘Hey, here’s the next movie!’ In fact, I have no idea when or if we would return to that character in the movies.”

It turns out that Reeves’ had initially planned for Keoghan’s Joker to take a (slightly) bigger role in his film — only to almost cut Keoghan out of the movie entirely. Here’s everything the filmmaker had to say about the character and what his future could be within his “Batman” universe, including a possible HBO Max series about Arkham Asylum.

Lazy loaded image
Paul Dano in “The Batman.” Warner Bros. / Courtesy Everett Collection

“It’s Almost Our Anniversary, Isn’t It?”

In an early cut of “The Batman,” Keoghan actually showed up much earlier, in a scene following the revelation that the Riddler has killed the Gotham City police commissioner (before Jeffrey Wright’s Jim Gordon gets the job) and left behind yet another note addressed to the Batman. Between the Riddler’s notes casting an uncomfortable spotlight on Batman and the discovery that the Riddler is killing city leaders neck-deep in corruption, Batman finds himself unnerved over what to make of what the Riddler is doing.

“I thought he would be really insecure about this and he’d probably want to find some way to get into the [Riddler’s] mindset, like in ‘Manhunter’ or ‘Mindhunter’ — this idea of profiling somebody, so you can predict his next move,” says Reeves.

So Reeves shot a scene in which Batman snuck inside Arkham, arriving at the door of a specific inmate.

“And this guy says, ‘It’s almost our anniversary, isn’t it?'” says Reeves. “You realize that they have a relationship, and that this guy obviously did something, and Batman somehow got him into Arkham.”

As they talk, Batman tells Joker he wants to know how Riddler thinks. Joker’s reply, as relayed by Reeves: “What do you mean, you want to know how he thinks? You guys think the same.”

Reeves smiles. “What he’s really doing is getting into Batman’s head,” he says. “And [Batman] is resisting this idea violently. And so that’s what that scene was. It was a scene to unsettle him.”

Ultimately, however, Reeves felt that the scene hit the same beat accomplished elsewhere in the movie. So he cut it. “It wasn’t necessary,” he says. “It was one of those scenes where, given how complex the narrative was, by taking it out, it kept the story moving in a way it needed to.”

Lazy loaded image
Matt Reeves directs Robert Pattinson on the set of “The Batman.” Courtesy of Jonathan Olley/Warner Bros.

“This Place Is Never Going to Change”

Cutting the first Joker scene was so heartbreaking that Reeves intends to release it once enough people have seen “The Batman.”

“It’s a really creepy, cool scene,” he says. “That was the scene that was meant to introduce this guy and just to tease the audience to go like, ‘Oh my god, he’s here too? And he’s not yet the Joker — what’s this going to be?’ And then it seems so delicious in the story, since we’d already set him up, to have the end of the story, the completion of the Riddler arc, be that he was in a cell next to this guy.”

But when Reeves cut the first scene, he thought the second scene with the Riddler would need to go as well — cutting Keoghan out of the movie entirely. When he tested the movie, however, he realized that losing the Joker and Riddler’s meet creep (to tweak a common phrase) affected the final scene of the film — in which Selina implores Batman to leave Gotham with her, knowing he’s fated to stay and fight for his city.

“Because when Selena is saying to him, ‘This place is never going to change,’ you hadn’t seen that, in fact, trouble was already brewing,” Reeves says. “You kind of felt like, well, Couldn’t you just go with her? Go with her! What’s the problem? What’s wrong with you?! It changed the emotional stakes. It didn’t feel the same.” Reeves also didn’t like losing the final beat of the Riddler’s arc, in which, after a lifetime of neglect and isolation, he finally finds a compatriot — albeit a murderous psychopath.

So he put the Joker-Riddler scene back in. “I initially tested it without it; when I put it back in, the scores for the ending went back up,” he says. “And I think it wasn’t just that people enjoyed seeing that character. It changed people’s response to the very ending of the movie, to see that Gotham was still Gotham, and that Batman really didn’t have a choice. He has to keep doing what he’s gonna do.”

Reeves knows that introducing the Joker so close to the end of the movie will invariably lead audiences to expect to see more of him in the next film. But that was not anywhere close to his goal. “I never was trying to say like, ‘Hey, guess what, here’s the Joker. Next movie!'” he says. “The idea was more to say, ‘Hey, look, if you think that trouble is going to go away in Gotham, you can forget it. It’s already here. And it’s already delicious.'”

Lazy loaded image
Left: Conrad Veidt in “The Man Who Laughs”; right: Barry Keoghan. Courtesy Everett Collection; Provider: Evan Agostini/Invision/AP

“So a Joke Was Played on Me”

To keep an air of mystery, and reinforce the idea that this Joker hasn’t fully become the Joker, Reeves decided to shoot both of Keoghan’s scenes with the actor’s face obscured and partially out of focus. But he still worked with prosthetic makeup artist Michael Marino (“Coming 2 America”) to develop this Joker’s full look.

“I said, ‘The shape of his hair, the shape of his mouth, it’s all going to read, but it’s going to be soft,'” Reeves says of his conversation with Marino. “So he knew that was the canvas he had to deal with.”

With so many Jokers in cinema history, the trick was figuring out how to differentiate Keoghan’s look as the character from his predecessors. So Reeves and Marino turned to the original inspiration for the Joker: Conrad Veidt’s performance in the 1928 silent film “The Man Who Laughs,” based on a novel by Victor Hugo.

“It’s like ‘Phantom of the Opera,'” Reeves says. “He has a congenital disease where he can’t stop smiling and it’s horrific. His face is half-covered through most of the film.” While it’s barely perceptible in the movie, Marino’s makeup evoked Veidt’s, giving Keoghan an unceasing rictus grin.

Even for a character who has just minutes of screen time, Reeves wanted to ensure that his film’s Joker was imbued with a clear psychological motivation, so he also extrapolated what it would be like for a kid to be born with a condition in which he never stopped smiling.

“It’s not about some version where he falls into a vat of chemicals and his face is distorted, or what [Christopher] Nolan did, where there’s some mystery to how he got these scars carved into his face,” he says. “What if this guy from birth had this disease and he was cursed? He had this smile that people stared at that was grotesque and terrifying. Even as a child, people looked at him with horror, and his response was to say, ‘Okay, so a joke was played on me,’ and this was his nihilistic take on the world.”

Lazy loaded image

“I Was Looking for Somebody Who Was Fearless”

When Keoghan’s casting was announced, his character was presented as a Gotham City cop named Stanley Merkel who works with Jim Gordon.

“I didn’t want to call him the Joker,” Reeves says. “I wanted him to be this kind of lean forward thing for people who were fans to go like, ‘Oh my god, I think that’s the Joker. I think they’re doing the Joker.'” But Reeves also knew that if he announced Keoghan’s actual screen credit — “Unseen Arkham Inmate” — it wouldn’t take very long for fans to guess what he was up to.

“I didn’t want to create all this speculation that we were doing the Joker by naming what he was, so we thought, well, let’s make him be a cop, and then people won’t really think too hard about it,” he says. Alas, between leaks from test screenings and a cryptic Instagram post, the internet thought plenty hard about who Keoghan was playing well before “The Batman” debuted, and sleuthed out that he was, indeed, playing the Joker.

Whether Keoghan will keep playing the Joker remains an open question.

“There might be places,” Reeves says. “There’s stuff I’m very interested in doing in an Arkham space, potentially for HBO Max. There are things we’ve talked about there. So it’s very possible. It also isn’t impossible, that there is some story that comes back where Joker comes into our world.”

By the same token, Reeves is acutely aware of the many memorable performances actors have given as the Joker, including by Jack Nicholson, Mark Hamill, Jared Leto, and — earning them both Oscars — Heath Ledger and Joaquin Phoenix.

“We made a really concerted effort to make this different from the other ‘Batman’ movies, because we needed to,” he says. “It’s something to think about with the Joker. It’s been done well, a number of times.”

When Reeves met with Keoghan about playing the Joker, he says he told the actor about his concerns. “I said to Barry, right from the beginning, ‘Look, I don’t know where this is going to go. I can’t promise that it’ll even ever come back. I don’t know.’ And I still feel that way now. I’m not sure exactly.”

For that reason, Reeves wanted someone eager to take on the “high-wire act” of playing the Joker, even if the performance only ever ended up lasting a few scant minutes. “I was looking not only for somebody who was a good actor, but somebody who was fearless,” he says. “Joaquin, as we were making the movie, had just won the Oscar. They already thought you can’t do the Joker again after Heath Ledger. And then Joaquin comes in. So I can imagine an actor going like, ‘There’s nowhere to go but down!'”

Reeves chuckles. “Barry was full in. That, along with the fact that I loved him as an actor, was the deciding factor. And we did it.”

Whether they’ll ever do it again will have to remain a tantalizing riddle for now.