3 Lines of Code Saved Anthropic 250K API Calls Per Day
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 conversat...

Source: DEV Community
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; 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 w