[BUG] `CLAUDE_CODE_AUTO_COMPACT_WINDOW` is capped at the hardcoded model context window size (preventing larger context for custom APIs)
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?
I am using Claude Code with a custom API endpoint (ANTHROPIC_BASE_URL) and custom models that support a larger context window (e.g., 1M tokens). However, I've observed that CLAUDE_CODE_AUTO_COMPACT_WINDOW only works when the value is smaller than the model's hardcoded default (200k).
If I set a value larger than 200k (e.g., 1,000,000), the setting appears to be ignored , and Claude Code triggers compaction at the default 200k limit.
Observed Behavior
- If
CLAUDE_CODE_AUTO_COMPACT_WINDOWis set to100,000(less than 200k), compaction correctly triggers at 100k. - If
CLAUDE_CODE_AUTO_COMPACT_WINDOWis set to1,000,000(greater than 200k), compaction triggers at the hardcoded 200k limit.
What Should Happen?
CLAUDE_CODE_AUTO_COMPACT_WINDOW should be honored even if it exceeds the hardcoded default window size, especially when using custom base URLs where the model's physical limit might be higher than Claude's standard 200k.
Error Messages/Logs
Steps to Reproduce
- Use a custom API and model that supports > 200k tokens.
``bash``
export ANTHROPIC_BASE_URL=http://your-custom-endpoint
export ANTHROPIC_DEFAULT_OPUS_MODEL=your-1m-context-model
- Launch Claude Code with a large compaction window:
``bash``
CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 claude
- Monitor the token usage and compaction behavior.
Claude Model
Other
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.138
Platform
Other
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗