Obsessed with insiders trying to undermine him, President Trump compiled “naughty and nice” lists to help him discover which White House members were leaking to the press, according to a new memoir.

Cliff Sims, a former communications aide, said Trump called him into a private study outside the Oval Office to pick his brain about possible leakers in 2017, Axios reported, citing Sims’ new book, “Team of Vipers: My 500 Extraordinary Days in the Trump White House.”

Sims wrote: “‘Give me their names,’ (Trump) said, his eyes narrowing. ‘I want these people out of here. I’m going to take care of this. We’re going to get rid of all the snakes, even the bottom-­feeders.’”

The 33-year-old described the “remarkable” scene of sitting with the president of the United States “basically compiling an enemies list — but these enemies were within his own administration.”

Sims added in the tell-all: “If it had been a horror movie, this would have been the moment when everyone suddenly realizes the call is coming from inside the house.”

The president rattled off a series of names of perceived turncoats, Sims wrote.

“Almost no one was deemed beyond reproach — not his chief of staff, not senior aides, almost no one other than those with whom he shared a last name,” he wrote.

“He wanted me to help him judge their loyalty. How, I wondered, had it come to this?”

Finally, Sims wrote, Trump whipped out a black Sharpie and scribbled two lists on a card engraved with the White House seal.

“One list was people he could trust. The other was people he couldn’t, and wanted to let go,” he wrote. “The combined lists included about 15 people — 10 of them naughty, and five of them (all campaign alumni) nice.”

Most of the targets on the president’s “unofficial Enemies list” survived the purge, “at least for a while. But Trump seemed to revel in his new inside knowledge.”

In September, Axios also cited a source saying that Trump carried a list of suspected leakers.

“He would basically be like, ‘We’ve gotta get rid of them. The snakes are everywhere. But we’re getting rid of them,’” the source told the news site at the time.

“When he was super frustrated about the leaks, he would rail about the ‘snakes’ in the White House,” the source added.