[BUG] Auto compact fails silently inside /goal — requires manual Ctrl+C interruption for compaction to trigger

Resolved 💬 3 comments Opened May 12, 2026 by uditgoenka Closed May 16, 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?

When running a long-duration task under /goal (e.g., 2+ hours of continuous E2E browser testing), auto compact never fires even as the context window fills up. The agent eventually hits the context limit and the session dies — losing all accumulated context, in-progress work, and requiring a full restart.

The only workaround is for the user to manually press Ctrl+C (interrupt the agent), which triggers the compaction. After compaction completes, the agent resumes correctly. But without manual intervention, the context just grows until the session crashes.

In my testing session, this happened 6 times over ~2.5 hours. Each time:

  1. Context grew unbounded while the agent was actively working (calling MCP tools, writing reports, filing GitHub issues)
  2. No automatic compaction triggered
  3. Session froze or crashed
  4. I had to Ctrl+C, wait for compaction, then tell the agent to "Continue"

This defeats the purpose of auto compact — it's supposed to be automatic, especially during long autonomous sessions where the user shouldn't need to babysit context management.

What Should Happen?

  1. Auto compact should trigger normally inside /goal sessions — the stop hook evaluation should not prevent or interfere with context compaction
  2. Compaction should fire proactively before the context limit is hit, not after the session crashes
  3. The agent should seamlessly continue after compaction without requiring user intervention ("Continue")
  4. Long-running autonomous tasks (like 2h browser testing under /goal) should be able to run unattended without the user needing to manually trigger compaction via Ctrl+C

Steps to Reproduce

  1. Set a long-running /goal:

``
/goal Run E2E browser tests on app.autoposting.ai for 2 hours straight. Find bugs, file GitHub issues.
``

  1. Let the agent work autonomously — it will call MCP tools (browser automation), write files, create GitHub issues, take screenshots, etc.
  2. After 30-60 minutes of continuous work, the context window fills up
  3. Expected: Auto compact triggers, compresses prior context, agent continues seamlessly
  4. Actual: No compaction occurs. The session either:
  • Freezes (agent stops responding, tools hang)
  • Crashes with context limit error
  • The stop hook fires but the agent cannot respond because context is full
  1. Only way to recover: Ctrl+C → compaction triggers → agent resumes after user says "Continue"
  2. This cycle repeats every 30-60 minutes throughout the session

Error Messages/Logs

No explicit error message. The session just stops responding. After Ctrl+C:

⚠️ CONTEXT COMPACTED - APPROVAL STATE CHECK:
If you were waiting for user approval via AskUserQuestion (e.g., Step 4 review gate),
you MUST re-confirm with the user before proceeding. Do NOT assume approval was given.

The compaction system reminder confirms compaction only happened because of the manual interrupt, not automatically.

Claude Model

Opus 4.6

Is this a regression?

Not sure — this is the first time I've run /goal for 2+ hours continuously

Last Working Version

_No response_

Claude Code Version

2.1.139

Platform

Anthropic API (Claude Max)

Operating System

macOS (Darwin 25.3.0)

Terminal/Shell

zsh

Additional Information

  • Related to my other /goal bug: #58348 (stop hook infinite loop)
  • The stop hook may be interfering with the compaction check — possibly the hook evaluation consumes the window where compaction would normally trigger
  • Session drops in my test: 6 total (3 from context exhaustion / failed auto-compact, 1 browser crash, 1 explicit context compaction that worked, 1 production 502 outage)
  • Each manual recovery costs ~2-5 minutes of lost momentum + token waste re-establishing context
  • Over a 2.5h session, this added up to ~15-20 minutes of downtime just from compaction failures
  • Workaround: Manually Ctrl+C every ~30 minutes to force compaction before the context limit is hit

View original on GitHub ↗

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