Autocompact fails to free sufficient space, leaves session stuck at context limit

Resolved 💬 3 comments Opened Feb 16, 2026 by iclaudiumihaila Closed Feb 19, 2026

Bug Description

After hitting the context limit, autocompact runs for a long time (~3 minutes) but fails to free enough space to continue. The session becomes stuck showing "Context limit reached · /compact or /clear to continue" with no way to proceed other than /clear.

Steps to Reproduce

  1. Use claude-opus-4-6 with a 200k context window
  2. Work on a multi-file coding session with agents, MCP tools, memory files, and skills loaded
  3. Eventually hit the context limit

Observed Behavior

After autocompact finishes:

  • Model: claude-opus-4-6 · 156k/200k tokens (78%)
  • Autocompact buffer: 33k tokens (16.5%)
  • Free space: 8k (3.9%)
  • Crunched for: 2m 57s

Despite spending ~3 minutes crunching, only 8k of free space was recovered — not enough to continue the conversation. The session is effectively dead, requiring /clear.

The breakdown:

  • System prompt: 5.6k (2.8%)
  • System tools: 19.2k (9.6%)
  • MCP tools: 5.7k (2.9%)
  • Custom agents: 488 tokens (0.2%)
  • Memory files: 10.8k (5.4%)
  • Skills: 2.4k (1.2%)
  • Messages: 115k (57.5%)
  • Free space: 8k (3.9%)
  • Autocompact buffer: 33k (16.5%)

Expected Behavior

Autocompact should either:

  1. Free enough space to allow at least a few more turns (e.g., compress messages more aggressively)
  2. Not take ~3 minutes if it can't meaningfully reduce context size
  3. Provide a better fallback (e.g., offer to drop old tool results, MCP tool definitions, or agent context)

Environment

  • Claude Code version: 2.1.42
  • Model: claude-opus-4-6 (200k context)
  • OS: macOS (Darwin 23.5.0)
  • Heavy system prompt load: ~44k tokens in non-message overhead (system prompt + tools + MCP + memory + skills + agents)

Screenshot

!Context limit after autocompact

Additional Context

The non-message overhead (system tools, MCP tools, memory files, skills, agents) consumes ~44k tokens (22%), and the autocompact buffer reserves another 33k (16.5%). This leaves only ~123k tokens for actual messages. With aggressive tool use (agents, browser automation, file reads), this fills up quickly, and autocompact can't compress enough to keep going.

Possible improvements:

  • More aggressive message compression (summarize tool results more aggressively)
  • Dynamic autocompact buffer sizing based on overhead
  • Allow users to configure which context categories to prioritize/drop
  • Smarter eviction of stale MCP tool definitions or old agent results

View original on GitHub ↗

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