[BUG] Context overflow 400 on self-hosted model after updating to 2.1.296: compaction doesn’t prevent or recover from “maximum context length” error
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?
After updating Claude Code from 2.1.269 to to 2.1.296, sessions using a self-hosted model fail with a 400 context-length error. The same setup ran on 2.1.269 without hitting this.
Downgrading to 2.1.269 fixes it. With the same settings, server, and model,
the error no longer occurs. The regression is somewhere between 2.1.270 and 2.1.296.
On 2.1.296, Claude Code sends a request where input + max_tokens exceeds the model's window,
even though the window is configured, and it doesn't recover by compacting.
Every later request in the session fails with the same error.
What Should Happen?
Expected behavior
- Auto-compaction triggers at around 220k (autoCompactWindow), so input + 32k
output stays under 262144.
- If the server still rejects a request for context length, Claude Code compacts
and retries, as it does for Anthropic's "Prompt is too long" error.
Actual behavior
- The conversation reaches 230145 input tokens despite autoCompactWindow=220000.
- The OpenAI-compatible error wording ("maximum context length") doesn't seem to
trigger the reactive compaction or retry path.
- The session can't continue.
Error Messages/Logs
API Error: 400 This model's maximum context length is 262144 tokens. However, you
requested 32000 output tokens and your prompt contains at least 230145 input tokens,
for a total of at least 262145 tokens. Please reduce the length of the input prompt
or the number of requested output tokens. (parameter=input_tokens, value=230145)
Steps to Reproduce
Settings (~/.claude/settings.json)
{
"model": "qwen3.8-flash-next-nvfp4",
"autoCompactWindow": 220000,
"env": {
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "262144",
"CLAUDE_CODE_MAX_OUTPUT_TOKENS": "32000"
}
}
Environment
- Claude Code: 2.1.296 (previously 2.1.269 version, worked fine)
- OS: Ubuntu 26.04.1 LTS
- Backend: vLLM serving qwen3.8-flash-next-nvfp4
- Server context limit (max-model-len): 262144
Steps to reproduce
- Configure Claude Code against a self-hosted model with a 262144-token window
using the settings above.
- Run a long session until the context grows past ~220k tokens.
- The request fails with the 400 above instead of auto-compacting first.
- Rewind the session back before the failure
- Resuming the session after a few minutes fails the same way, with the same input count (230145).
Claude Model
Other
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.269
Claude Code Version
2.1.296 (Claude Code)
Platform
Other
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Xterm
Additional Information
Workaround
Downgrade to 2.1.269:
curl -fsSL https://claude.ai/install.sh | bash -s 2.1.269
Possibly related changelog entries (all within 2.1.270–2.1.296)
- 2.1.288: first request using the built-in output limit and auto-compact window
instead of the server's
- 2.1.288: /autocompact now saves the window per model (modelSettings)
- 2.1.288: "Prompt is too long" fix when the last reply reported zero token usage
- 2.1.285: sessions behind a custom ANTHROPIC_BASE_URL use the 1M window for
models that have one
- 2.1.284: recompaction when a compacted request is still too long