OUTPUT_TOKEN_MAX hardcoded to 32k prevents using full 64k output limit for Claude Sonnet 4.5 with extended thinking #1937

Closed
opened 2026-02-16 17:33:19 -05:00 by yindo · 2 comments
Owner

Originally created by @calvinalkan on GitHub (Oct 3, 2025).

Originally assigned to: @rekram1-node on GitHub.

Problem

Claude Sonnet 4.5 supports 64k output tokens, but OpenCode has a hardcoded limit
that prevents using the full capacity when extended thinking is enabled.

Current Behavior

In src/session/prompt.ts:

export const OUTPUT_TOKEN_MAX = 32_000

const outputLimit = Math.min(model.info.limit.output, OUTPUT_TOKEN_MAX) ||
OUTPUT_TOKEN_MAX

This caps outputLimit at 32k even when the model config specifies 64k:

"claude-sonnet-4-20250514": {
  "limit": {
    "output": 64000,
    "context": 200000
  }
}

When using extended thinking with a 32k budget:

thinking:
  type: enabled
  budgetTokens: 32000

The calculation becomes: 32000 - 32000 = 0, causing:

AI_InvalidArgumentError: maxOutputTokens must be >= 1

Expected Behavior

OUTPUT_TOKEN_MAX should be at least 64k to support Claude Sonnet 4.5's full output
capacity with extended thinking enabled.

Workaround

Reduce thinking budgets to fit within 32k total (e.g., budgetTokens: 20000 leaves
12k for output).

Originally created by @calvinalkan on GitHub (Oct 3, 2025). Originally assigned to: @rekram1-node on GitHub. ## Problem Claude Sonnet 4.5 supports 64k output tokens, but OpenCode has a hardcoded limit that prevents using the full capacity when extended thinking is enabled. ## Current Behavior In `src/session/prompt.ts`: ```typescript export const OUTPUT_TOKEN_MAX = 32_000 const outputLimit = Math.min(model.info.limit.output, OUTPUT_TOKEN_MAX) || OUTPUT_TOKEN_MAX ``` This caps outputLimit at 32k even when the model config specifies 64k: ```json "claude-sonnet-4-20250514": { "limit": { "output": 64000, "context": 200000 } } ```` When using extended thinking with a 32k budget: ```yaml thinking: type: enabled budgetTokens: 32000 ``` The calculation becomes: 32000 - 32000 = 0, causing: AI_InvalidArgumentError: maxOutputTokens must be >= 1 ## Expected Behavior OUTPUT_TOKEN_MAX should be at least 64k to support [Claude Sonnet 4.5's full output](https://docs.claude.com/en/docs/about-claude/models/overview) capacity with extended thinking enabled. ## Workaround Reduce thinking budgets to fit within 32k total (e.g., budgetTokens: 20000 leaves 12k for output).
yindo closed this issue 2026-02-16 17:33:19 -05:00
Author
Owner

@rekram1-node commented on GitHub (Oct 3, 2025):

hm we will need to adjust out logic for the budget tokens calculation...

@rekram1-node commented on GitHub (Oct 3, 2025): hm we will need to adjust out logic for the budget tokens calculation...
Author
Owner

@rekram1-node commented on GitHub (Oct 5, 2025):

should be fixed in next release

@rekram1-node commented on GitHub (Oct 5, 2025): should be fixed in next release
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1937