It’s the rare star who covers for his own understudy. But Lin-Manuel Miranda did just that when Javier Muñoz, his alternate in “Hamilton,” missed a Sunday matinee.

Considering Sunday matinees are the only shows Muñoz plays, you may wonder what kept him away.

Blame it on cancer.

“I was diagnosed in October,” Muñoz tells The Post. “I spent about six weeks not wanting to think about it, face, it, deal with it.” Even now, he’d rather not say exactly what cancer he’s up against, only that “I had never felt fear before like this in my life.”

For weeks, the 40-year-old says, he said nothing. “I’d just call out [sick] or push through,” says the slender, goateed Muñoz, whose job includes observing every “Hamilton” performance for any new nuances, and to go on for Miranda if needed. (Good luck with that, Muñoz says: “Lin’s such a workhorse — if both his legs fell off, he’d wheel himself out there!”)

But in November, Muñoz did what he had to do: He left the show to undergo surgery, followed by radiation treatments that depleted him, then physical therapy to get him strong enough to take the stage.

All told, he missed two months of Sundays, in which cast member Jon Rua often went on in his stead.

Another show might have gone on with an alternate understudy. Not “Hamilton.”

“There was no thought at all about [replacing him],” says Thomas Kail, the director of both “Hamilton” and “In the Heights,” the 2008 Tony winner in which Muñoz also alternated with Miranda.

“Javi’s someone who has given so much,” Kail continues. “Now we wanted to make sure he had what he needed to be well, and to know he wasn’t alone.”

‘I was diagnosed in October. I spent about six weeks not wanting to think about it, face it, deal with it.’ - Javier Muñoz on having cancer

He wasn’t.

“God bless Leslie Odom Jr.!” Muñoz says. His eyes fill with tears as he recalls how the man who plays Aaron Burr, Hamilton’s frenemy, organized a food drive: Meals, paid for by members of the cast, arrived at Muñoz’s Astoria apartment every day.

And, yes, his parents were there for him — and knew just what he was up against: Some 12 years ago, within a period of six months, they were both diagnosed with cancer. Muñoz took a year off from acting and auditioning to take a day job, moving back into his boyhood home in Brooklyn to help with meals, laundry and doctor appointments.

Happily, his parents recovered, and on Feb. 14 celebrated their 56th anniversary by watching their son star in “Hamilton.” That day, just five weeks after his last radiation treatment, Muñoz showed why some fans call him “the sexy Hamilton.”

Though he’s tailored his Alexander on Miranda’s, Muñoz brings an edgy intensity to the role. Miranda’s puppy-dog-eyed Alexander is someone you’d proudly introduce to your parents; Muñoz’s is someone you’d sneak up the back stairs.

Then again, any comparisons between the two make him uncomfortable. “We work so hard and so well together that, in my mind, I find it almost impossible to separate our versions,” he says. (Well, maybe Mel Brooks can — or thinks he can. Muñoz says the “2,000-Year-Old Man” came backstage one Sunday and said, “So you’re better than him, right? Yeah, yeah, so he’s the writer, but you’re better!”)

As far as Kail’s concerned, Miranda’s created a role that’s bigger than he is.

“Javi’s not the alternate — he is Hamilton on Sundays,” the director says.

Adds Renée Elise Goldsberry, the show’s Angelica Schuyler, Hamilton’s sister-in-law and intellectual equal: “To understudy or standby takes a tremendous amount of humility.

“It’s a very supportive role. [But] when Javi goes on, that’s a lion going on, jumping headfirst into the battle. Javi proves that both sides — supporting and alpha male — exist. And he does it brilliantly.”