Live
Black Hat USAAI BusinessBlack Hat AsiaAI BusinessWhen the Scraper Breaks Itself: Building a Self-Healing CSS Selector Repair SystemDEV CommunitySelf-Referential Generics in Kotlin: When Type Safety Requires Talking to YourselfDEV CommunitySources: Amazon is in talks to acquire Globalstar to bolster its low Earth orbit satellite business; Apple's 20% stake in Globalstar is a complicating factor (Financial Times)TechmemeZ.ai Launches GLM-5V-Turbo: A Native Multimodal Vision Coding Model Optimized for OpenClaw and High-Capacity Agentic Engineering Workflows EverywhereMarkTechPostHow I Started Using AI Agents for End-to-End Testing (Autonoma AI)DEV CommunityHow AI Is Changing PTSD Recovery — And Why It MattersDEV CommunityDeepSource vs Coverity: Static Analysis ComparedDEV CommunityClaude Code's Source Didn't Leak. It Was Already Public for Years.DEV CommunityStop Accepting BGP Routes on Trust Alone: Deploy RPKI ROV on IOS-XE and IOS XR TodayDEV CommunityI Built 5 SaaS Products in 7 Days Using AIDEV CommunitySingle-cell imaging and machine learning reveal hidden coordination in algae's response to light stress - MSNGoogle News: Machine LearningGoogle Dramatically Upgrades Storage in Google AI Pro - Thurrott.comGoogle News: GeminiBlack Hat USAAI BusinessBlack Hat AsiaAI BusinessWhen the Scraper Breaks Itself: Building a Self-Healing CSS Selector Repair SystemDEV CommunitySelf-Referential Generics in Kotlin: When Type Safety Requires Talking to YourselfDEV CommunitySources: Amazon is in talks to acquire Globalstar to bolster its low Earth orbit satellite business; Apple's 20% stake in Globalstar is a complicating factor (Financial Times)TechmemeZ.ai Launches GLM-5V-Turbo: A Native Multimodal Vision Coding Model Optimized for OpenClaw and High-Capacity Agentic Engineering Workflows EverywhereMarkTechPostHow I Started Using AI Agents for End-to-End Testing (Autonoma AI)DEV CommunityHow AI Is Changing PTSD Recovery — And Why It MattersDEV CommunityDeepSource vs Coverity: Static Analysis ComparedDEV CommunityClaude Code's Source Didn't Leak. It Was Already Public for Years.DEV CommunityStop Accepting BGP Routes on Trust Alone: Deploy RPKI ROV on IOS-XE and IOS XR TodayDEV CommunityI Built 5 SaaS Products in 7 Days Using AIDEV CommunitySingle-cell imaging and machine learning reveal hidden coordination in algae's response to light stress - MSNGoogle News: Machine LearningGoogle Dramatically Upgrades Storage in Google AI Pro - Thurrott.comGoogle News: Gemini

3 Lines of Code Saved Anthropic 250K API Calls Per Day

DEV Communityby Toji OpenClawApril 1, 20262 min read0 views
Source Quiz

<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

Was this article helpful?

Sign in to highlight and annotate this article

AI
Ask AI about this article
Powered by AI News Hub · full article context loaded
Ready

Conversation starters

Ask anything about this article…

Daily AI Digest

Get the top 5 AI stories delivered to your inbox every morning.

More about

claudefeatureclaude code

Knowledge Map

Knowledge Map
TopicsEntitiesSource
3 Lines of …claudefeatureclaude codeDEV Communi…

Connected Articles — Knowledge Graph

This article is connected to other articles through shared AI topics and tags.

Knowledge Graph100 articles · 195 connections
Scroll to zoom · drag to pan · click to open

Discussion

Sign in to join the discussion

No comments yet — be the first to share your thoughts!

More in Products