Barbra Streisand has slapped hubby James Brolin with a new cheating ultimatum!

The diva announced James can return to ABC’s “Castle,” as long as there’s no flirting with the leading ladies, sources told The National ENQUIRER.

“Nothing’s written in stone,” said an insider, “but Barbra isn’t taking any chances now that the show’s a lock for a new season.”

James, 74, has guest-starred twice as the long-absent father of the show’s title character, played by Nathan Fillion.

As The ENQUIRER has reported, James developed a flirty friendship with actress Stana Katic, 36, and she was caught in the middle of a nasty battle between him and Barbra, 72.

“James went on and on about how delightful Stana was,” a friend said at the time.

“Barbra accused James of having an affair with Stana, and he shot back, ‘Don’t be ridiculous!’

“But Barbra refused to let it go, and they got into a terrible screaming match.”

Barbra was also furious because she believes “Castle” co-star Susan Sullivan, 72, made a play for her handsome hubby, gushing: “I’m hoping (producers) bring (him) back … He’s an attractive guy.”

And with “Castle” drawing 10 million viewers, TV insiders consider it “certain” to be renewed. “And you can bet they’ll be bringing Brolin back,” said the insider.

“That’s why she gave James the cheating ultimatum.”