In the middle of July last year, then-national security affairs adviser Robert C. McFarlane opened a meeting on Libya with President Reagan and top administration foreign policy advisers by saying that Muammar Qaddafi threatened U.S. interests, that diplomatic pressure and economic sanctions had failed to curtail his terrorism, and that much stronger measures should be undertaken to thwart the Libyan leader.

After McFarlane's presentation, something happened that has been rare in the Reagan administration on foreign policy issues. Everyone agreed. The Central Intelligence Agency and Departments of State and Defense each concurred. An unmistakable warning was to be sent to Qaddafi, although it was not yet clear how, where or when.

This unusual consensus launched a series of discussions, studies, interagency meetings, and even military targeting plans on Libya. The door was considered open for new ideas on how to deal with Qaddafi. There even was serious consideration of a preemptive military strike against Libya in concert with U.S. allies in the Middle East, according to well-placed sources, but Reagan never agreed to such actions.

A top-secret CIA study dated several days after the National Security Planning Group (NSPG) meeting in July analyzed the pros and cons of preemptive military action and concluded that the administration had an opportunity to redraw the map of North Africa.

Reagan's senior advisers agreed that, following the hijacking of TWA flight 847 in June, when one American was killed and 39 others held hostage for 17 days, a line had to be drawn against terrorism. Even Reagan, who had shown restraint after previous terrorist incidents, said that the televised humiliation aboard the TWA jet was too much to endure and that the United States would act in the future, the sources said.

U.S. intelligence showed that Iran and Syria probably were more involved in the recent acts of terrorism, but those countries were not the visible symbols of evil that Qaddafi presented. A demonstration of U.S. resolve was necessary and Libya was singled out.

The key planner on the Libya issue was Vice Adm. John M. Poindexter, then the deputy national security affairs adviser who eventually succeeded McFarlane as the senior adviser. Poindexter chaired regular, even weekly, White House meetings. Poindexter made a secret visit to Egypt around Labor Day last year to coordinate possible joint military operations against Libya.

Sources described this as only contingency planning, but it was given extraordinary importance and secrecy. He was accompanied by Donald R. Fortier, now Poindexter's deputy at the NSC.

Poindexter carried with him a pledge from Reagan that the United States would provide direct combat support to Egypt in any confrontation with Libya along the 600-mile Egyptian-Libyan border, according to two informed sources. One official recently played down the significance of this pledge, saying that it was routine in any contingency planning with an ally.

In a parallel development, Reagan approved a CIA covert operation designed to undermine Qaddafi; again, the president directed that this effort be coordinated with U.S. allies in the Middle East disposed to see Qaddafi removed from power. An intelligence analysis done before the November summit meeting in Geneva between Reagan and Soviet leader Mikhail Gorbachev concluded that strong overt or covert action against Qaddafi would not trigger a Soviet response and would not adversely affect the summit.

Administration attention was refocused on Libya again late last year, when U.S. intelligence determined that Soviet-made SA5 long-range antiaircraft missiles were being installed at two and possibly three sites in Libya.

The White House then attempted to send another emissary to Egypt to continue contingency planning in December, but the Egyptians reportedly put it off, according to knowledgeable sources. At that time, U.S.-Egyptian relations were strained following the interception by U.S. jet fighters of an Egyptian airliner carrying the four hijackers of the cruise ship Achille Lauro.

The Pentagon further discouraged any direct U.S. military action and determined that an all-out military engagement with Libya could require up to six U.S. divisions, or more than 90,000 men.

Following the Dec. 27 terrorist attacks on the Rome and Vienna airports, the CIA found a strong Libyan connection to the terrorists and anti-Qaddafi planning was accelerated. At meetings of the NSPG on Jan. 6 and 7, the president ordered that more money and attention be given to the covert CIA plan designed to undermine Qaddafi; Reagan also directed that military contingency planning with Egypt continue. Publicly, the president ordered increased economic sanctions.

Aircraft carrier operations north of Libya were ordered in late January, but the Defense Department wanted to wait until three carriers were available near the Gulf of Sidra before testing Qaddafi's claim that the entire gulf is Libyan territory.

Qaddafi's claim, rejected by virtually all other nations, presented the administration with what one source called "a golden opportunity" to test Libya but not undertake any preemptive or retaliatory action against targets that had not attacked U.S. forces first.

"Any response would be defensive," said one official, "and there was at least the presumption that international law and public opinion would be on our side."

A senior Pentagon planner was sent to Egypt in February to continue the contingency planning, which has received much attention in the White House because of Poindexter's previous role, the sources said.

One source said this week's action may have satisfied the president's determination to demonstrate U.S. resolve, but the source also indicated that a wide range of more dramatic options are available if Qaddafi provokes them.

Several sources said that given the more radical options, the administration has taken a moderate course.

"American public opinion was ready for this, prepared, knowing that Qaddafi is a bad actor," one official said. "They're ready for just about anything; they knew something was going to happen; they would probably tolerate anything the president chose to do."

Since the first year of the Reagan administration, when Qaddafi allegedly was planning to send hit squads to assassinate top U.S. officials, the Libyan leader has been a kind of nemesis for the administration, particularly CIA Director William J. Casey, according to sources.

"There are lots of intelligence collection assets given to Qaddafi, trying to keep up with him, attempts to follow him, to intercept his phone calls, take photographs of him," one senior source said.

At the Defense Department, Qaddafi has been taken less seriously, according to sources, because he poses no direct strategic threat to the United States. But in the last nine months, Reagan, Casey and Poindexter have made Qaddafi a primary focus. The vast national security apparatus of the United States has been focused on the Libyan leader, including diplomacy, economic sanctions, a CIA covert plan, and now three Navy carrier groups