The saga of the House Ways and Means Committee's attempt to overhaul the tax code is sometimes writ in the fine print, in the unnoticed sections of tax law where only those seeking to preserve an obscure loophole care to wander.

Where little federal revenue is at stake and only a few members of the committee care deeply, lobbyists often strike gold, as they did last weekend.

Ways and Means members decided then to preserve a threatened tax break for shipbuilding, a benefit so obscure that it is not even in the Internal Revenue Code, which implements the tax law.

But it had been the subject of intense lobbying by business and labor for almost a year, and of impassioned appeals from other members of Congress asking to save it. Even officials of the Transportation Department went to bat for the break, which President Reagan and Ways and Means Committee Chairman Dan Rostenkowski (D-Ill.) wanted eliminated.

In the end, proponents got almost all they wanted.

"The result was not just happenstance. None of these things just happen by the grace of God," said Alan Granwell, a partner in the New York law firm of Cadwalader, Wickersham & Taft and a lobbyist for shipping interests.

The tax provision they rescued is, even proponents admit, a subsidy to the U.S. shipbuilding industry that costs the Treasury $400 million a year in lost revenue. It works almost like an Individual Retirement Account: Companies deposit money into a special fund: the Capital Construction Fund. They do not have to pay taxes on the money or on the interest it earns, if, when the the money is withdrawn, it is used to pay for building American ships with American labor.

Ships used in international trade, domestic trade or fisheries are covered by the fund, which has been in existence since 1936. The companies must reduce the depreciation write-offs they take on the ships if they use money from the fund, but they can still enjoy such other tax advantages as the 10 percent investment tax credit.

Although other industries also have special tax advantages, the capital construction fund has been a target of various tax-revision efforts for some time.

"The current rules for taxation of merchant marine capital construction funds are a gross departure from generally applicable principles of taxation," the Reagan proposal said. "A direct subsidy would be more straightforward and would reflect the costs of the subsidy in the budget of the appropriate agency."

That statement rings with irony to representatives of the shipbuilding industry, who point out that the administration has dismantled almost all spending programs that once aided maritime construction. Industry representatives say the fund is needed to keep shipbuilding jobs in the United States and to ensure that a merchant marine fleet is available in time of war.

"Basically it's an offset to the advantages that many other countries give" to their shipbuilding industries, said Albert E. May, executive vice president of the Council of American Flag Ship Operators.

The provision has not protected the industry from a serious decline as other nations have moved into the market. In the 1950s, American-flag merchant ships carried about half of all U.S. foreign trade. Today, the figure is about 5 percent. No orders have been placed for international trade vessels since 1978, although other types of ships have been built.

Roughly $900 million is sitting in the fund, deposited by 126 ship owners. In the past, the fund has been troubled by abuse: a report by the Transportation Department's inspector general this year found that the Maritime Administration had approved $178 million in withdrawals that did not meet the fund's standards, resulting in a loss to the U.S. Treasury of $79.9 million.

Nonetheless, Transportation Department officials were said by industry representatives to have been "very helpful" in pushing for the fund's preservation, and Assistant Navy Secretary for shipbuilding Everett Pyatt wrote a letter supporting the fund. On Capitol Hill, Reps. Walter B. Jones (D-N.C.), Mario Biaggi (D-N.Y.) and Norman F. Lent (R-N.Y.) lobbied for the fund.

Rep. Brian J. Donnelly (D-Mass.), a Ways and Means member with 6,000 shipbuilding jobs at the General Dynamics plant in his Quincy district, began fighting for the fund as soon as the Treasury Department first proposed dismantling it last year.

He and Rep. Cecil Heftel (D-Hawaii) met with Rostenkowski and his staff recently and laid out their case. Donnelly handed the chairman a proposed amendment to the tax-overhaul plan that placed some minor restrictions on the fund but would continue it indefinitely.

When the committee sat down to write taxes on Sunday, the staff passed out the proposal as if it were Rostenkowski's own. No objections to it were raised. The only relevant amendment, which would have loosened one of the new restrictions, was defeated, and the proposal was adopted without dissent.