Skip to content

feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#1

Closed
ruslan-kurchenko wants to merge 1 commit intodevfrom
feat/opus-1m-context-window
Closed

feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#1
ruslan-kurchenko wants to merge 1 commit intodevfrom
feat/opus-1m-context-window

Conversation

@ruslan-kurchenko
Copy link
Owner

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)
Loading

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 (with and without snapshot suffixes), negative cases for Opus 4.5, Opus 4.1, Haiku, unknown models, and empty strings.

Reviewer Notes

  • The prefix list ["claude-opus-4-6", "claude-sonnet-4-5", "claude-sonnet-4-"] intentionally uses a trailing hyphen on claude-sonnet-4- to match Sonnet 4 snapshots (e.g., claude-sonnet-4-20250514) without matching Sonnet 4.5 twice — Sonnet 4.5 is caught by its own explicit prefix first
  • Bedrock path previously used isSonnet (a loose includes("sonnet") check) — now uses the same supports1MContext() for consistency

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@ruslan-kurchenko
Copy link
Owner Author

@codex review this

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc822bc94e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const CONTEXT_1M_BETA = "context-1m-2025-08-07"

export function supports1MContext(model: string): boolean {
const prefixes = ["claude-opus-4-6", "claude-sonnet-4-5", "claude-sonnet-4-"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Match canonical Sonnet 4 model for 1M context

The new prefix list excludes the documented claude-sonnet-4 model ID because it only matches claude-sonnet-4-... (with a trailing hyphen). When users request claude-sonnet-4, supports1MContext() returns false, so anthropic-beta: context-1m-2025-08-07 is no longer sent on either the direct Anthropic path or the Bedrock anthropic_beta path, which regresses that model back to the default context limit.

Useful? React with 👍 / 👎.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Extend the Anthropic context-1m beta header beyond Sonnet 4 to also
cover Claude Opus 4.6 and Claude Sonnet 4.5 models, for both direct
API and Bedrock paths.

- Extract supports1MContext() helper with prefix-based model matching
- Replace inline startsWith check and remove isSonnet variable
- Hoist beta version string into CONTEXT_1M_BETA constant
- Add 12 unit tests covering supported, unsupported, and edge cases
@ruslan-kurchenko ruslan-kurchenko force-pushed the feat/opus-1m-context-window branch from fc822bc to 2007403 Compare February 6, 2026 10:03
@ruslan-kurchenko
Copy link
Owner Author

Closing in favor of anomalyco#12342 which supersedes this PR.

This PR only patched the Zen console proxy layer, while anomalyco#12342 provides a complete solution including core runtime beta headers, adaptive thinking for Opus 4.6, compaction overflow fix, and AI SDK v5→v6 upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant