Two communist countries, Bulgaria and Yugoslavia, recently cooperated in the capture of West German terrorists, but the cooperation has come at a price for Bonn.

At the time both of these episodes created optimism in the West that these communist countries were willing to cooperate to curb terrorism, but subsequent developments raise questions about whether these is such a new attitude.

In both cases, informed sources say, "mutual interests" were involved rather than overall East-West considerations.

For example, on May 11 four of West Germany's most-wanted terrorists were captured in Zagreb, Yugoslavia, in a dramatic operation that was hailed as a sign fo broadening Eas-West cooperation in such matters.

Two-and-a-half months later, however, these four terrorists are still being held in Yugoslav jails. Although both Belgrade and Bonn offically deny it, Yugoslavia is demanding a proce: that West Germany extradite between four and eight Croatian extremists who are now in West German jails.

Such a swap is not a simple matter, however.

Extradition laws are extremely strict in West Germany, presenting a rough problem on which West Germany courts will have to rule, rather than the Bonn government.

In addition, the West Germans are afraid that if they turn over the Croatians, they will expose themselves to retaliatory terrorist strikes from other Croatians who are here in large numbers. While the Croatians are being held by the West Germans are viewed by the Yugoslav government as terrorists and murderers, many Yugoslav exiles consider them freedom fighters.

Yugoslav, although a communist country, is outside the Warsaw Pact and has a history of taking independent positions.

More interesting, however, is the cast of Bulgaria, which is inside the Eastern bloc. In mid-June, Bulgaria allowed West Germany police to come into the country and arrest four other West German terrorists and fly them quickly back to West German jails.

At the time, this was hailed as an important step because it suggested Soviet acquiescence in the fight against Western terrorism and because the Bulgarians apparently did not ask anything in return.

Although officials in Bonn's chancellory deny it, there us reason for suspecting that the major factor in the Bulgarian decision involved a quiet exchange for Bulgarians who were allegedly operating as spies in West Germany and whose activities were known to West German security forces.

The four West Germans were first spotted in Bulgaria by a prison official from the jail in West Berlin from which the terrorists had escaped on May 27. The prison official happened to be vacationing in Bulgaria and spotted the four at a beach area.

WestGerman police swooped into Bulgaria with government permission and made the arrests. The Bulgarian police did not take part in the arrest because the terrorists had committed no crimes in Bulgaris.

Ironically, the life of the prison official who spotted the group may now be in some danger because another aspect of the episode.

Informants suggest that West Berlin's Justice Ministry, acutely embarrassed by the escape from the supposedly top security Moabit jail on May 27, went too far in describing the capture of the four in Bulgaria. The details of how they were spotted apparently should not have been made public.

West Berlin's justice minister, Juergen Baumann, resigned on July 3 after a parliamentary report was critical of the jailbreak. His resignation, however, also came after the group was recaptured in Bulgaria, and securities sources say police anger over release of details about the prison official also played a part in that resignation.

Informants say there have been some signs that Soviets may be willing to assist more than in the past on the matte of combating terrorism. The subject is understood to have been raise by West Germant Chancellor Helmut Schmidt during the visit here in early May of Soviet leader Leonid Brezhnev.

Generally, however, security officials are skeptical that Brezhnev would go very far in matters which, at some point might cause him difficulties in the Middle East or other areas where radical elements have proved a serious thorn in the side of Western governments.