BOTH sides in Libya’s civil war knew they would need to sell oil again fast once the conflict was over. So for the most part they took care not to ruin the energy infrastructure. For example, while fierce fighting was devastating the western town of Zawiya, the large oil refinery to its north lay idle but untouched by war, its workers still able to have lunch in the canteen. By mid-2012, less than a year after Muammar Qaddafi’s demise, Libya’s oil production, almost entirely switched off during half a year of ferocious fighting, had regained its pre-war level of about 1.5m barrels a day (b/d)—years earlier than expected. Proudly, Libya’s new leaders said output could soon rise to 2m b/d or more. The oil minister, Abdelbari Arusi, promised a new hydrocarbons law and an auction of leases for unexplored territory to foreign oil companies. Libya’s oil reserves, at 47 billion barrels, already Africa’s biggest, could—it was said—increase by another 10 billion.

But Libya’s political chaos is, alas, spreading to the oil industry. Workers and militias now often disrupt production at energy installations, forcing the government to give them money before they will switch the valves back on. In late May protesters shut down the Feel oilfield in Libya’s south-west. Tobruk, Ras Lanuf, Zueitina and other ports from which oil is exported have been afflicted too. Mr Arusi said recently that protesters had cost his country $1 billion in lost revenue.

If only the government had offered decent jobs to disaffected locals and former fighters last year, things might be better today. Now it may have to resort to force to stop the rot, which could then create even worse chaos. The government is still struggling to bring an array of unruly militias to heel.

Oil people say bureaucracy is stifling recovery, as decisions get shuffled between the state-controlled National Oil Company (NOC), the oil ministry, and Ali Zeidan, the prime minister. The Arabian Gulf Oil Company, better known as Agoco, a part of NOC that operates in Libya’s east, has for 15 months been unable to replace crucial power-generation equipment at its Sarir and Misla oilfields. Output there will probably soon drop from 380,000b/d to around 300,000b/d, says one insider: a loss of $8m a day at current oil prices.

Foreign firms, unsettled by sporadic violence and an attack in January by jihadists on a gas plant in neighbouring Algeria, close to its border with Libya, are not rushing to send their people back. BP, a British oil giant, which was ready to begin fresh drilling when the uprising started, recently withdrew more of its foreign staff. It has not said when work will begin again.

Before an auction, Libya needs to provide new geological information. But none of the oilfield-services firms that could acquire fresh seismic data is doing so. A new oil law, meanwhile, needs a consensus in the General National Congress, Libya’s proto-parliament. But its speaker, Muhammad Megarief, was forced to resign last month after a law was passed to purge anyone who had served in a senior post in Qaddafi’s regime—even though he defected from his post as an ambassador more than 30 years ago.

To pacify eastern Libyans, who have tended to feel done down by the country’s new rulers, who hail more from the west, the government plans to move NOC’s headquarters from Tripoli, the capital, to Benghazi—a city the American and British governments advise their people to avoid because of the persistent menace of uncontrolled militias there.

So the initial optimism over oil is fading. Libya will struggle to keep output stable, let alone increase it. This will disappoint oil traders who prize the country’s high-quality crude. But it is much worse for Libyans. The IMF says oil and gas account for 70% of the country’s GDP and 95% of its exports. Despite the resumption of oil production and a sharp rise in GDP last year, Libya’s economy has yet to get back to its pre-war size.