Repository navigation
fix(claude): declare the model context window to Claude Code - #102
Merged
Merged
Conversation
Claude Code only knows Anthropic model ids, so a third-party id opens on its built-in 200k default. The CLI resolves the model's real window from /v1/models but never hands it over, so minimax/minimax-m3.1-flash (1M) reports 200k in /context while the website says 1M. The test asserts the launch env declares CLAUDE_CODE_MAX_CONTEXT_TOKENS for a concrete model, leaves it unset for an unknown window and for a virtual preset, and still declares a window below 200k. Co-authored-by: Duyet Le <me@duyet.net> Co-authored-by: duyetbot <bot@duyet.net> Co-Authored-By: Claude Code <noreply@anthropic.com>
Claude Code 2.1.304 keys its model metadata on Anthropic model ids. A third-party id is an unknown model, so it opens on the built-in 200,000-token default and minimax/minimax-m3.1-flash reported 200k in /context while the catalog and the website say 1,000,000. The CLI already resolved the window from /v1/models and carried it on BuildToolEnvInput.context_window, but never handed it over. It set CLAUDE_CODE_AUTO_COMPACT_WINDOW, which is the auto-compact threshold, not the window. The launch env now declares CLAUDE_CODE_MAX_CONTEXT_TOKENS from the resolved window. An unknown window stays unset, and a virtual preset keeps its own window because its hop is picked per request and anyrouter/auto[1m] already carries the suffix Claude Code reads. Co-authored-by: Duyet Le <me@duyet.net> Co-authored-by: duyetbot <bot@duyet.net> Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
anyr claudenow tells Claude Code the model's real context window throughCLAUDE_CODE_MAX_CONTEXT_TOKENS.Why
Claude Code 2.1.304 keys its model metadata on Anthropic model ids. A third-party id is an unknown model, so it opens on the built-in 200,000-token default.
minimax/minimax-m3.1-flashreported200kin/contextwhile the catalog and the website say 1,000,000.The CLI already resolved the number from
/v1/modelsand carried it onBuildToolEnvInput.context_window, but never handed it over. It setCLAUDE_CODE_AUTO_COMPACT_WINDOW, which is the auto-compact threshold, not the window.How
One insert in
build_tool_envinsrc/spawn.rs, inside theclaudebranch.Guardrails.
anyrouter/auto[1m]already carries the suffix Claude Code reads.CLAUDE_CODE_AUTO_COMPACT_WINDOWis untouched. It is the threshold, not the window.Verification
Against the same base URL and the same model.
Before the fix the same session reported
26.3k / 200k (13%).Tests
The first commit adds the failing test, the second the fix.
1000000.128000.cargo testpasses, 416 tests across the crate.cargo fmt --checkis clean.Fixes #100
🤖 Generated with Claude Code