I am starting to wonder which side Trump is rooting for in 2018

  • Trump's handling of Congress in the past month is seriously increasing the chance for Democratic gains in the midterm election.
  • Maybe Trump thinks a win for Democrats in 2018 will help him in 2020 — he can run as a victim of an entrenched bipartisan establishment instead of with his own party.
  • Regardless, Trump's embrace of Nancy Pelosi basically blunts what House Republicans have honed as their major defensive weapon in elections: demonizing Pelosi.

Donald Trump's comments about and dealings with Congress over the past month raise a series of interrelated questions:

  • Does he understand how much he is increasing the prospects for serious Democratic gains in the midterm elections?
  • If he does (at some level), are his actions the result of a calculation that the benefit they provide for his immediate agenda outweighs whatever harm they do to Republican chances in an election more than a year away?
  • Or, is his angry frustration at the inability — unwillingness in guru Steve Bannon's view — of the Republican Congress to deliver on any of his major campaign themes becoming a view that he personally would lose little governmentally with Democratic control of one branch?

Maybe he thinks a win for the Democrats in 2018 would allow him in 2020 to run as the victim of an entrenched bipartisan establishment rather than an ineffective Republican leader who could not get his own party to follow him.

My current guess — subject to modification by his future behavior — is a combination of no to question one and an evolving yes to question three.

In particular, I am skeptical that he is fully conscious of how much his deal with Nancy Pelosi and Chuck Schumer undercut Republican strategy for what was already shaping up as a difficult campaign next year, but I also doubt that it would have made much difference to him if he was.

The most important data point in this analysis is his ongoing embrace of Nancy Pelosi —fortunately for her, a metaphoric one. Trump has acknowledged Pelosi as a member of the new triumvirate on federal spending, given her full credit for her influence on his decisions affecting Dreamers and included her in serious discussions about tax policy. To conservative true believers, that's the equivalent of asking the arch-heretic's advice on doctrinal matters.

"And even if Donald, Nancy and Chuck are never again an amiable trio, the damage has already been done to any campaign that relies on convicting a candidate based on guilt by association with Nancy Pelosi."

Trump has done more to blunt what House Republicans have been honing as their major defensive weapon than all of the Democratic consultants could ever have hoped to do.

Wholly unfairly, House Republicans have used a caricature of Pelosi with some effect — most recently using it to deflate Democratic hopes for an upset by Jon Ossoff in a special congressional election in Georgia.

This is not unprecedented. Tip O'Neill and Newt Gingrich both played that role in the 80s and 90s, respectively. Legislative leaders are rarely popular with the wider electorates in the jurisdictions which they serve. Not only is Bob Dole the only congressional leader to win a presidential nomination since Henry Clay — with a similarly unsuccessful result — in the states with which I am most familiar, Senate majority leaders, presidents and House speakers almost always lose when they run for governor.

In Pelosi's case, there are three factors that are increasing their desire to target her. First, there is the fact that she is the only woman in American history to hold one of the three major policy-making positions in the federal government. Second, using San Francisco as a symbol of moral decay is a convenient way of dog-whistling several prejudices which "respectable" politicians do not want to voice explicitly. Third, less recognized but maybe most important, she has been one of the most successful Speakers in decades. The negative passions she incites are clearly fueled by her record: Much of this year's Republican agenda consists of efforts to undo the legislative record she helped compile in 2009-2010.

Having noted all of this, I believe that the benefit Republicans get from demonizing her have been exaggerated. Anger at President Obama was the determining factor in the 2010 midterm elections and Democrats did much better than the norm in each of that year's special elections. The centrality of the anti-Pelosi campaign in Republican plans for the 2018 House elections is not because of its potency, but because of the weakness of every other option. Demonizing Nancy Pelosi is not a magic bullet; it's simply the only one they have.

In fairness to Trump, some of the Republicans' problems are of their own making. Not only does the ideological zeal of some of their number make it hard for them to look like people to who you want to entrust responsible jobs, they have volunteered to take votes that will be very hard to defend in November. Expect to hear a lot about Wells Fargo, Equifax, and irresponsible financial companies that will undoubtedly be named later in the districts of Republicans who voted to effectively abolish the independent Consumer Financial Protection Bureau.

But whereas every previous president would have at least tried to help his co-partisans, Trump has vigorously exacerbated their difficulties. He has, over the past month and more, attacked the Congress which is under his party's control. When he has gotten specific, he has more often named Republicans than Democrats. Having pushed them to vote for a health-care bill with which he was unfamiliar, he repaid them by publicly denouncing it as mean. And he and his allies are promoting the kind of ideologically embittering primaries from which the winners will emerge badly wounded. (It is a received truth among politicians that those who tell incumbents that primaries are good for them have never had to run in one.)

And now he is severely diminishing the force of the one argument that they hoped would survive all the year's bad news: Pelosi-phobia. Don't be distracted by what we did or didn't do, they plan to tell voters; focus instead on the terrible things that will be done by the Wicked Witch of the West Coast.

"Oh," their Democratic opponents can now respond, "you mean Nancy of the team of Chuck and Nancy on whom your president has relied for advice." Attacked as one who will take guidance from Nancy Pelolsi, I would happily be the Democratic candidate who responded, "You mean like Donald Trump did when he faced a serious crisis and turned to her to help avoid a government shutdown and get aid to hurricane victims? "Given the satisfaction Trump shared with his new allies at the good press their co-operation generated for him, and the continued inability of the House Republicans to govern, there is very likely to be more of this.

And even if Donald, Nancy and Chuck are never again an amiable trio, the damage has already been done to any campaign that relies on convicting a candidate based on guilt by association with Nancy Pelosi. Donald Trump just changed the game.

Commentary by Barney Frank, chair of the House Financial-Services Committee from 2007 to 2011, during which time Congress enacted the TARP program and the financial-reform bill known as Dodd-Frank. Follow him on Twitter@BarneyFrank.

For more insight from CNBC contributors, follow @CNBCopinion on Twitter.