Writers write what they know — and TV writers know Hollywood. Three comedies — FX’s “The Comedians,” HBO’s “The Comeback” and Showtime’s “Episodes” — took dead aim at the industry this past season and invited the rest of the world to join in.

Sticking to the truth while making it funny is the key, say those who pen the scripts.

“Comedians” showrunner Ben Wexler recounts a conversation with a colleague over a business deal gone wrong.

“He tells me that however this shakes out, there will be no hard feelings, and I’m incredibly relieved,” says Wexler. “Then he clarifies that there will be no hard feelings from him.”

The experience always stuck with him — what could be more Hollywood, after all — so he slipped it deftly into a “Comedians” script.

“I think it’s always a balancing act,” says Wexler of satirizing the business. “There’s always an attempt to push the boundaries, but then also calculating how far do we want to go before it ceases to be funny.”

Dave Murray for Variety

There’s a risk, too, for his stars, Billy Crystal and Josh Gad, who both play fictionalized versions of themselves.

“Your ego’s gonna get bruised,” Gad told reporters at the Television Critics Assn. press tour in January. “And that’s sort of the agreement we made going into it is, some of it is going to get ugly for all the right reasons. This entire show is one big giant trust exercise.”

Crystal added the thin line between reality and satire makes for great television.

“And as an actor and a comedian, it’s fun to play with that, and it’s bold,” Crystal said. “I love the challenge of it for all of us in the cast.”

HBO’s “The Comeback” centers on actress Valerie Cherish (played by Lisa Kudrow), a once-popular sitcom star who’s scrambling to get back in the spotlight by both making a documentary on her life and acting in a series that tells the fictionalized backstage tale of that sitcom produced by bitter writer Paulie G.

In a party scene this season, Valerie tries to have a confidential conversation with former co-star Juna about a friend’s cancer while waiters keep interrupting them.

“Juna says, ‘I’m here for you — well for the next three days but then I’m leaving town to shoot a movie,’ ” Kudrow says. “She’s not really around, and we can go hard after people like that as long as we balance it with our truth as human beings.”

Juna also confides she’s hurt by the fictionalized portrait of herself, which makes Valerie noticeably uncomfortable. It’s a moment that is reflected in real life as well.

“I feel actresses are nervous and writers are freaked out,’’ says Michael Patrick King, who co-created and produces “The Comeback” with Kudrow. He says he’s actually seen actresses begin to make Valerie’s signature “yoga blessing hands” — and then check themselves.

“But the first person I hear from is myself, because this is a documentary about me. It’s the most accurate thing I’ve written. Anyone who works in television knows I’ve been there.”

King says when they had Andy Cohen, Lisa Vanderpump, Conan O’Brien and others on the show, playing versions of themselves, they always felt they were in on the joke.

“The only real villain in this is Paulie G., but he’s still a human being with real world flaws,” Kudrow says. “That explains why he’s such a mess and a dangerous human being.”

Showtime’s “Episodes” has “Friends” star Matt LeBlanc playing a larger-than-life version of himself in the comedy about a British husband-and-wife writing team who travel to Los Angeles to remake their hit show — with disastrous results.

“We did have a conversation about burning bridges,” says David Crane (“Friends”), who co-created the series with his writing and life partner Jeffrey Klarik. “Jeffrey doesn’t mind burning bridges or making people uncomfortable.”

Both say people in the industry seem to embrace the show, and don’t bear them any ill will.

“I’m not sure they have a sense of humor about it, but when you have a show like this, they have to be careful about letting us know,” says Klarik with a laugh. “One of the things about these people is that they have a language all their own. Which people outside of these environments call lying.

They seriously aren’t capable of telling you the truth.”

Or simply don’t want to see it.

“They don’t recognize themselves,” Klarik says. “One of the (characters on the show) is based on a woman at the BBC, where we first pitched the show, who just had this sour face and sat on the show for two years before she bought it. She’s no longer at the BBC.”

Crane says the show’s humor extends beyond L.A.

“If it’s just a Hollywood satire, we would all be bored quickly,” Crane says. “In order for the satire to work, it has to be truthful and honest, but at the heart of our show it’s also the journey of (main characters) Sean and Beverly.”

Yet what happens to them we all can relate to — and laugh at.

“I’ll admit I can’t remove the bitterness, and I filter everything through my own experiences,” Klarik says. “I see the ridiculousness of it all, and that’s where you find the humor.”