The newly consummated political marriage of Montgomery County District Attorney Bruce L. Castor Jr. and Commissioner James R. Matthews is one of convenience, not love, so they did what such couples do.

They got a prenuptial agreement.

The bitter Republican rivals put their animosity aside yesterday to run as a ticket for county commissioner, and negotiated a written deal that spells out their roles on the board if they win in November, five sources familiar with the agreement said yesterday.

The sources include political figures with ties to both camps, and spoke on condition of anonymity because neither Castor nor Matthews was commenting.

The deal was hammered out in the morning when Castor and Matthews met with intermediaries Michael Marino, the county solicitor and a longtime Castor ally, and Barry Miller, former county solicitor and counsel to Matthews.

The document spells out who gets to be chairman if they both win - not a sure thing because the Democrats are mounting a stiff challenge with their two candidates for the three-member board, former U.S. Rep. Joseph Hoeffel and incumbent Democratic commissioner Ruth Damsker.

If the GOP retains control, Matthews would be chairman for the first part of 2008, after which he is expected to give up the post - but not his seat on the Board of Commissioners - to run for state treasurer, according to two Republican officials. Matthews did the same last year when he ran for lieutenant governor alongside gubernatorial candidate Lynn Swann.

Also discussed were scenarios concerning the chairmanship in the event Castor runs for governor in 2010, the sources said.

One of the two GOP officials noted that the need for such an agreement didn't bode well for the relationship.

"When you have to have counseling before the marriage, there's a problem," said the source.

But another Republican Party leader said the agreement made sense.

"I believe that they wanted to cover a whole bunch of things," said the party official. "I think that's smart."

The Matthews-Castor '07 committee announced their ticket in a terse statement.

"Please note that we have agreed to run for the GOP nomination for county commissioner as a team," the statement said, thanking the "many party leaders who helped bring us together."

The two did not return calls seeking comment.

The feud has its roots in the split between county Republican leaders Robert Asher, a national GOP committeeman, who supports Matthews, and former Republican county chairman Frank Bartle, who is a Castor ally. Castor has warred with Matthews over budget and prison issues, and on Monday, Matthews said Castor's ego "could float the Titanic."

Four other Republican candidates - Commissioner Thomas Ellis, former Lower Merion School Board President Jill Govberg, State Rep. Kate Harper, and former State Rep. Melissa Murphy Weber - withdrew from the race, GOP officials said.

Yesterday was the deadline for candidates to take their names off the ballot without a court order.

Democrats in Bucks, Chester and Delaware Counties will have contested primaries, as will Republicans in Chester and Delaware Counties.

Democrats, who have not won a county row office in recent memory, are hoping that a decade of inroads will result in a takeover of the courthouse in November.

Voters will note the GOP bad blood, said Montgomery County Democratic chairman Marcel Groen.

"You can't paper over what appears to be a very strong personality disagreement," Groen said. "I think people want their leaders to be cohesive, stable, and have a vision that they can work on together."

County GOP chairman Kenneth Davis said, "You can't force people to like each other, but we have a common goal, and we will work together toward that goal."