A longtime spokesman for the state court system accidentally butt-dialed a Post reporter — yukking it up about how “I barely show up to work” while pocketing a $166,000-plus salary and boosting his taxpayer-funded pension.

After speaking by cellphone with the reporter about a planned exposé on his cushy schedule, David Bookstaver butt-dialed back, and unwittingly left a four-minute voicemail while chatting with at least two other people.

On the voicemail, Bookstaver admitted lying to The Post about how he spent his weekdays and confirmed the accounts of court system sources who said he’s been working as little as two days a week.

‘Look, the bottom line is, I’ll suffer through a terribly embarrassing story and then go get my f–king pension and retire.’

“I spoke to [the reporter] on the record for awhile. I said, ‘I’m in a much less visible position; that doesn’t mean I’m not doing anything,’ ” Bookstaver said.

“But, frankly, look, the bottom line: The story’s true. I’m not doing anything. I barely show up to work and I’ve been caught.”

The remark promoted laughter, after which Bookstaver explained that he didn’t need to show up “because they took away all my responsibilities and left my pay.”

At one point, he lamented having bragged about his ability to play hooky. “They left me alone and look, I have a big mouth. I told people I’m not doing much. I do take a lot of time off,” he said.

“I kind of asked for it. You know, if you have a big mouth, you know it catches up with you.”

Bookstaver, who’s planning to retire Oct. 1, also raised the possibility he could get fired “because of a story in The Post,” but said it “would probably affect my pension check by $6 a month.”

“Look, the bottom line is, I’ll suffer through a terribly embarrassing story and then go get my f–king pension and retire,” he said.

Sources said Bookstaver, who was hired in 1996 after working as director of public information for the city’s former Emergency Medical Service, was stripped of his spokesman duties following a change in leadership of the state Unified Court System last year.

Chief Judge Janet DiFiore replaced Bookstaver with Lucian Chalfen, who was her chief spokesman when she was Westchester County district attorney, before she was put in charge of the court system in January 2016.

But Bookstaver retained his Office of Court Administration “communications director” title and hefty pay, while Chalfen was named “special projects coordinator” and given Bookstaver’s duties along with a $140,000 salary in February 2016, records show.

Since then, Bookstaver has only shown up at his office in lower Manhattan between two and four days a week, sources said.

He also hasn’t worked on Fridays for at least the past three years, often spending long weekends at a second home in upstate Warwick where he often goes bow-hunting, sources said.

“It’s outrageous that our membership is in its seventh year without a contract, and there are employees at [OCA] making in excess of $150,000 a year for no-show jobs,” fumed Patrick Cullen, president of the Supreme Court Officers Association.

If Bookstaver retires on Oct. 1, he will be 59 and will have twice celebrated his Sept. 27 birthday since Chalfen took over his duties.

By remaining on the public payroll, Bookstaver — who inherited nearly $2.5 million from his late mother in 2015, court records show — has trimmed the penalty he faces for taking early retirement before age 62.

If he had retired around the time DiFiore became chief judge, he would have been 57 and had his pension benefits slashed by 21 percent.

That will be reduced to only 15 percent if he remains a public employee until he turns 59.

Court administration sources said DiFiore likely let Bookstaver keep his title and income — about $15,000 a year less than city Civil and Criminal Court judges are paid — as a favor to her predecessor, former Chief Judge Jonathan Lippman.

“It is not uncommon for one administration to do a favor for another,” one high-ranking source said.

Another senior-level source said there was a “culture of nepotism” in the courts, which the source described as “ extremely incestuous.”

Bookstaver was very close to Lippman when he was chief judge, court sources said.

In 2001, Lippman officiated at Bookstaver’s wedding to Kerry Beagan inside his judicial chambers in Manhattan, then “led a celebration of the couple’s marriage at the Old Tavern in Grafton, Vt.,” according to a New York Times wedding announcement.

A request for comment from DiFiore was answered by Chief Administrative Judge Lawrence Marks, who said that while Bookstaver “no longer handles the day-to-day press inquiries, in his less publicly visible role as communications director, David’s experience and insight are no less valuable.”

Lippman, who’s now “of counsel” at the Latham & Watkins law firm, denied that he sought to keep Bookstaver on the payroll.

“David, I assume, was kept on because he did a good job,” Lippman said.

Warning: Graphic language