When Donald Trump perceives an attack, he hits back, and his weapon of choice has long been the courts. He threatens legal action himself and through his lawyers, in private missives and in public blasts. Sometimes, he actually files suit.

Now, with an energized Democratic House majority mounting an array of investigations and talking impeachment in the wake of the special counsel’s report on Russian interference in the 2016 election, the president is vowing to “head to the U.S. Supreme Court.”

Never mind that the high court plays no role in impeachment, which the Founders designed as a faceoff between the executive and legislative branches. In politics, as in business, marriage and nearly every aspect of a career spanning five decades, Trump uses the courts and threats of legal action for self-defense and to punish those who seek to alter the image he has crafted for himself.

This week, Trump’s private attorneys filed suit against the House Oversight Committee and Trump’s own accounting firm after the panel subpoenaed his financial records. The Justice Department announced that Attorney General William P. Barr instructed one of its top officials to ignore a subpoenaed deposition. And the president tweeted that “If the partisan Dems ever tried to Impeach, I would first head to the U.S. Supreme Court.”

Rep. Gerald E. Connolly (D-Va.), a member of the Oversight Committee, accused the president of “triggering a constitutional crisis.” Of course, battles between Congress and presidents have wound up in court before, notably in the final stages of the confrontation between lawmakers and President Richard Nixon. And presidents have often spoken of the Supreme Court in decidedly political terms; Franklin Roosevelt even sought to expand the court’s roster to pack it with ideologically like-minded justices.

But Trump is unlike any predecessor in his lifelong dependence on the court system as a rhetorical club to wield over his enemies, a tool of public persuasion and a tactical weapon of delay and distraction. From his meteoric rise in the Manhattan real estate development business through his string of bankruptcies in the casino hotel business, Trump has turned to the courts more than any other future president, having been involved in more than 4,000 lawsuits himself and through his businesses, according to a database assembled by USA Today.

In most cases, his goal has not necessarily been to win, but rather to use the notion of a court battle to diminish or destroy an opponent. From early on in his lifelong pursuit of fame, fortune and power, Trump has joined “I’ll sue” with brash rhetoric, a constant media presence and an infinite capacity for starting over.

As president, however, Trump seems taken with the idea that the judges he has appointed will not only guarantee legal victory but will be the ultimate safeguard of his actions and policies.

From the start of his 2016 campaign, Trump made clear that he saw the courts not as an independent branch of government, but as one more weapon in a president’s arsenal. “We’re going to have great judges, conservative, all picked by the Federalist Society,” he told Breitbart News in June 2016. “If it’s my judges, you know how they’re gonna decide,” Trump told an evangelical Christian audience a week later, answering a question about Second Amendment gun rights.

The coming months will test that notion against the historic role of the judiciary, particularly the Supreme Court.

“The Supreme Court plays no role in impeachment, and there’s virtually no way the court would take up any challenge to an impeachment,” said Peter Irons, a constitutional lawyer and political scientist at the University of California at San Diego, who has written a history of the high court. “More important, they are the institution that stands apart from partisan politics. If we come to think of the court as simply five Republicans and four Democrats, then that bulwark is really broken.”

Trump was encouraged to use the courts as a weapon by his early mentor, New York attorney Roy Cohn. He recognized from the start of his career that the mere threat of a lawsuit enabled him to respond to crises with delay, distraction and deflection.

Most often, his threats to take opponents to court are just that — words intended to intimidate or silence an enemy, rather than a precursor to any actual filing of a lawsuit.

In 2004, when a writer named Robert Slater was researching a book about him, Trump had his attorney write a letter announcing that a suit would be filed if the author published a book without Trump’s approval.

Ultimately, there was no lawsuit. After the threat, Trump called Slater, told him he’d heard the writer was “an amazing guy,” and offered to cooperate. If he liked the book, he said, he’d even buy a load of copies. The publisher agreed to let Trump see the book ahead of its release, and Trump was even allowed to remove material he didn’t like.

Sometimes, he sued for publicity. In 1984, he filed a $500 million defamation suit against a Chicago Tribune critic who called Trump Tower’s lobby “a kitschy shopping atrium of blinding flamboyance.” A judge dismissed the case, but Trump got a load of media attention from it.

Other times, he sued as personal punishment. In 2006, he filed a libel suit against Tim O’Brien, the author of a biography that concluded Trump’s net worth was not the $6 billion he claimed, but rather “somewhere between $150 million and $250 million.”

The suit was dismissed, but only after three expensive years of proceedings.

Trump told The Washington Post that suing O’Brien was worthwhile even though he’d always known that, as a public figure, he was highly unlikely to win a libel judgment. “I liked it because I cost him a lot of time and a lot of energy and a lot of money,” Trump said. “I said, ‘Go sue him, it will cost him a lot of money.’ ”

Sometimes, Trump would talk lawsuit just for the heck of it. “Watch [John] Kasich squirm,” Trump tweeted about the Ohio governor, one of his opponents in the 2016 GOP primaries. “If he is not truthful in his negative ads, I will sue him just for fun!”

In the end, Irons, the constitutional lawyer, said Trump “almost always backs down from his threats to sue. For example, all the women who accused him of sexual misconduct during the campaign: He threatened to sue them and, of course, he never did.”

Even as president, Trump has not shied away from turning to the courts. Less than a month after the inauguration, first lady Melania Trump filed suit in New York against the Daily Mail, the London-based news organization that had published allegations that she once worked as an “elite escort.”

The lawsuit sought compensation for the “harm done to her, her commercial brand and her business opportunities.” Two months later, the Mail settled the case, apologizing to the first lady and paying a reported $2.9 million in damages.

As quick as Trump is to talk lawsuit, some of those who have represented him contend that he does not reflexively head to the courthouse. Rather, they say, he thinks of the courts as one tool in a quiver of weapons available to confront opponents.

“I was with him 20 years in his two matrimonials and he never once went to court,” said Jay Goldberg, a New York attorney who handled Trump’s two divorces. Goldberg said Trump often “wanted to go to court, but I persuaded him it wasn’t in his best interests and he resolved the issues through other means.”

Goldberg has quoted Trump’s frequent admonition to his lawyers: “Don’t tell me it can’t be done. Your job is to tell me how it can be done.”

Although some of Trump’s lawyers have come to view him as impulsive and easily angered by the court system’s long delays and emphasis on process, others say he is a savvy legal consumer who understands how to use the courts to his advantage.

Sometimes that’s a simple matter of filing repeated motions to stretch out a lawsuit and make an opponent spend more on attorneys’ fees. And sometimes it involves more overtly aggressive moves, such as when Trump used his campaign rallies to bash a federal judge, Gonzalo Curiel, who was presiding over a case against Trump University.

“I have a judge who is a hater of Donald Trump, a hater,” candidate Trump said at one rally. “The judge, who happens to be, we believe, Mexican, which is great — I think that’s fine.”

As president, Trump has found that his old tactic of threatening lawsuits continues to win lots of attention. Since taking office, he has threatened to sue — among others — the New York Times and The Post, the publisher of a critical book and former political adviser Stephen K. Bannon.

None of those suits, however, has come to pass.