[BUG] Compaction death spiral - 211 compactions consuming all tokens with zero progress

Resolved 💬 12 comments Opened Feb 8, 2026 by tckwgd Closed Apr 18, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Description

A conversation entered an infinite compaction loop, triggering 211 compactions in a single session. 95% of these were rapid-fire (≤10 lines apart),
making zero meaningful progress while consuming my entire token quota.

What Happened

The session had 3 phases:
┌─────────────────────────┬─────────────┬────────────────────────────────────────────────────────────────────────┐
│ Phase │ Lines │ Description │
├─────────────────────────┼─────────────┼────────────────────────────────────────────────────────────────────────┤
│ Normal work │ 0–308 │ Running tools, editing files, building Xcode project — everything fine │
├─────────────────────────┼─────────────┼────────────────────────────────────────────────────────────────────────┤
│ Work with interruptions │ 308–996 │ 149 tool calls completed despite occasional compaction │
├─────────────────────────┼─────────────┼────────────────────────────────────────────────────────────────────────┤
│ Death spiral │ 1,053–2,534 │ ~200 compactions in a loop, no meaningful work done │
└─────────────────────────┴─────────────┴────────────────────────────────────────────────────────────────────────┘
In the death spiral, the model repeated this cycle endlessly:

compact → read summary → attempt to read a file → context full → compact → read summary → attempt same file → context full → ...

The model was trying to fix a Python script (convert_to_ios.py), but every time it read the file, the context window filled up and triggered
another compaction. It never had enough remaining context to actually edit the file.

Root Cause

The system context consumed nearly the entire context window, leaving almost no room for actual work:

  1. Massive git status: Hundreds of untracked files (generated PNG images with long paths) — the git status alone was enormous
  2. Large CLAUDE.md files: Project had detailed specification docs loaded into system context
  3. MEMORY.md: Additional persistent memory content
  4. Compaction summary itself: Each summary was substantial, further reducing available space

After compaction, the system prompt + summary + git status already approached the context limit. Reading even one file pushed it over, triggering
re-compaction immediately.

Evidence

  • Transcript file: 17MB, 2,670 lines
  • 211 compaction events detected in the transcript
  • 201 (95%) were rapid-fire with ≤10 lines between them
  • The spiral consumed 1,599 lines of transcript with no useful output
  • User had to manually interrupt after noticing the session was stuck

Expected Behavior

  1. Circuit breaker: After N consecutive compactions (e.g., 3–5) without meaningful tool calls between them, the system should stop and notify the

user instead of continuing the loop

  1. User visibility: Show a warning when compaction frequency is abnormally high (e.g., "Context is too constrained to make progress")
  2. Smart context management: When system context (git status, CLAUDE.md, etc.) consumes most of the window, the system should detect this and

either trim the git status or warn the user

  1. Token protection: Set a maximum compaction count per session to prevent unbounded token consumption

Impact

  • Entire token quota exhausted with zero productive output
  • User had no clear indication of what was happening — only saw repeated "compacting" status
  • No self-recovery — the model could not detect or escape the loop

Environment

  • Claude Code version: 2.1.37
  • Model: claude-opus-4-6
  • Platform: macOS (Darwin 25.2.0, ARM64)
  • Session ID: 45e02365-ab02-46dd-9a15-bfe6cff9fd88

What Should Happen?

When the system detects that compaction is occurring repeatedly without meaningful progress (e.g., 3–5 consecutive compactions with no successful
tool calls between them), it should:

  1. Stop the loop automatically and display a clear error message to the user, such as: "Context is too constrained to make progress. Consider

starting a new session or reducing system context (e.g., commit/gitignore untracked files)."

  1. Not consume additional tokens on futile compaction cycles.

Currently, there is no circuit breaker — my session ran 211 compactions in a row, consuming my entire token quota with zero useful output and no
user-facing warning.

Error Messages/Logs

Steps to Reproduce

  1. Open a project with a large system context:
  • Large CLAUDE.md file (detailed project specs)
  • Large MEMORY.md file
  • Hundreds of untracked files in git (e.g., generated PNG images), causing git status output to be very large
  1. Start a long, multi-step coding task that involves reading and editing files (in my case: fixing bugs in a Python script + building an Xcode

project)

  1. Continue working in the same session as context accumulates
  2. Once the first compaction triggers, the system context (git status + CLAUDE.md + MEMORY.md + compaction summary) fills nearly the entire context

window

  1. The model attempts to read a file, context overflows, triggers another compaction — entering an infinite loop

Key condition: The system context alone must be large enough that after compaction, there is insufficient room to read even one file without triggering re-compaction.

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.34

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

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