fix: make Claude 200k context window selection take effect - #8409
Conversation
Claude Code auto-enables the 1M-token context window for models that support it (claude-opus-5, claude-fable-5, claude-sonnet-5), so passing a bare model slug does not mean 200k — the session silently runs at 1M regardless of the selection. Opt out explicitly by setting CLAUDE_CODE_DISABLE_1M_CONTEXT=1 whenever the resolved context window is 200k. The opt-out goes through the SDK settings option (the flag-settings layer) instead of the spawned process env, because an `env` block in a user or project settings file overrides the process env and would silently defeat the fix. Because the flag-settings opt-out also outranks an explicit `[1m]` model suffix (verified empirically), a mid-thread model switch must restate it for the new selection — otherwise a session started at 200k would silently clamp a later 1M selection, and vice versa. sendTurn now calls applyFlagSettings alongside setModel. ClaudeTextGeneration spawns the same CLI with the same bare slug, so it gets the same opt-out. Fixes pingdotgg#8405 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This change makes the existing Claude 200k selection alter the effective context capacity across live sessions and CLI-based text generation, including model switches. The implementation is focused and tested, but the production runtime impact of this propagated SDK/CLI configuration merits human review. You can add or adjust custom eligibility rules. Learn more. |
What Changed
Selecting the 200k context window for Claude models now actually runs the session at 200k. The adapter injects
env: { CLAUDE_CODE_DISABLE_1M_CONTEXT: "1" }into the SDK's flag-settings layer whenever the resolved context window is200k, restates or clears it on mid-thread model switches viaapplyFlagSettings, and applies the same opt-out inClaudeTextGeneration(commit-message / PR-content / thread-title generation, which spawns the same CLI).Why
Fixes #8405. Claude Code auto-enables the 1M window for
claude-opus-5/claude-fable-5/claude-sonnet-5unless the process opts out, soresolveClaudeApiModelId's bare slug does not mean 200k — the 200k selection was a silent no-op and every such session ran at 1M (verified empirically viamodelUsage[].contextWindow; details in the issue).Three design points, each verified against SDK 0.3.170 + CLI 2.1.247:
settingSources: ["user", "project", "local"], and anenvblock in a user/project settings file overrides the spawned process env — aqueryOptions.env-based fix is silently defeated by e.g."env": {"CLAUDE_CODE_DISABLE_1M_CONTEXT": "0"}in~/.claude/settings.json. Flag settings (the SDKsettingsoption) outrank those files.[1m]model suffix, so without restating it onsetModel, a session started at 200k (any default Sonnet session) would silently clamp a later 1M selection to 200k.sendTurnnow callsapplyFlagSettingsalongsidesetModel, passingnullto clear when the new selection isn't 200k.ClaudeTextGenerationspawns the same CLI with the same bare slug and already builds a--settingsobject, so it gets the same conditional spread.This also makes the context meter agree with reality (#5286):
selectedClaudeContextWindowseeds 200k and the CLI now confirms it instead of reporting 1M.Testing: 7 new / 2 updated unit tests across
ClaudeAdapter.test.tsandClaudeTextGeneration.test.ts; fullsrc/provider+src/textGenerationsuites pass (691 passed, 8 skipped); typecheck clean. Behavior verified end-to-end through the real SDK: bare slug → 1,000,000; with the flag-settings opt-out → 200,000 (including winning against a conflicting user-settingsenvblock); mid-sessionapplyFlagSettingsflip verified in both directions.Checklist
I included before/after screenshots for any UI changes(no UI changes)I included a video for animation/interaction changes(no animation changes)🤖 Generated with Claude Code
Note
Medium Risk
Changes how Claude sessions are configured (context window and live model switches); wrong flag logic would silently run at 1M or clamp 1M selections, but behavior is narrowly scoped and well-tested.
Overview
Fixes 200k context window selections being ignored: Claude Code auto-enables 1M for supported models, so the adapter now sets
CLAUDE_CODE_DISABLE_1M_CONTEXTthrough the SDKsettings/ flag-settings layer (not process env) whenresolveClaudeContextWindowis200k, including default-200k models like Sonnet 5.On mid-thread model changes,
sendTurncallsapplyFlagSettingsbeforesetModel—setting the opt-out for 200k orenv: nullto clear it—so the flag stays in sync with the model id and can override an explicit[1m]suffix.The same conditional is applied in
ClaudeTextGenerationfor CLI-spawned flows (commit messages, etc.). Tests cover start-session settings, merges with fast mode, and flag updates when switching between 1M and 200k.Reviewed by Cursor Bugbot for commit 87eba2d. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix Claude 200k context window by setting
CLAUDE_CODE_DISABLE_1M_CONTEXTflagWhen a user selects the 200k context window, the SDK and CLI now set
env: { CLAUDE_CODE_DISABLE_1M_CONTEXT: "1" }so the 1M context is actually disabled.makeClaudeAdapterinjects the flag intocreateQuerysettings and callsquery.applyFlagSettingson model switches insendTurn, clearing it (env: null) when the new model is not 200k.makeClaudeTextGenerationadds the same env flag to the CLI--settingspayload for 200k selections.ClaudeQueryRuntimeinterface now exposesapplyFlagSettingstyped from the SDK'sQuery.Macroscope summarized 87eba2d.