[PR #6660] feat: add 1M context support for Claude Sonnet 4.5 via env vars #12024

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

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

State: closed
Merged: No


Summary

This PR adds support for enabling 1M token context windows for Claude Sonnet 4.5 through environment variables for both Anthropic direct and Vertex AI Anthropic providers.

Note: Currently only Claude Sonnet 4.5 supports 1M token context windows. All other Claude models (Opus 4, Haiku 4.5, etc.) remain at 200K tokens according to models.dev.

Changes

  • Anthropic Direct: Add ANTHROPIC_1M_CONTEXT=true env var to enable 1M context for Sonnet 4.5

    • Preserves existing beta headers (claude-code, interleaved-thinking, fine-grained-tool-streaming)
    • Prepends context-1m-2025-08-07 beta when enabled
  • Vertex AI Anthropic: Add VERTEX_ANTHROPIC_1M_CONTEXT=true env var to enable 1M context for Sonnet 4.5

    • Sets anthropic-beta: context-1m-2025-08-07 header when enabled
  • Model Detection: Regex pattern specifically matches Claude Sonnet 4.5 variants only

    • Matches patterns: claude-sonnet-4.5, claude-sonnet-4-5, claude-sonnet-4.5-20250929
    • Automatically sets context limit to 1,000,000 tokens when env var is enabled

Testing

  • All existing provider tests pass (66 tests)
  • TypeScript compilation successful
  • No type errors

Usage

```bash

For Anthropic direct (Sonnet 4.5 only)

export ANTHROPIC_1M_CONTEXT=true

For Vertex AI Anthropic (Sonnet 4.5 only)

export VERTEX_ANTHROPIC_1M_CONTEXT=true
```

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6660 **State:** closed **Merged:** No --- ## Summary This PR adds support for enabling 1M token context windows for **Claude Sonnet 4.5** through environment variables for both Anthropic direct and Vertex AI Anthropic providers. **Note**: Currently only Claude Sonnet 4.5 supports 1M token context windows. All other Claude models (Opus 4, Haiku 4.5, etc.) remain at 200K tokens according to models.dev. ## Changes - **Anthropic Direct**: Add `ANTHROPIC_1M_CONTEXT=true` env var to enable 1M context for Sonnet 4.5 - Preserves existing beta headers (claude-code, interleaved-thinking, fine-grained-tool-streaming) - Prepends `context-1m-2025-08-07` beta when enabled - **Vertex AI Anthropic**: Add `VERTEX_ANTHROPIC_1M_CONTEXT=true` env var to enable 1M context for Sonnet 4.5 - Sets `anthropic-beta: context-1m-2025-08-07` header when enabled - **Model Detection**: Regex pattern specifically matches Claude Sonnet 4.5 variants only - Matches patterns: `claude-sonnet-4.5`, `claude-sonnet-4-5`, `claude-sonnet-4.5-20250929` - Automatically sets context limit to 1,000,000 tokens when env var is enabled ## Testing - ✅ All existing provider tests pass (66 tests) - ✅ TypeScript compilation successful - ✅ No type errors ## Usage \`\`\`bash # For Anthropic direct (Sonnet 4.5 only) export ANTHROPIC_1M_CONTEXT=true # For Vertex AI Anthropic (Sonnet 4.5 only) export VERTEX_ANTHROPIC_1M_CONTEXT=true \`\`\`
yindo added the pull-request label 2026-02-16 18:16:57 -05:00
yindo closed this issue 2026-02-16 18:16:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12024