Retired detective superintendent Matthew Fenwick said he believed reporter Dan Johnson would run a story about South Yorkshire Police's investigation into the singer unless he was told about the search.
READ MORE: South Yorkshire Police pay £400,000 to Sir Cliff RichardDiscussing a meeting in July 2014 with Mr Johnson and the force's head of corporate communications, Mr Fenwick said: "I believed the BBC was in a position to publish a story and I didn't want them to publish a story at that stage.
"(Mr Johnson) said he could and he would, and we came to an arrangement that he would not publish it then but that we would let him know when we were going to take further action.
"I felt that we didn't have many options - there was no option, other than to co-operate with him."
Sir Cliff is suing the BBC for "substantial damages" over its coverage of the raid at his penthouse apartment in Sunningdale, Berkshire, in August 2014 following an allegation of sexual assault.
READ MORE: Sir Cliff Richard breaks down in tears over BBC's filmed South Yorkshire Police raid on homeThe 77-year-old singer claims the report was a "very serious invasion" of his privacy and has had a "prolonged impact" on him.
BBC bosses dispute his claims.
The singer thanked a group of fans gathered outside the court as he left after the third day of the hearing on Monday.
He appeared to pose for photographs and one fan shouted: "The whole world loves you Cliff," as he got into a taxi.
Another supporter said: "Thumbs up," to which the singer replied: "Not yet".
Sir Cliff broke down in tears giving evidence on Friday, as he told the judge his name had been "smeared" across the world.
READ MORE: Sir Cliff Richard to give evidence in court over BBC coverage of South Yorkshire Police raidBBC lawyers previously told the court the raid was a "matter of legitimate public interest" and its coverage was accurate and in good faith.
Metropolitan Police officers working on the Operation Yewtree investigation into historic sex offences passed the allegation to South Yorkshire Police in July 2014.
A man claimed he was sexually assaulted as a teenager by the singer at a rally led by Evangelist Billy Graham at Sheffield United's Bramall Lane stadium in the 1980s.
Sir Cliff denied the allegation and in June 2016 prosecutors announced that he would face no charges.
A BBC spokesman has said the BBC reported Sir Cliff's "full denial of the allegations at every stage."
The trial, before Mr Justice Mann, is due to last 10 days.