fix: size the 1M context window for the bracket alias form (opus[1m]) - #302
Merged
Conversation
`contextWindowForModel` matched only the `-1m` suffix, so the bracket form
Claude Code actually emits — `opus[1m]`, `claude-opus-5[1m]` — fell through to
the conservative 200k default. Asking EXPLICITLY for the 1M variant therefore
sized the window WORSE than the bare `opus` alias, which resolves to 1M.
Observed on a live session pinned to `opus[1m]`: codeoid computed a 200k window
against ~999k of real usage. Affected consumers:
- the percent-of-window figure on SessionInfo (session.ts) — reads ~500%
- the fork / provider-switch seed budget (seedBudgetChars via
targetContextWindow) — 5x too small, so history seeds over-truncate
Auto-rotate is NOT affected: decideRotation is passed the static
`Session.CONTEXT_WINDOW` (1M), not this per-model resolution.
This also did NOT cause the "prompt is too long" overflow seen on that session
— that has a separate cause (compaction firing reactively after the API error
rather than proactively). This is an independent defect surfaced while
investigating it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
saucam
force-pushed
the
fix/one-million-window-bracket-alias
branch
from
August 25, 2026 04:36
a03f15e to
d1285f6
Compare
jalbrethsen-highflame
approved these changes
Aug 25, 2026
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.
The bug
contextWindowForModelmatched only the-1msuffix, so the bracket form Claude Code actually emits —opus[1m],claude-opus-5[1m]— fell through to the conservative 200k default.The result inverts caller intent: asking explicitly for the 1M variant sized the window worse than the bare alias.
opus[1m]sonnet[1m]claude-opus-5[1m]opushaikuHow it surfaced
Found while investigating a real
prompt is too long: 1000076 tokens > 1000000 maximumon a live session pinned toopus[1m], where codeoid computed a 200k window against ~999k of actual usage.Blast radius (traced, not assumed)
Affected — the two production consumers of this function:
SessionInfo(session.ts:2826) — reads ~500% occupancyseedBudgetCharsviatargetContextWindow) — 5× too small, so history seeds over-truncateNot affected:
decideRotationis passed the staticSession.CONTEXT_WINDOW(hardcoded1_000_000), not this per-model resolution. An earlier revision of this description claimed otherwise; that was wrong.What this does not fix
It did not cause that overflow. The rotation path never consulted this value, and separately, under-sizing would make rotation fire earlier rather than later. The overflow has an independent cause — compaction firing reactively after the API error rather than proactively at a threshold — which is upstream SDK behavior and is being tracked separately.
Verification
lint+typecheckclean, 2370 pass / 0 fail. Four regression assertions on the bracket form including case-insensitivity, plus ahaikuguard so a bracket suffix can't manufacture a 1M window where no such variant exists.🤖 Generated with Claude Code