[PR #12451] feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5 #14220

Closed
opened 2026-02-16 18:19:02 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12451

State: closed
Merged: No


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-07 beta header was only sent for models matching claude-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

  • Introduce supports1MContext() — a single source of truth for which models get the 1M context beta
  • Apply the beta flag consistently across direct Anthropic API and AWS Bedrock request paths
  • Cover Opus 4.6, Sonnet 4.5, and Sonnet 4 model families (with snapshot date suffixes)

System 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 modifyHeaders and modifyBody — replacing a hardcoded claude-sonnet- prefix check with supports1MContext() 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

  • The prefix "claude-sonnet-4" (without trailing hyphen) matches both the canonical claude-sonnet-4 model ID and date-suffixed variants like claude-sonnet-4-20250514 — while "claude-sonnet-4-5" is listed separately to explicitly cover Sonnet 4.5
  • Bedrock path previously used isSonnet (a loose includes("sonnet") check) — now uses the same supports1MContext() for consistency

Fixes #12452
Fixes #12438
Fixes #12338
Fixes #11267

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12451 **State:** closed **Merged:** No --- ## 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-07` beta header was only sent for models matching `claude-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 - Introduce `supports1MContext()` — a single source of truth for which models get the 1M context beta - Apply the beta flag consistently across direct Anthropic API and AWS Bedrock request paths - Cover Opus 4.6, Sonnet 4.5, and Sonnet 4 model families (with snapshot date suffixes) ## System Design ### Beta Header Injection Flow ```mermaid 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 `modifyHeaders` and `modifyBody` — replacing a hardcoded `claude-sonnet-` prefix check with `supports1MContext()` 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 - The prefix `"claude-sonnet-4"` (without trailing hyphen) matches both the canonical `claude-sonnet-4` model ID and date-suffixed variants like `claude-sonnet-4-20250514` — while `"claude-sonnet-4-5"` is listed separately to explicitly cover Sonnet 4.5 - Bedrock path previously used `isSonnet` (a loose `includes("sonnet")` check) — now uses the same `supports1MContext()` for consistency Fixes #12452 Fixes #12438 Fixes #12338 Fixes #11267
yindo added the pull-request label 2026-02-16 18:19:02 -05:00
yindo closed this issue 2026-02-16 18:19:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14220