/compact fails with 'Conversation too long' when context limit is reached
Bug Description
/compact fails with an error when the conversation reaches the context limit — the exact situation where /compact is needed most. This creates a deadlock: the user cannot compact, cannot continue, and is forced to /clear (losing all context).
Steps to Reproduce
- Use Claude Code in a long session until "Context limit reached · /compact or /clear to continue" appears
- Run
/compact - Observe the error
Error Messages
First attempt:
❯ /compact
Error: Error during compaction: Error: Conversation too long. Press esc twice to go up a few messages and try again.
Subsequent attempts — same error, then the session becomes completely unresponsive:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must contain non-whitespace text"},"request_id":"req_011CXnuVCF3KmwzeqdM4gFNZ"}
Expected Behavior
/compact should always succeed, especially when the context limit is reached. Possible approaches:
- Progressively drop older messages before attempting compaction
- Use a smaller/faster model for the compaction summary when context is too large
- Truncate the conversation to fit within limits before summarizing
Environment
- Claude Code version: 2.1.31
- OS: Ubuntu Linux 6.8.0-94-generic (x86_64)
- Model: claude-opus-4-5-20251101
Impact
High — This is a Catch-22: /compact is the recommended action when context is full, but it fails precisely in that situation. The only workaround is /clear, which destroys all session context including task progress. This happens consistently across sessions and projects.
Additional Context
The "Press esc twice to go up a few messages and try again" suggestion does not help — the error persists regardless. After the compaction failure, the session often enters a broken state where even normal messages fail with the text content blocks must contain non-whitespace text API error.
21 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
I can confirm this regression. My workflow has been processing book content (reading 10-20+ chapter files,
synthesizing notes) reliably for hundreds of books over the past weeks as I use it to take notes on ebooks I want to read.
This morning (Feb 4), the same workflow started hitting context limits and
/compactfails to recover. I've tried:Same result each time - context fills up and
/compactdoesn't help, forcing/clearwhich loses all work progress.Environment:
Workflow that broke:
This started immediately after updating to recent versions. The timing aligns with the v2.1.30 session memory changes.
Mine either fails because 'Conversation too long', or doesn't even do anything and just stays idle, always showing 0 tokens consumed.
In summary I can't even compact the conversation at all at this point, not even restarting CC like when the 'Conversation too long' issue appeared in the past. I have to always start a new session from scratch, honestly this sucks badly.
Same issue
❯ /compact
⎿ Error: Error during compaction: Error: Conversation too long. Press esc twice to go up a few messages and try again.
model: Sonnet 1M context
Additional severity report: In some cases this is worse than just
/compactfailing — the app becomes completely bricked.When context limit is reached with a sufficiently large conversation (heavy CLAUDE.md + many skills + MCP servers):
/compactfails: "Conversation too long"/clearis also blocked — the context limit gate blocks ALL input, including recovery commandsThis is not just data loss from
/clear— it's a complete app freeze requiringkill/Ctrl+C/close terminal.Screenshot from my session showing the deadlock: https://github.com/anthropics/claude-code/issues/23809
Environment: macOS, latest Claude Code, large project with extensive CLAUDE.md, 30+ skills, and MCP servers.
Experiencing the same issue — Claude Code in VS Code integrated terminal
Hitting this exact same compaction deadlock on Claude Code 2.1.32, running Opus 4.6 inside the VS Code integrated terminal on the
batch-processorbranch of a medical imaging application project.Environment:
The session becomes completely unrecoverable after this error. The "press esc twice" suggestion does nothing. Auto-compact also fails to trigger before the context reaches this broken state.
This is a critical workflow blocker — the tool is unusable for any non-trivial session that runs long enough to need compaction, which is exactly the scenario where it's needed most.
lol, back to 2.0.65 for me; I finally upgraded (stopped following
stablewhen they removed theTabthinking toggle) for 4.6, but this bug isn't worth itEDIT: Steps I took for recovery, for any unlucky souls who are facing a bricked session
2.0.65(verify withclaude --versionafter)/statusin the bricked session to get your session IDjsonl(which has one line per message (ish))EDIT 2: Forgot to add this because _I_ forgot, add this to your
~/.claude/settings.jsonto make the downgrade stick:this github-actions bot in this repo is unhinged. makes users go around in circles endlessly from one issue to another. its impossible to reach the issue that is not a duplicate, if all others are. scatters community attention needlessly.
saaame
Same here
I have hit the exact same issue on version
2.1.39. This is one of the worst bugs the app could possibly have. It makes long running sessions impossible. This needs to be fixed ASAP.Up Up
Hey folks, we've made some fixes to help with this bug - which will go out in the next release after 2.1..42 (has not been released at time of posting this comment). Going to keep this open until I've receive confirmations that it's fixed.
If you still run into this please
/bugand send me your feedback ids. Makes it much easier to debugAdding my voice here. Max subscriber, Opus 4.6, macOS, 600+ sessions.
We hit this exact deadlock during a 72-hour client sprint — three concurrent 1M context sessions all rate-limited simultaneously. Couldn't compact any of them because compaction requires an API call, which was rate-limited. Filed #26575 about the rate-limit variant of this same deadlock.
What saved us: we'd already built a persistent state system (memory files on disk that the agent writes to continuously, not just at session end). When compaction nukes working memory, our agent can reconstruct from disk. Without that, we'd have lost hours of creative decisions, client corrections, and technical state. We built it because we got burned enough times.
fadedlamp42's recovery procedure (downgrade + JSONL recovery) is the kind of thing that should be in official docs.
The fundamental issue is what Memphizzz described in #18027 — the agent can't see its own fuel gauge. If it could, it would save state before the crisis, and the deadlock wouldn't matter because the important context would already be on disk.
Appreciate everyone documenting this so clearly. The regression identification (broke around Feb 4 / v2.1.30) and the 74% trigger (russ2370) are both really useful data points.
This issue is very much not fixed, still getting this constantly, nearly every single longer conversation I have with Claude Code/Opus I run into this multiple times and either have to go REALLY far back in the history or start over and waste a ton of tokens reexplaining everything.
FWIW, on standard context, I am able to work around this Catch-22 by adding context, running compact, then reverting to the previous standard content, if desired. /model sonnet[1m] still works when you're stuck in this loop, but of course adds to your pay-as-you go.
Of course, if you're already at 1m, this doesn't help.
Related: #29957 proposes a proactive solution to this — topic-aware fork prompts to prevent context bloat, overflow-to-file recovery instead of data loss on compaction, and graduated warnings before the emergency. If this problem matters to you, a thumbs-up there would help consolidate the signal.
Environment:
Experience:
/compactfailed 5+ consecutive times with:Auto-compaction also did not trigger. The session was completely stuck — no way to continue, no way to compact. The only option was
/clear, which lost the entire session context including a pending request for a summary of work done.Pressing Esc twice as suggested in the error message had no effect.
This is a workflow blocker for any non-trivial session. The compaction mechanism needs to work precisely when conversations are long — that's its entire purpose.
Adding a +1 and a specific use case that I think sharpens the "natural break" framing:
The most impactful version of this feature, from a UX perspective, is compaction triggered immediately after Claude finishes delivering a response — not before the next user message, not mid-tool-chain, but in the ~5–30 seconds while the user is reading the response they just received.
Why the timing matters as much as the threshold:
The current experience in long sessions:
User sends message
Claude starts responding
Context limit hit → compaction interrupts → user waits
User gets response, already frustrated
The desired experience:
User sends message → Claude responds fully
[background: context at 80% → compaction runs while user reads]
User types next message → context is already clean, no wait
The user is always reading after a response. That's the only moment in the conversation where they're guaranteed to not be waiting on Claude. Using that window for compaction is zero-cost from a perceived latency standpoint.
Proposed settings.json:
{
"autoCompactThreshold": 0.80,
"autoCompactTiming": "after-response"
}
after-response would mean: once the final token of a response is delivered, if context usage exceeds autoCompactThreshold, begin compaction in the background. Queue the next user message until compaction completes (which by then may already be done).
This pairs naturally with the "Compact at next natural break" mode described in the original issue — I'd just argue the break should be after delivery, not before the next prompt.
This is a duplicate of #2038, which was fixed as of version 2.1.85.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.