[BUG] CLAUDE_CODE_MAX_OUTPUT_TOKENS has no effect on Opus 4.6 — output stays capped at 32000
Resolved 💬 16 comments Opened Feb 8, 2026 by carrotRakko Closed Apr 19, 2026
💡 Likely answer: A maintainer (ashwin-ant, collaborator)
responded on this thread — see the highlighted reply below.
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_MAX_OUTPUT_TOKENS=64000 does not take effect on Opus 4.6. The documentation states:
CLAUDE_CODE_MAX_OUTPUT_TOKENS — Default: 32,000. Maximum: 64,000.
However, when setting CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000, the output is still capped at 32,000 tokens:
API Error: Claude's response exceeded the 32000 output token maximum.
To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.
The error message itself suggests using the very environment variable that was already set to 64,000.
After the error, the agent continued and completed its response in a follow-up turn.
What Should Happen?
Setting CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000 should raise the output limit to 64,000 tokens as documented.
Error Messages/Logs
API Error: Claude's response exceeded the 32000 output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.
Steps to Reproduce
- Set the environment variable:
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000 - Launch Claude Code with Opus 4.6:
claude --dangerously-skip-permissions - Give a prompt that generates a long output (e.g., "Write an exhaustive, chapter-by-chapter history of large language models from the 1940s to 2026, structured as 20 chapters")
- Observe the error: "exceeded the 32000 output token maximum"
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.37 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
iTerm2
Additional Information
- Tested with multiple values:
CLAUDE_CODE_MAX_OUTPUT_TOKENS=4000,16000,64000,128000— the 32000 limit remained in all cases - The session transcript shows
maxThinkingTokens: 31999regardless of the environment variable value - Related open issues reporting the same 32000 error on Opus 4.6 (without env var configuration): #23553, #24055
- Opus 4.6 API max output is 128K tokens per model documentation, but the CLI documentation caps at 64,000
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
16 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
These issues report the 32000 error itself. This issue specifically reports that
CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000does not change the limit — the environment variable is documented but has no effect on Opus 4.6. I've already commented on #24055 and #23553 linking back here.✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
Same problem here,
variable
CLAUDE_CODE_MAX_OUTPUT_TOKENSset, terminal restartedand still getting errors like:
Is it possible, that subagents do not respect that variable CLAUDE_CODE_MAX_OUTPUT_TOKENS ?
It's because it allows 64000 for opus-4-5 but there's no specific check for opus-4-6 so the check goes to the default of capped at 32000
Great info. Can we ground this information based on some official docs like here?:
https://code.claude.com/docs/en/settings
They explain the
CLAUDE_CODE_MAX_OUTPUT_TOKENS, but there is no info how it behaves in relation to various models and their versions...no but you can ground it based on the claude code binary
Good news: This appears to be fixed in v2.1.42! 🎉
The fix is not mentioned in the v2.1.42 changelog, but comparing the v2.1.41 and v2.1.42 npm packages confirms that the per-model output token upper limit logic was changed:
opus-4-6had no specific entry, falling through to theopus-4default with an upper limit of 32,000 — exactly as @bkuczabs-arch identifiedopus-4-6is now explicitly listed with{ default: 32000, upperLimit: 64000 }, matchingopus-4-5and other modelsCLAUDE_CODE_MAX_OUTPUT_TOKENS=64000should now take effect on Opus 4.6.---
✍️ Author: Claude Code with @carrotRakko
Now I'm getting:
API Error: Claude's response exceeded the 64000 output token maximum. To configure this
behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.
It looks like Opus4.6 in subscription is limited to 64k output tokens (default is 32k).
It can be increased above this value only if using API.
Don't forget, that total context windows tokens (200k) = input tokens + model thinking + output tokens.
I.e. if you increase output tokens, you are decreasing your space for (input tokens + thinking).
Just to understand, there is a trade-off
I will never understand why people feel the need to make stuff up and post it publicly as if it's fact especially on something like a GitHub issue. I guess giving the benefit of the doubt you're listening to an AI hallucination without actually checking yourself.
Claude code is hard coded to cap max output tokens at 64000. Has nothing to do with API vs sub. Log in with an API key all you want and it will be the same thing.
You are definitely right man, taking a lesson from this.
Just wanted mention, these information were not completely made up and was based on:
<img width="2428" height="1990" alt="Image" src="https://github.com/user-attachments/assets/2deba4cc-843c-4fff-b884-ae2cfd61fc72" />
So actually, there some sort o chaos in Anthropic docs,
if it is really limited to 64k for an API, as Anthropic "claims" 128k output tokens should be supported...
Yeah their docs are extremely bad for claude code. Those are the API docs though so different thing.
You have no idea how much undocumented stuff claude code has...
Adding production impact data from an agentic infrastructure built on Claude Code.
We orchestrate autonomous agents — infrastructure operations, investigations, multi-step workflows — with subagents handling delegated tasks extensively. Väinämöinen, named after the Kalevala sage, because even mythological bards end up debugging token limits.
Real-world impact of the 32K default + 64K CLI cap:
A Sonnet subagent running a complex design task ran for 55 minutes with 34 tool calls, then hit
API Error: Claude's response exceeded the 32000 output token maximum. The entire session's deliverable was lost — no file written, no partial output recoverable. Nearly an hour of compute and reasoning, gone.We acknowledge the v2.1.42 fix for Opus 4.6 — thank you. Setting
CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000now works correctly across models for us on v2.1.72.The remaining gap: 64K CLI cap vs 128K API capability.
Opus 4.6 supports 128K output at the API level, but the CLI enforces a 64K ceiling. For agentic workloads with complex reasoning chains, extended thinking can consume a large share of the output budget, leaving limited room for actual response content. Raising the CLI cap to match the API's 128K for Opus 4.6 would eliminate this bottleneck.
Related pain point (locked issues #25569, #10738):
Subagents spawned via the Task tool are hardcoded at 32,000 regardless of the env var. When the main agent delegates complex work to subagents — as any serious agentic workflow must — those subagents hit the wall on longer reasoning tasks. The closed-as-not-planned status on #25569 is difficult to reconcile with agentic orchestration being a primary use case for Claude Code.
The old sage has learned: when the kantele's strings are too short, even the sweetest melody gets cut off mid-verse. We would appreciate the CLI cap being raised to match Opus 4.6's API capability, and subagents inheriting the configured limit.
This was fixed in v2.1.42 — CLAUDE_CODE_MAX_OUTPUT_TOKENS is now respected up to 64K for Opus 4.6 instead of being clamped to 32000. If you're still seeing this in the latest version, please comment with your version and repro and we'll reopen.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.