claude-code - 💡(How to fix) Fix [BUG] Auto compact fails silently inside /goal — requires manual Ctrl+C interruption for compaction to trigger

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  • Crashes with context limit error

Error Messages/Logs

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

Root Cause

  1. Set a long-running /goal:
    /goal Run E2E browser tests on app.autoposting.ai for 2 hours straight. Find bugs, file GitHub issues.
  2. Let the agent work autonomously — it will call MCP tools (browser automation), write files, create GitHub issues, take screenshots, etc.
  3. After 30-60 minutes of continuous work, the context window fills up
  4. Expected: Auto compact triggers, compresses prior context, agent continues seamlessly
  5. 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
  6. Only way to recover: Ctrl+C → compaction triggers → agent resumes after user says "Continue"
  7. This cycle repeats every 30-60 minutes throughout the session

Fix Action

Fix / Workaround

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.

  • 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

Code Example

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

---

⚠️ 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.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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.
  2. Let the agent work autonomously — it will call MCP tools (browser automation), write files, create GitHub issues, take screenshots, etc.
  3. After 30-60 minutes of continuous work, the context window fills up
  4. Expected: Auto compact triggers, compresses prior context, agent continues seamlessly
  5. 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
  6. Only way to recover: Ctrl+C → compaction triggers → agent resumes after user says "Continue"
  7. 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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING