Skip to content

Conversation

@ColbySerpa
Copy link

@ColbySerpa ColbySerpa commented Oct 9, 2025

feat: Add Claude Sonnet 4.5 1M context window support for Claude Code provider

Related GitHub Issue

Closes: #8585

Roo Code Task Context (Optional)

Description

Adds support for Claude Sonnet 4.5 with 1M token context window to the Claude Code provider.

Changes made in packages/types/src/providers/claude-code.ts:

  • Added new model ID: claude-sonnet-4-5-20250929[1m]
  • Set contextWindow: 1_000_000 (overrides default 200K from base anthropic model)
  • All other properties inherited from base claude-sonnet-4-5 model

Implementation Details:
This follows the same pattern used by Bedrock and Anthropic API providers for 1M context support:

  1. The model definition spreads properties from the base anthropic model (which has contextWindow: 200_000)
  2. Our explicit contextWindow: 1_000_000 overrides the inherited value
  3. The ClaudeCodeHandler's getModel() method returns the full ModelInfo object with the overridden contextWindow
  4. The sliding window truncation logic in src/core/sliding-window/index.ts uses this contextWindow value to determine when to truncate messages

When users select this model via /model sonnet[1m] in Claude Code:

  • The system retrieves the model definition with contextWindow: 1_000_000
  • Messages won't be auto-truncated until they exceed 1M tokens (instead of 200K)
  • The truncation calculation respects the full 1M token context window

Test Procedure

Manual Verification:

  1. Select the model using /model sonnet[1m] in Claude Code
  2. Verify the model is loaded with correct contextWindow in developer tools
  3. Create a conversation with context approaching 1M tokens
  4. Confirm truncation doesn't occur until exceeding 1M tokens (previously would truncate at ~200K)

Code Review:

  • Verified model definition follows TypeScript type constraints (satisfies Record<string, ModelInfo>)
  • Confirmed contextWindow override pattern matches existing 1M implementations in:
    • webview-ui/src/components/ui/hooks/useSelectedModel.ts (lines 203-211 for Bedrock)
    • webview-ui/src/components/ui/hooks/useSelectedModel.ts (lines 367-397 for Anthropic)
  • Confirmed the spread operator pattern correctly overrides the contextWindow property

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - This is a backend model configuration change with no UI modifications.

Documentation Updates

  • Yes, documentation updates may be helpful to inform users about the new 1M context model availability via the [1m] suffix in Claude Code.

Additional Notes

This implementation adds the model definition but relies on the existing infrastructure:

  • The ClaudeCodeHandler.getModel() method already properly returns model info with all properties
  • The sliding window truncation logic already uses the contextWindow property from model info
  • No additional changes needed to support the 1M context - the existing code paths handle it automatically

Get in Touch

Discord:


Important

Adds claude-sonnet-4-5-20250929[1m] model with 1M token context window to Claude Code provider, overriding default 200K token limit.

  • Behavior:
    • Adds support for claude-sonnet-4-5-20250929[1m] model with 1M token context window in claude-code.ts.
    • Overrides default contextWindow of 200K tokens to 1M tokens.
    • Truncation logic in src/core/sliding-window/index.ts respects the 1M token limit.
  • Implementation:
    • Model inherits properties from claude-sonnet-4-5 and overrides contextWindow.
    • getModel() method in ClaudeCodeHandler returns model info with updated context window.
  • Testing:
    • Manual verification includes loading model and checking truncation at 1M tokens.
    • Code review confirms TypeScript type constraints and contextWindow override pattern.

This description was created by Ellipsis for e014043. You can customize this summary. It will automatically update as commits are pushed.

@ColbySerpa ColbySerpa requested review from cte, jr and mrubens as code owners October 9, 2025 22:17
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. enhancement New feature or request labels Oct 9, 2025
Copy link

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

I found some issues that need attention before this can be merged.

supportsReasoningBudget: false,
requiredReasoningBudget: false,
},
"claude-sonnet-4-5-20250929[1m]": {
Copy link

Choose a reason for hiding this comment

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

Critical: Model ID naming inconsistency. The model ID "claude-sonnet-4-5-20250929[1m]" includes a date (20250929) that doesn't exist in the base anthropic models. The base model being spread is "claude-sonnet-4-5" (no date), not "claude-sonnet-4-5-20250929".

This creates confusion because:

  1. The date in the model ID suggests it's based on a dated model variant
  2. But it's actually spreading from the undated "claude-sonnet-4-5" base model
  3. This inconsistency could lead to maintenance issues

Consider either:

  • Using "claude-sonnet-4-5[1m]" to match the base model name, OR
  • Documenting why the date is included if it has semantic meaning for Claude Code

},
"claude-sonnet-4-5-20250929[1m]": {
...anthropicModels["claude-sonnet-4-5"],
contextWindow: 1_000_000, // 1M token context window (requires [1m] suffix)
Copy link

Choose a reason for hiding this comment

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

Major: Missing pricing information for 1M context. The base claude-sonnet-4-5 model in anthropic.ts has tiered pricing for 1M context (lines 21-29 in anthropic.ts):

  • Input: $6 per million tokens (vs $3 for ≤200K)
  • Output: $22.50 per million tokens (vs $15 for ≤200K)
  • Cache writes: $7.50 per million tokens (vs $3.75 for ≤200K)
  • Cache reads: $0.60 per million tokens (vs $0.30 for ≤200K)

The current implementation inherits the base pricing ($3/$15) which is incorrect for 1M context usage. You should either:

  1. Override the pricing fields to match the 1M tier pricing, OR
  2. Document that Claude Code uses different pricing than the Anthropic API

requiredReasoningBudget: false,
},
"claude-sonnet-4-5-20250929[1m]": {
...anthropicModels["claude-sonnet-4-5"],
Copy link

Choose a reason for hiding this comment

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

Minor: Consider adding a test case for the new 1M context model in __tests__/claude-code.spec.ts to verify:

  1. The model ID is valid and can be retrieved
  2. The contextWindow is correctly set to 1_000_000
  3. The model properly inherits other properties from the base model

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 9, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 9, 2025
@mrubens mrubens merged commit bdc91b2 into RooCodeInc:main Oct 9, 2025
23 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 9, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.