[BUG] API Error: max_tokens: 250001 > 128000 and thinking.budget_tokens error on Opus 4.6 and Opus 4.5 (Linux)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude Code sends max_tokens: 250001 to the API when using Opus 4.6, which exceeds the model's 128K limit. After switching to Opus 4.5, a second error appears: thinking.budget_tokens should not exceed maximum possible tokens in the context window. Both errors occur on the very first prompt of a fresh session (e.g., just typing "hello").
What Should Happen?
Claude Code should correctly set max_tokens and thinking.budget_tokens values within the limits supported by each model:
- Opus 4.6: max_tokens should not exceed 128,000
- Opus 4.5: max_tokens should not exceed 64,000
- thinking.budget_tokens should not exceed the available context window
A simple prompt like "hello" should receive a normal response without any API errors, regardless of the selected model.
Error Messages/Logs
Opus 4.6 error (first attempt):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 250001 > 128000, which is the maximum allowed number of output tokens for claude-opus-4-6"},"request_id":"req_011CXxgdU34AM39HkJEvgy2P"}
Opus 4.6 error (second attempt, different error on same session):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"`thinking.budget_tokens` should not exceed maximum possible tokens in the context window."},"request_id":"req_011CXxggSrT5gxc67p6SvpUD"}
Opus 4.5 error (after switching model via /model):
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"`thinking.budget_tokens` should not exceed maximum possible tokens in the context window."},"request_id":"req_011CXxgrRGjFKPEyYPhZs7KP"}
All three errors occur on the very first prompt of a session (typing just "hello" or any simple text). No workaround (environment variables, settings.json, full reinstall) resolves the issue.
Steps to Reproduce
- Install Claude Code via native installer:
curl -fsSL https://claude.ai/install.sh | bash - Start Claude Code (defaults to Opus 4.6)
- Type any simple prompt (e.g., "hello")
- Observe error:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 250001 > 128000, which is the maximum allowed number of output tokens for claude-opus-4-6"}} - Switch to Opus 4.5 via
/model claude-opus-4-5-20251101 - Type the same prompt
- Observe error:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"thinking.budget_tokens should not exceed maximum possible tokens in the context window."}}
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.2
Claude Code Version
2.1.37
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Additional Information
Configuration
~/.claude/settings.json at time of error:
{
"statusLine": {
"type": "command",
"command": "chroot=\"\"; [ -n \"${debian_chroot}\" ] && chroot=\"($debian_chroot)\"; printf '%s\\033[01;32m%s@%s\\033[00m:\\033[01;34m%s\\033[00m' \"$chroot\" \"$(whoami)\" \"$(hostname -s)\" \"$(pwd)\""
},
"enabledPlugins": {
"frontend-design@claude-plugins-official": true
}
}
No custom maxTokens, max_tokens, or thinking settings were configured. Default settings only.
System Info
- OS: Linux Mint (Ubuntu-based)
- Architecture: x86_64
- Claude Code: v2.1.37 (native binary, ELF 64-bit)
- Installation:
curl -fsSL https://claude.ai/install.sh | bash - Subscription: Max plan (x20)
Key Observations
- The value
250001is not present in any user configuration file. It appears to be hardcoded or dynamically calculated within the Claude Code binary. - The binary is a compiled ELF executable (
~/.local/share/claude/versions/2.1.37), so the problematic value cannot be edited by users. - The
thinking.budget_tokenserror persists even after switching from Opus 4.6 to Opus 4.5, suggesting corrupted session state or incorrect budget calculation for both models. - Full uninstall (removing
~/.local/bin/claude,~/.local/share/claude,~/.claude,~/.claude.json) and fresh reinstall did not fix the issue. CLAUDE_CODE_MAX_OUTPUT_TOKENS=128000environment variable had no effect, consistent with #24159.
Workarounds Attempted (all failed)
| Workaround | Result |
|---|---|
| CLAUDE_CODE_MAX_OUTPUT_TOKENS=128000 | No effect |
| maxTokens: 128000 in settings.json | No effect |
| Full uninstall + reinstall | Same errors |
| claude update | Already on latest |
| Clearing ~/.claude/sessions and ~/.claude/projects | Same errors |
| Switching to Opus 4.5 via /model | Different error (thinking.budget_tokens) |
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗