Skip to content

Conversation

@stevenvo
Copy link

@stevenvo stevenvo commented Jan 2, 2026

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
```

- Add ANTHROPIC_1M_CONTEXT env var for Anthropic direct API
- Add VERTEX_ANTHROPIC_1M_CONTEXT env var for Vertex AI Anthropic
- Only applies to Claude Sonnet 4.5 models (not Opus 4 or Haiku)
- Sets context limit to 1,000,000 tokens when enabled
- Adds context-1m-2025-08-07 beta header when enabled
code-yeongyu pushed a commit to code-yeongyu/oh-my-opencode that referenced this pull request Jan 3, 2026
… vars (#450)

- Update preemptive-compaction hook to use 1M limit when env vars set
- Update dynamic-truncator to use 1M limit for output truncation
- Update context-window-monitor to use 1M limit for usage tracking

Previously hardcoded 200k limits caused compaction at 140k tokens even
with 1M context enabled. Now respects env vars consistently with base
opencode implementation.

Fixes compaction triggering too early with Claude Sonnet 4.5 1M context.

Related to anomalyco/opencode#6660
@stevenvo stevenvo closed this by deleting the head repository Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant