Feature: Auto-compact and continue when context limit reached

Resolved 💬 3 comments Opened Feb 7, 2026 by lexabu Closed Feb 7, 2026

Problem

When working on long tasks, Claude Code hits the context limit and stops with "Context limit reached · /compact and continue". This requires manual intervention to run /compact and then re-prompt Claude to continue.

For autonomous workflows or long-running tasks, this interruption breaks the flow and requires babysitting.

Proposed Solution

Add an option to automatically compact and continue when the context limit is reached:

Option A: CLI flag

claude --auto-compact

Option B: Settings config

{
  "autoCompact": true
}

Option C: Environment variable

CLAUDE_AUTO_COMPACT=1 claude

Behavior

When enabled and context limit is reached:

  1. Automatically trigger compaction (equivalent to /compact)
  2. Resume the current task without user intervention
  3. Optionally log that compaction occurred

Use Cases

  • Long implementation tasks that span many files
  • Autonomous agent workflows
  • CI/CD pipelines using Claude Code
  • Any scenario where human-in-the-loop for compaction is undesirable

Alternatives Considered

  • Hooks: Current PreCompact and SessionStart hooks fire around compaction but cannot trigger it
  • Wrapper scripts: Fragile, don't integrate well with interactive mode
  • Larger context: Doesn't solve the fundamental issue, just delays it

Additional Context

This would complement the existing hook system nicely - users could still use SessionStart + "compact" matcher to restore critical context after auto-compaction.

View original on GitHub ↗

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