Compaction fails with 'Conversation too long' due to identical warning/error thresholds
Bug Description
Compaction can fail with "Conversation too long. Press esc twice to go up a few messages and try again." in an unrecoverable state, especially when running multiple parallel agents or rapid tool usage.
Root Cause (from v2.0.76 bundle analysis)
The warning and error thresholds are identical in the code:
var Ty5=20000, Py5=20000; // Both 20K tokens from threshold
function T9A(A){
let Q=zT2(),
B=Hd()?Q:EHA(),
Z=B-Ty5, // Warning threshold
Y=B-Py5, // Error threshold (SAME as warning!)
J=A>=Z, // isAboveWarningThreshold
X=A>=Y; // isAboveErrorThreshold
// ...
}
Since Ty5 === Py5 === 20000, both isAboveWarningThreshold and isAboveErrorThreshold trigger at the exact same token count. This gives users no advance warning before hitting the hard limit.
Steps to Reproduce
- Start a conversation and accumulate context (e.g., reading multiple files)
- Launch 3-4 parallel Task agents that generate significant output
- Wait for agents to complete and return results
- Observe "Context low" warning appears
- Attempt
/compact- fails with "Conversation too long" - User is now in unrecoverable state
Expected Behavior
- Warning threshold should trigger before error threshold (e.g.,
Ty5=30000, Py5=20000) - This would give users ~10K tokens of buffer to manually compact before hitting the hard limit
- Compaction should have a pre-flight check to fail gracefully before making an API call that will exceed context
Actual Behavior
- Warning and error thresholds fire simultaneously
- By the time user sees "Context low", compaction may already be impossible
- The compaction API call itself can exceed context window, causing the error
- User must lose conversation history to recover
Additional Issues Identified
- No pre-flight validation: Code doesn't verify the conversation will fit before making compaction API call
- Race condition: Messages continue accumulating during the 15-60 second compaction window
- Token estimation: The 1.33x multiplier may underestimate actual usage
Suggested Fix
// Change from:
var Ty5=20000, Py5=20000;
// To (example):
var Ty5=30000, Py5=20000; // 10K token buffer between warning and error
This creates a graduated warning system where users have time to react.
Environment
- Claude Code version: 2.0.76
- OS: Windows 11 (MSYS2/Git Bash)
- Scenario: Running multiple parallel agents via Task tool
Workaround
Use /context frequently and manually /compact at ~85% usage, before the warning appears.
🤖 Generated with Claude Code
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/13889
- https://github.com/anthropics/claude-code/issues/14274
- https://github.com/anthropics/claude-code/issues/15765
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code