fix(shared): respect cached model context limits for Anthropic providers post-GA#2664
Merged
code-yeongyu merged 2 commits intocode-yeongyu:devfrom Mar 25, 2026
Conversation
…ers post-GA After Anthropic's 1M context GA (2026-03-13), the beta header is no longer sent. The existing detection relied solely on the beta header to set anthropicContext1MEnabled, causing all Anthropic models to fall back to the 200K default despite models.dev reporting 1M. Update resolveActualContextLimit to check per-model cached limits from provider config (populated from models.dev data) when the explicit 1M flag is not set. Priority order: 1. Explicit 1M mode (beta header or env var) - all Anthropic models 2. Per-model cached limit from provider config 3. Default 200K fallback This preserves the code-yeongyu#2460 fix (explicit 1M flag always wins over cached values) while allowing GA models to use their correct limits. Fixes premature context warnings at 140K and unnecessary compaction at 156K for opus-4-6 and sonnet-4-6 users without env var workaround.
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Correctly updates Anthropic context limit resolution to respect cached model data post-GA, with explicit flag priority and comprehensive tests. No regressions identified.
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Auto-approved: The change surgically enables cached context limits for specific Anthropic GA models while preserving existing behavior and priority for all other models, including the 1M explicit flag.
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.
Summary
After Anthropic's 1M context GA (2026-03-13), the
anthropic-beta: context-1mheader is no longer required. However,context-limit-resolver.tsstill relies on this header to detect 1M support viaanthropicContext1MEnabled. Without the header, all Anthropic models fall back to the 200K default — even thoughmodels.dev(and OpenCode's cached model data) correctly reports 1M forclaude-opus-4-6andclaude-sonnet-4-6.This causes:
Changes
Update
resolveActualContextLimit()to check per-model cached limits from provider config when the explicit 1M flag is not set.Priority order:
ANTHROPIC_1M_CONTEXTenv var) → 1M for all Anthropic modelsThis preserves the #2460 fix (explicit 1M flag always takes priority over cached values, preventing the old regression where cached 200K overrode the 1M flag) while allowing post-GA models to use their correct limits from the cache.
Test Changes
context-limit-resolver.test.ts: 3 new test cases (GA cache hit, no cache fallback, explicit flag priority)context-window-monitor.model-context-limits.test.ts: Updated to verify cached limits are respected for Anthropic providers, with both below-threshold and above-threshold scenariosVerification
bun run typecheck✅bun run build✅bun teston all related files: 30/30 pass ✅Related Issues
Summary by cubic
Fixes Anthropic context limit detection post-1M GA by using cached limits only for GA 4.6 models when the explicit 1M flag is off. Older Anthropic models stay at 200K, while opus-4-6 and sonnet-4-6 get their correct 1M windows, preventing early warnings and compaction.
Written for commit bf804b0. Summary will update on new commits.