Context compaction retries loop burns ~1M tokens with no user present

Resolved 💬 3 comments Opened Mar 30, 2026 by josephrobertlopez Closed Apr 3, 2026

Description

5 context compaction agents fired within 5 minutes (6:52-6:57 AM local time) on an idle session with no user input. Each carried ~19MB / ~200K tokens of context. Estimated total burn: ~1M tokens in 5 minutes while user was asleep.

The compaction itself exceeded context limits, triggering re-compaction in a loop. Logs show [earlier conversation truncated for compaction retry] on 3 of the 5 agents.

Evidence

Session log directory: ~/.claude/projects/-home-joey-media-server/*/subagents/

| Timestamp | Agent | Size | Lines |
|-----------|-------|------|-------|
| 6:52 AM | agent-acompact-0b188092b718f82d | 19.2 MB | 2,337 |
| 6:53 AM | agent-acompact-3ae4b3560187e9c7 | 18.9 MB | 2,251 |
| 6:53 AM | agent-acompact-705f6753f13dd884 | 19.0 MB | 2,285 |
| 6:53 AM | agent-acompact-e35eb9dcc7256dfd | 19.1 MB | 2,310 |
| 6:57 AM | agent-acompact-11d79a9ad14cea76 | 19.2 MB | 2,348 |
| Total | | 95.3 MB | 11,531 |

The parent session main log was 23MB / 3,430 lines — a long-running session with multiple subagents that had been idle for hours before the compaction loop started.

Expected Behavior

  • Compaction should cap retries (e.g., max 2 attempts)
  • If compaction itself exceeds limits, fail gracefully with a message like "Session too large to compact — use /clear or start a new session"
  • Compaction should not fire on idle sessions with no pending user input
  • There should be a configurable setting for max compaction retries

Actual Behavior

Compaction retried 5 times in 5 minutes, each time re-processing the full ~19MB context, burning approximately 1M tokens total. No user was at the keyboard. No error was surfaced.

Impact

This consumed roughly 10% of a weekly Opus token budget in 5 minutes with no user-facing value produced.

Environment

  • Claude Code CLI (latest as of 2026-03-30)
  • Model: Claude Opus 4.6 (1M context)
  • OS: Fedora 43 (Linux 6.18.13)
  • Session context: Long-running session with ~106 subagents across 2 days, main log grew to 23MB before compaction triggered
  • The session included subagents searching arXiv for paper endorsement emails

Suggested Fix

  1. Cap compaction retries (max 2)
  2. Exponential backoff between retries
  3. Don't retry compaction if the compacted output itself exceeds limits — surface an error instead
  4. Add a maxCompactionRetries setting to settings.json
  5. Don't trigger compaction on sessions with no pending user message

🤖 Generated with Claude Code

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗