[BUG] Context auto-compaction re-enters plan mode without user request
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 context auto-compaction occurs during a session where plan mode was previously active (but the user had moved past it to other tasks), Claude re-enters plan mode after compaction completes. The user did not request plan mode — the post-compaction state restoration incorrectly resumed a stale planning context instead of the most recent activity.
This is especially disruptive because once re-entered, plan mode has no cancel/abort path (see #26520), so the user is trapped in a state they didn't initiate. The only escape is /clear, which destroys all session context.
What Should Happen?
Post-compaction state restoration should resume from the most recent user activity, not from an earlier plan mode state the user had already moved past. If the user completed a plan, persisted it, and moved on to other tasks, compaction should restore the session to those subsequent tasks — not re-enter plan mode.
Steps to Reproduce
- Enter a session and begin work that involves plan mode.
- Complete the plan. When ExitPlanMode is presented, instruct Claude to persist the plan file to disk and move on to other tasks instead of approving.
- Continue working on other tasks (file writes, tool calls, etc.) until the context window fills.
- Allow auto-compaction to trigger.
- Observe: after compaction, Claude re-enters plan mode for the earlier plan rather than resuming the most recent task.
- Attempting to exit plan mode without approving triggers the gridlock described in #26520.
Claude Model
Opus
Is this a regression?
Not sure
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Related: #26520 (ExitPlanMode lacks defer/abandon option). That issue covers the gridlock UX once stuck in plan mode. This issue is specifically about compaction incorrectly re-entering plan mode — a distinct root cause that amplifies the #26520 problem by putting users into the gridlock state without their consent.
Duplicate search performed: Searched "auto-compaction plan mode", "context compaction plan mode", "plan mode stuck", "ExitPlanMode", and "planning mode stuck". No existing issues cover the compaction-triggered re-entry scenario. Closest match is #26520 (gridlock UX) and #29371 (compaction aggressiveness near completion), but neither addresses compaction restoring stale plan mode state.
Claude Code version: 2.1.63
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗