Claude Code · Requests and models
API Error: Claude’s response exceeded the 32000 output token maximum
Claude Code’s “response exceeded the 32000 output token maximum” means one reply hit its output cap. Continue, split the work or raise the limit.
Message
The exact error
API Error: Claude's response exceeded the 32000 output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.Also appears as:
- On a request re-sent without streaming
- API Error: Claude's response exceeded the 64000 output token maximum for a request sent without streaming. The CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable cannot raise this limit.
Meaning
What does “exceeded the output token maximum” mean?
Every request sets a cap on how many tokens Claude may write in one reply, its max output tokens. This error means the reply reached that cap and was cut off there. The number in the message is the cap that applied: it varies by model, and for a model ID Claude Code doesn’t recognise the default is 32,000. It’s about one reply, not the conversation: the context window can still have plenty of room. The second form means a streaming request failed and was re-sent without streaming, which caps the reply at 64,000 tokens whatever you set.
Causes
Why did Claude’s reply get so long?
- Asking for a very large output in one go, such as a whole long file, a full rewrite or a big generated dataset
- A single tool call carrying a huge file write, which counts as output
- Long extended thinking before the answer, which shares the same output budget
- A custom or gateway model ID that Claude Code can’t match to a known model, so it uses the 32,000 default
Fix
How do I fix the output token maximum error?
Reply “continue”
If Claude wrote some text before the cut-off, send
continuein an interactive session to get the rest. The text it already wrote stays in the conversation.Ask for smaller pieces
Ask for one file, one section or one step per reply, or for targeted edits rather than rewriting a whole file. This is the most reliable fix, because no cap can be raised past the model’s own maximum.
Raise CLAUDE_CODE_MAX_OUTPUT_TOKENS
When the message says to set it, raise the cap. Claude Code lowers a value above the model’s cap to the cap (128,000 for an unrecognised model ID). A higher value leaves less of the context window before auto-compact triggers, so don’t raise it more than you need.
macOS / Linux export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000 claudeWindows PowerShell $env:CLAUDE_CODE_MAX_OUTPUT_TOKENS = "64000" claude~/.claude/settings.json { "env": { "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "64000" } }For the “sent without streaming” form, fix the stream
That 64,000 cap can’t be raised. It appears when streaming failed first, often because of a proxy or gateway, so look at Unable to connect to API and ask for smaller outputs meanwhile.
Explained
Is this the same as “Prompt is too long”?
No. Prompt is too long is about input: the whole conversation no longer fits the context window. The output token maximum is about one reply being longer than the per-reply cap. You can hit it in a brand-new session with a short prompt that asks for a lot of text.
The token counter gives a feel for how many tokens a file of a given size is, so you can see when “write the whole thing” will run past a 32,000-token cap. The guide to Claude Code token usage explains why smaller, focused requests also cost less.
FAQ
Questions people ask
What is the maximum value for CLAUDE_CODE_MAX_OUTPUT_TOKENS?
It depends on the model: each has its own output cap, listed in Anthropic’s models overview, and Claude Code lowers anything above it to the cap. For a model ID Claude Code doesn’t recognise, the default is 32,000 and the cap is 128,000. A request re-sent without streaming is limited to 64,000 regardless.
Where do I set CLAUDE_CODE_MAX_OUTPUT_TOKENS?
Set it in your shell before starting claude, or permanently in the env block of ~/.claude/settings.json, then start a new session. Claude Code reads environment variables at startup, so changing it inside a running session has no effect until you restart.
Does raising the output token limit cost more?
Only if Claude actually writes more, since output is billed per token generated. The side effect is on context: a higher cap reserves more room for the reply, so auto-compact triggers earlier. Splitting work into smaller replies usually beats raising the cap.
Why does the error mention 32000 when my model supports more?
The number is the cap that applied to that request, not the model’s own limit. Many reports on GitHub from 2026 show 32,000 as the default, and current versions still use it for a model ID they can’t resolve, which is common with gateways. Set CLAUDE_CODE_MAX_OUTPUT_TOKENS to raise it, within the model’s real limit.
Related
Related errors
Keep exploring