feat: add 1M token context window support for Claude 4+ via env vars#6654
Closed
stevenvo wants to merge 5 commits into
Closed
feat: add 1M token context window support for Claude 4+ via env vars#6654stevenvo wants to merge 5 commits into
stevenvo wants to merge 5 commits into
Conversation
…uilds This commit addresses two issues with the bin/opencode wrapper script: 1. **ES Module Compatibility**: Converts CommonJS require() syntax to ES module imports. The package.json specifies "type": "module", which causes Node.js to treat .js files as ES modules. While Bun (the project's primary runtime) allows require() in ES modules, Node.js strictly enforces ES module syntax, causing failures for developers using Node.js. 2. **Local Development Support**: Adds check for binaries in dist/ folder before looking in node_modules/. When developers build locally with 'bun run build' and use npm link for testing, the compiled binaries are placed in dist/, but the wrapper only searched node_modules/, causing it to fail. These changes improve the developer experience for contributors who: - Use Node.js instead of Bun for running the wrapper - Test local builds via npm link or similar methods The changes are backward compatible - production packages continue to work as the wrapper still checks node_modules/ as a fallback. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add ANTHROPIC_1M_CONTEXT env var for Anthropic direct - Add VERTEX_ANTHROPIC_1M_CONTEXT env var for Vertex AI Anthropic - Automatically enable 1M context for Claude 4+ models (opus/sonnet/haiku) - Preserve existing beta headers while adding context-1m-2025-08-07 beta - Improve model ID matching regex for Claude 4 variant detection
Only Claude Sonnet 4.5 currently supports 1M token context windows. Updated regex pattern from claude-(opus|sonnet|haiku)-4 to claude-sonnet-4[.-]5 to specifically match only Sonnet 4.5 variants.
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
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=trueenv var to enable 1M context for Sonnet 4.5context-1m-2025-08-07beta when enabledVertex AI Anthropic: Add
VERTEX_ANTHROPIC_1M_CONTEXT=trueenv var to enable 1M context for Sonnet 4.5anthropic-beta: context-1m-2025-08-07header when enabledModel Detection: Regex pattern specifically matches Claude Sonnet 4.5 variants
claude-sonnet-4.5,claude-sonnet-4-5,claude-sonnet-4.5-20250929Testing
Usage