HM Revenue & Customs was tonight investigating explosive allegations about tax avoidance schemes operated by Barclays Bank, made by a whistleblower in the firm and apparently substantiated by leaked documents.

HMRC's moves came as the government announced steps to try to discourage tax avoidance by Britain's banks, now frequently dependent on state aid. The chancellor launched plans for a code of practice in which banks would be expected to abide by the "spirit of the law".

The whistleblower in Barclays's apparently troubled structured-finance department at Canary Wharf has disclosed to the Liberal Democrats the existence of a scheme codenamed Project Knight.

In memos seen by the Guardian, executives from SCM, Barclays's structured capital markets division, sought approval for a 2007 plan to sink a total of more than $16bn (£11.4bn) into US loans.

Tax benefits were to be generated by an elaborate circuit of Caymans companies, US partnerships and Luxembourg subsidiaries, in a $4bn deal with North Carolina Branch Banking & Trust Co (BB&T).

Memos detailing a number of alleged tax avoidance schemes in elaborately structured international loans were published by the Guardian on its website.

The Guardian today identified two similar, larger schemes which Barclays apparently carried out. One, involving an entity called Pelleas, involved a $6bn loan and the other, Claudas, swallowed up $7bn.

The chancellor, Alastair Darling, told parliament: "I have asked HM Revenue & Customs to publish shortly a draft code of practice on taxation for the banking sector – so that banks will comply not just with the letter but the spirit of the law."

Darling said the draft would be published by the time of the budget next month and that the full version would be introduced as soon as possible afterwards.

Although he did not give details of how it would be enforced, he said the banks dependent on taxpayer support would be expected to comply. "The public would expect that, if it is supporting the bank system, then those banks are prepared to abide by that code," he said.

Darling said the government had taken action against tax avoidance in every budget since 1997 but that, as soon as one loophole was closed, another opened up. "Partly because the very complexity of banking, the way in which, sometimes just investment banks and sometimes others have sought to develop instruments in order to avoid pay taxes has in itself posed a systemic threat to the system."

The Lib Dem Treasury spokesman, Matthew Oakeshott, said that the leaked documents showed that HMRC attempts to keep up with the banks' tax avoidance were like "a fat policeman chasing a speeding Ferrari".

HMRC said: "We have received papers relating to allegations of tax avoidance in the banking industry which we are studying carefully."

A spokesman for Barclays insisted that all its transactions were discussed with HMRC. "Project Knight was voluntarily and fully disclosed to HMRC, though there was no statutory obligation to do so."

A senior former tax official familiar with Barclays's tax strategies said HMRC was not always able to realise what lay behind the limited disclosures by the bank.

Project Knight appeared to be a scheme to obtain double tax reliefs in different countries, he said.

"By my reckoning, the scheme, which has been highly engineered to get around tax rules, looks set to save Barclays about £60m a year in tax on a £4bn loan outlay."

He said HMRC "will not be provided with anything about the counterparties, and the structures which each scheme employs will not usually be volunteered. A group the size of Barclays will have hundreds of subsidiaries, and will submit its accounts and computations by the vanload to a relatively small team of investigators.

"There is plenty of scope for things to be missed or misunderstood, and the bank will not only volunteer nothing, leaving the inspector to ask precisely the right questions, but will also, with the help of advisers, craft replies to HMRC questions with a view to giving factually correct but as unhelpful answers as possible."