Skip to content

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

Description

@calvinalkan

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).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions