[BUG] Why is the 13K buffer (`nx1 = 13000`) needed in the autocompact threshold calculation?
Resolved 💬 3 comments Opened Nov 20, 2025 by tao2years Closed Jan 19, 2026
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?
In the npm package @anthropic-ai/claude-code, the file cli.js (or cli-new.js in the source) contains:
Definition:
var nx1 = 13000,
tyI = 20000,
eyI = 20000;
Usage:
function AkI() {
let A = s4A(), // Available input tokens
B = A - nx1, // Auto-compact threshold = Available - 13000
Q = process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE;
// ... environment variable override logic ...
return B
}
The nx1 = 13000 constant is used to calculate the auto-compact threshold by subtracting 13K from the available input tokens.
🔍 Current Understanding
Based on code analysis, the 13K buffer appears to be designed to:
- Reserve space for the compression prompt (~2,000 tokens)
- Account for system overhead (~720 tokens)
- Provide a safety margin for token counting errors
However, there is no comment or documentation explaining:
- Why exactly 13,000 tokens?
- What is the calculation basis?
- Why not 3K, 5K, or 10K?
What Should Happen?
🧪 Experimental Findings
I conducted experiments modifying the nx1 value:
- Changed to 3K (
nx1 = 3000):
- ✅ System runs normally
- ✅ Compression works correctly
- ✅ Model receives more context
- Changed to 0 (
nx1 = 0):
- ✅ System runs normally
- ✅ Compression works correctly
- ✅ Model receives even more context
❓ Questions
- Why is 13K specifically chosen?
- Is this an empirical value from testing?
- Is there a specific calculation or formula?
- What edge cases does 13K protect against that 3K or 0 cannot?
- Is 13K necessary?
- My experiments show that 3K and even 0 work fine
- The actual compression prompt only needs ~2,720 tokens
- Why reserve 13K when only ~2.7K is actually used?
- What are the risks of reducing it?
- Are there specific scenarios where 13K is critical?
- Does it depend on model type, context size, or other factors?
- What happens in edge cases with very large contexts?
- Documentation request:
- Could you add comments explaining the rationale for 13K?
- Or provide documentation on how this value was determined?
This has been puzzling me for a while.
Error Messages/Logs
Steps to Reproduce
- change 13k -> 3k or sth else
- work until auto compression
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.28
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗