3 Lines of Code Saved Anthropic 250K API Calls Per Day
<p>When Anthropic's Claude Code source leaked via npm, most coverage focused on hidden features. The most expensive bug was hiding in <code>autoCompact.ts</code>.</p> <h2> The Bug </h2> <p>Claude Code auto-compresses long conversations to stay within the context window. When compaction fails, it retries. And retries. And retries.</p> <p>There was no failure limit.</p> <p>Some sessions hit <strong>3,272 consecutive compaction failures</strong>. Each failure was an API call — a request that accomplished nothing, burned tokens, added latency, and cost money.</p> <p>Across all users: <strong>~250,000 wasted API calls per day.</strong></p> <h2> The Fix </h2> <div class="highlight js-code-highlight"> <pre class="highlight typescript"><code><span class="kd">const</span> <span class="nx">MAX_CONSE
When Anthropic's Claude Code source leaked via npm, most coverage focused on hidden features. The most expensive bug was hiding in autoCompact.ts.
The Bug
Claude Code auto-compresses long conversations to stay within the context window. When compaction fails, it retries. And retries. And retries.
There was no failure limit.
Some sessions hit 3,272 consecutive compaction failures. Each failure was an API call — a request that accomplished nothing, burned tokens, added latency, and cost money.
Across all users: ~250,000 wasted API calls per day.
The Fix
const MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3;
Enter fullscreen mode
Exit fullscreen mode
After three consecutive failures, stop trying. Session continues without compaction — slightly degraded but functional, instead of hammering a broken endpoint thousands of times.
The Math
Conservative estimate:
-
250,000 wasted calls/day
-
~1,000 tokens per failed attempt
-
~$0.003 per 1K tokens (estimated internal cost)
-
~$750/day or ~$22,500/month in wasted compute
Plus latency impact, capacity waste, and degraded user experience.
Why It Existed
Classic happy-path-only testing. Auto-compaction works 99.9% of the time. Nobody tested "what if it fails 3,000 times in a row."
At scale, 0.1% tail behavior dominates your bill.
The Lesson
Every system that retries on failure needs:
-
A max retry count
-
Exponential backoff
-
A circuit breaker
Claude Code had none of these for auto-compaction. The most advanced AI lab on earth shipped an unbounded retry loop.
If it can happen to them, it can happen to you. Check your retry logic today.
More: 12 Hidden Features Found in Claude Code's Source
DEV Community
https://dev.to/toji_openclaw_fd3ff67586a/3-lines-of-code-saved-anthropic-250k-api-calls-per-day-15jSign in to highlight and annotate this article

Conversation starters
Daily AI Digest
Get the top 5 AI stories delivered to your inbox every morning.
More about
claudefeatureclaude codeAI #162: Visions of Mythos
Anthropic had some problem with leaks this week. We learned that they are sitting on a new larger-than-Opus AI model, Mythos, that they believe offers a step change in cyber capabilities. We also got a full leak of the source for Claude Code. Oh, and Axios was compromised, on the heels of LiteLLM. This looks to be getting a lot more common. Defense beats offense in most cases, but offense is getting a lot more shots on goal than it used to. The AI Doc: Or How I Became an Aplocayloptimist came out this week. I gave it 4.5/5 stars, and I think the world would be better off if more people saw it. I am not generally a fan of documentary movies, but this is probably my new favorite, replacing The King of Kong: A Fistful of Quarters. There was also the usual background hum of quite a lot of thin
Start Small to Build Value through Digital Twin
The Future Ready podcast launched recently, offering a new channel where listeners can hear from Siemens and guest experts as they discuss the key technologies, industry trends and other drivers of today’s rapidly changing industrial landscape. The podcast has already featured conversations on the transition to software-defined automation, the immense potential of Industrial AI and [ ]
Knowledge Map
Connected Articles — Knowledge Graph
This article is connected to other articles through shared AI topics and tags.
More in Products

How analytics and AI are reshaping the boundaries of IT leadership
IT leadership is under more pressure than ever. As analytics and AI become embedded in everyday operations, expectations of CIOs are expanding, often without clear agreement on where IT leadership begins and ends. Many organizations assume that strong IT leadership will naturally extend to analytics and AI. In practice, that assumption no longer holds. The challenge is not that IT leadership has become less important, but that it is no longer sufficient on its own. To understand why, it helps to be clear about what has changed, what has not and where the boundaries of IT leadership now sit. What hasn’t changed about IT leadership At its core, IT leadership remains about the enablement and stewardship of the organization’s technology environment and capabilities. In practice, this has alway

7 tips for rationalizing your application portfolio
A strong application portfolio is an essential IT resource. Ensuring that the portfolio is ready to meet enterprise operational and financial needs is essential to long-term business success. Unfortunately, applications tend to accumulate over time, leading to bloat that creates confusion, undermines efficiency, and introduces risk to the organization . Application rationalization streamlines an existing application portfolio to improve efficiency, reduce complexity, make room for innovation, and lower the total cost of ownership (TCO) through a specific set of processes. Application rationalization is a daunting task for any CIO. Here are seven tips that can make the process faster and easier. Be methodical and make use of metadata “Application management is periodically necessary to redu

The invisible AI adding value to World2Meet
As prevalent as AI implementation is, not all organizations approach it in the same way, or to the same degree. Many are still testing the technology, with specific and limited use cases, while others have integrated it in a way that’s transformative. The latter is the case for World2Meet (W2M), the travel division of global tourism company Iberostar Group, and a finalist in the Best AI and Intelligent Automation Project category at last year’s CIO 100 Awards for its Intelligent Process Automation (IPA) initiative. Seeing is believing W2M CIO Joan Barceló says IPA is essentially the invisible AI that’s truly delivering value. Launched in 2023 with the goal to explore everything that could be automated and equipped to gain efficiency and productivity, IPA began to deliver results in 2025.

The end of the org chart: Leadership in an agentic enterprise
Most security initiatives fail before the first line of code is written. Not because the technology is wrong, but because the problem was framed poorly from the start. Leaders often move fast toward familiar answers, then wonder why progress stalls. Last year, a global cybersecurity technology company brought me in to help run a Privileged Access Management proof of concept. On paper, it made sense. PAM was proven, defensible and easy to justify to cybersecurity leaders. The intent was legitimate and the urgency was real. Once we looked closer, the real issue became obvious. Centralizing PAM had no internal support. Stakeholders were wary, resisted heavy controls and were unconvinced it would help them do their jobs. Pushing forward would have burned credibility and months of effort. So we


Discussion
Sign in to join the discussion
No comments yet — be the first to share your thoughts!