feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5 #12451
+98
−4
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
Extends the Anthropic 1M context window beta to Claude Opus 4.6 and Claude Sonnet 4.5 models. Previously only Sonnet 4 variants could leverage the extended context — this unlocks it for the newest high-capability models across both direct API and Bedrock paths.
Problem & Solution
Problem: The
context-1m-2025-08-07beta header was only sent for models matchingclaude-sonnet-*, so Opus 4.6 and Sonnet 4.5 users hit the default context limit despite the models supporting 1M tokens.Solution: Replace the inline prefix check with a dedicated
supports1MContext()predicate that matches all eligible model families, applied consistently to both API paths.Key Changes
supports1MContext()— a single source of truth for which models get the 1M context betaSystem Design
Beta Header Injection Flow
sequenceDiagram participant Client participant Handler as handler.ts participant Select as selectProvider() participant Helper as anthropicHelper participant API as Anthropic API / Bedrock Client->>Handler: POST /zen (model: claude-opus-4-6) Handler->>Select: selectProvider(model) Select-->>Handler: providerInfo (anthropicHelper) rect rgb(40, 40, 40) note right of Handler: Request modification Handler->>Helper: modifyHeaders(headers, body, apiKey) Helper->>Helper: supports1MContext(body.model)? alt Model supported Helper-->>Handler: set anthropic-beta: context-1m-2025-08-07 else Model not supported Helper-->>Handler: no beta header end Handler->>Helper: modifyBody(body) note right of Helper: Bedrock: injects anthropic_beta field end Handler->>API: fetch(url, { headers, body }) API-->>Client: Response (up to 1M context)The change affects the decision point inside
modifyHeadersandmodifyBody— replacing a hardcodedclaude-sonnet-prefix check withsupports1MContext()that covers three model prefixes.Testing Strategy
The
supports1MContext()helper is tested against all model families: positive cases for Opus 4.6, Sonnet 4.5, and Sonnet 4 (canonical and date-suffixed), negative cases for Opus 4.5, Opus 4.1, Haiku, unknown models, and empty strings.Reviewer Notes
"claude-sonnet-4"(without trailing hyphen) matches both the canonicalclaude-sonnet-4model ID and date-suffixed variants likeclaude-sonnet-4-20250514— while"claude-sonnet-4-5"is listed separately to explicitly cover Sonnet 4.5isSonnet(a looseincludes("sonnet")check) — now uses the samesupports1MContext()for consistencyFixes #12452
Fixes #12438
Fixes #12338
Fixes #11267