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 message
API Error: Claude's response exceeded the 32000 output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.What it means
One reply (thinking included) ran into the output token ceiling for the request. By the time you see this, Claude Code has already tried to continue three times and hit the ceiling each time.
What to do
Ask for the work in smaller pieces. If a single answer really needs more room, raise CLAUDE_CODE_MAX_OUTPUT_TOKENS before starting Claude Code; it can't go past the model's cap.
Every request Claude Code sends to Anthropic's API carries a max_tokens value, a ceiling on how much the model may write in a single reply. When the reply hits it, the API stops the response and reports stop_reason as max_tokens. Claude Code turns that into this line:
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 number is whatever ceiling that request went out with, so you'll also see 64000 or 128000. It isn't a usage limit and your plan is fine. 311 issues in anthropics/claude-code mention "max_tokens" as of September 25, 2026, and 71 quote "output token maximum" itself.
What Claude Code tried before showing it
This was the part I didn't expect. In the 2.1.282 binary the error doesn't reach your screen straight away. Claude Code holds it back, adds a hidden message telling the model it hit the output limit and should pick up mid-thought and break the rest into smaller pieces, then sends the conversation again. It does that up to three times. You only see the line once all three continuations have also run into the ceiling.
That explains the complaint in older issues that the model "keeps running after this error is shown". In February 2026 (issue #23553, version 2.1.32) the error printed and the work carried on anyway. The automatic continue has been there since 2.1.0, according to the changelog. So if the line is on your screen in a current version, the task has been cut short several times in a row, and it's usually one enormous file write or a very long stretch of thinking that did it.
Thinking counts against the same ceiling
Extended thinking tokens are output tokens. Claude Code clamps the thinking budget to one token below max_tokens, and the env var reference says the same, so a long think leaves less room for the answer. The top issue on this error (#24055, 139 comments) opens with "After 8 minutes of thinking" on Opus 4.6.
What CLAUDE_CODE_MAX_OUTPUT_TOKENS does, and where it stops
The variable the message names is real, and it sets max_tokens for most requests. Set it in your shell before you launch, for example export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000. Two things about it surprised people in the issues.
Each model has a cap, and a bigger number is quietly lowered to it. In 2.1.282's model table, Opus 4.6 through Opus 5 and both Fable models default to 64,000 with a cap of 128,000; Opus 5.5 starts at 128,000; Opus 4.5, Sonnet 4.5 and Haiku 4.5 start at 32,000 and stop at 64,000. A model ID Claude Code doesn't recognize, like a gateway's own name for a model, gets 32,000. A value that isn't a positive number is ignored and the default is used. (Scientific notation used to break it: before 2.1.208, 1e6 became 1.)
Raising it also costs you context. The official reference says a higher value "reduces the effective context window available before auto-compaction triggers", because that room is set aside for the reply. So setting it to the cap everywhere trades earlier compaction for fewer cut-off replies.
If you set it and still see 32000, check the version. Opus 4.6 users hit exactly that in February; a Claude Code collaborator replied in April that it "was fixed in v2.1.42" and is "now respected up to 64K for Opus 4.6 instead of being clamped to 32000".
What to do
The fix that always works is a smaller ask. Tell Claude to write the file in sections, or to do one module per turn. A hidden nudge already asked it to do that three times, and it didn't take, so say it yourself in plain words.
If one reply genuinely needs to be long, raise the variable toward your model's cap and restart Claude Code, since it's read at launch.
The context-window version
Right beside it in the code there's a second message:
API Error: The model has reached its context window limit.
This one comes from a different stop reason, model_context_window_exceeded, meaning the conversation plus the reply filled the whole window rather than the reply hitting its own ceiling. Claude Code tags it the same way and runs the same three-step recovery before showing it. Raising the output variable won't help here; /compact or a fresh session will.
Other lines the same feature prints
Match yours against these if the one at the top of the page is not quite it. They come from the same code and mean related things.
Claude's response exceeded the 32000 output token maximumAPI Error: Claude's response exceeded the 64000 output token maximum.To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.API Error: The model has reached its context window limit.stop_reason: max_tokens