Context limit reached breaks /compact — conversation becomes unrecoverable
Bug
When a session hits the context limit, /compact also fails with:
Error: Error during compaction: Error: Conversation too long. Press esc twice to go up a few messages and try again.
This leaves the user stuck — can't continue, can't compact, forced to /clear and lose all session context.
Steps to reproduce
- Work on a multi-task session with many file reads/edits (7+ tasks involving code exploration, editing, and testing)
- Eventually the context fills up and tool calls start showing "Context limit reached"
- Run
/compact /compactitself fails because the conversation is too long for the compaction prompt
Expected behavior
/compact should always work, even when at the context limit. It should be able to summarize and truncate the conversation regardless of current length — this is precisely when it's needed most.
Actual behavior
/compact fails with the same context limit error, creating an unrecoverable state where the only option is /clear which loses all working context.
Environment
- Claude Code CLI
- Observed across multiple sessions with extended multi-task workflows
Suggestion
Reserve headroom for the compaction prompt so it can always execute, or implement a fallback compaction strategy (e.g., aggressive truncation) when the standard compaction can't fit.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗