Claude Code "API Error: Claude's response exceeded the ... output token maximum": what it means and how to fix it
This error appears in Claude Code, Anthropic's coding agent, when a single reply from Claude reaches the largest number of output tokens the request allowed and is cut off there. It is a limit on the length of one reply, not a rate limit, a billing problem or a context-window overflow. Anthropic documents two variants of the message, and they have different fixes: one can be changed with the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable, the other explicitly cannot.
The 30-second answer
- Get the rest of the reply first: in an interactive session, reply
continue. Per the official error reference, the text Claude wrote before the cutoff stays in the conversation. - Read the message to the end. If it says "To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable", raising that variable can help. If it says "for a request sent without streaming", the variable cannot raise the limit.
- The variable is capped per model. Claude Code lowers a value above the model's cap to the cap, so a very large number is not a way around the limit.
- The durable fix is smaller replies: ask for one file or one section per reply.
- The number in the message varies. The docs print it as
...; only the 64000 non-streaming case is documented as a fixed value.
The exact error
API Error: Claude's response exceeded the ... output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable. 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.
Both lines are copied from the section "Response exceeded the output token maximum" of Anthropic's Claude Code error reference, fetched on 9 November 2026. The ... in the first line is the documentation's own placeholder for a number that depends on the request. Specific numbers that users report seeing there, most often 32000, are user-reported and were not reproduced for this page.
Verified against the official docs — 9 November 2026
This page is doc-cited, not reproduced. The error was not triggered in a real Claude Code session: doing so needs a signed-in session and a paid reply long enough to hit the limit. What was checked today:
1. The error reference. Its "Find your error" table lists Claude's response exceeded the ... output token maximum under Request errors. The linked section describes the cause as "Claude's reply reached the largest number of output tokens the request allowed and was cut off there", and gives the two message forms shown above.
2. The environment variable reference. The CLAUDE_CODE_MAX_OUTPUT_TOKENS row on the environment variables page reads, in full:
Set the maximum number of output tokens for most requests. Defaults and caps vary by model; see max output tokens. Claude Code lowers a value above a model's cap to the cap. For a model ID Claude Code can't resolve to a model it knows, the default is 32000 and the cap is 128000. Increasing this value reduces the effective context window available before auto-compaction triggers
3. The installed version on the machine used for this page (macOS; no session was started and no configuration was changed):
$ claude --version 2.1.321 (Claude Code)
Not verified: the per-model default and maximum output values. The docs link to Anthropic's models overview for those, and that page was not fetched for this article, so no per-model numbers are given here. The numbers users report in the first variant were also not verified.
Step 1: Work out which variant you have
The two messages start the same way and end differently. The ending tells you whether a setting can help.
| Message ends with | What the docs say it means | Can the variable raise it? |
|---|---|---|
| "To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable." | The reply hit the output maximum for the request | Yes, up to the model's cap |
| "for a request sent without streaming. The CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable cannot raise this limit." | A streaming request failed and Claude Code re-sent it without streaming, which limits the reply to 64,000 output tokens | No |
In both cases the first move is the same and is the one the docs list first: if Claude wrote some text before the cutoff, reply continue in an interactive session to ask for the rest.
Step 2: The reply is simply too long for one turn
The usual shape of this problem is a request that asks for a great deal of output in one reply: a whole large file, many files at once, or a long document. The documented fix does not involve any setting:
- Ask Claude for the output in smaller pieces, "such as one file or one section per reply" (the error reference's wording).
- Use
continueto finish a reply that was already cut off.
This works for both variants and has no side effect on the context window, so try it before changing configuration.
Step 3: Raise CLAUDE_CODE_MAX_OUTPUT_TOKENS (first variant only)
If your message tells you to set the variable, you can raise the per-reply maximum. Three documented facts decide whether it will help:
- There is a cap per model. "Claude Code lowers a value above a model's cap to the cap." If you are already at the cap, a bigger number changes nothing.
- It costs context. "Increasing this value reduces the effective context window available before auto-compaction triggers." A higher output limit means compaction happens sooner in long sessions.
- It covers "most requests", not all. The docs do not list which requests are excluded.
The environment variables page documents two places to set a variable. Its own examples use API_TIMEOUT_MS; the snippets below follow the same documented pattern with this variable's name. The value 64000 is only an example, not a recommendation for your model.
In your shell, before launching claude (macOS, Linux, WSL). This lasts for that terminal session; add the export line to ~/.bashrc or ~/.zshrc to keep it:
export CLAUDE_CODE_MAX_OUTPUT_TOKENS="64000" claude
On Windows PowerShell the documented form is $env:NAME = "value", and on Windows CMD it is set NAME=value. Claude Code reads shell variables at startup, so a change takes effect the next time you launch claude.
In a settings file, under the env key. This applies every time claude runs, however it was launched:
{
"env": {
"CLAUDE_CODE_MAX_OUTPUT_TOKENS": "64000"
}
}
The docs list which file applies to whom: ~/.claude/settings.json for you in every project, .claude/settings.json for everyone working in the project, .claude/settings.local.json for you in this project only, and managed settings for an organization. If the same variable is set in both your shell and a settings file, the docs say the settings file value applies in most sessions, so check both places if your change seems to be ignored.
Step 4: The 64000 "without streaming" variant
This message means the limit was not set by your configuration. The error reference explains that a streaming request failed, Claude Code re-sent it without streaming, and that re-sent request is limited to 64,000 output tokens. The message says outright that the variable cannot raise this limit.
The documented options are the same two as in Step 2: reply continue, and ask for smaller pieces. The error reference does not say why the original streaming request failed or how to prevent the fallback, so this page does not guess.
One version note from the same section: "Before v2.1.299, a reply cut off on such a re-sent request ended the turn without this message, as if the reply were complete." If you are on an older version and long replies sometimes stop short with no error, that is the documented explanation. Run claude --version to check.
Step 5: Custom or gateway model IDs
If you reach Claude through a gateway or alias that Claude Code does not recognize, the limits are different. The variable's documentation says: "For a model ID Claude Code can't resolve to a model it knows, the default is 32000 and the cap is 128000." In that setup the default output maximum may be lower than the model actually supports, and setting CLAUDE_CODE_MAX_OUTPUT_TOKENS explicitly is the documented way to change it, up to 128000.
FAQ
What value should I set CLAUDE_CODE_MAX_OUTPUT_TOKENS to? The documentation does not give one number. Defaults and caps vary by model, and a value above the model's cap is lowered to the cap rather than rejected. The per-model maximums are on Anthropic's models overview page, which was not fetched for this article. Remember the trade-off: a higher value leaves less context before auto-compaction.
Why does my error say 32000 when the documentation shows "..."? The docs use ... because the number varies with the request. Reports of 32000 are user-reported and were not reproduced here. The one documented source of that figure is the default for a model ID Claude Code cannot resolve (Step 5). Whether that explains any particular report is not verified.
Is the text Claude wrote before the cutoff lost? No, according to the error reference: "That text stays in the conversation." Reply continue in an interactive session to ask for the rest.
I set the variable and still get the error with 64000 in it. Why? That is the non-streaming variant. The request was re-sent without streaming after a streaming failure, and that path is limited to 64,000 output tokens regardless of the variable. Use continue and smaller requests.
Related
Verified on 9 November 2026: error wording, meaning and fixes checked against Anthropic's Claude Code error reference and environment variables reference as fetched that day, with Claude Code 2.1.321 installed locally. The error itself was not triggered, and per-model output limits and user-reported numbers were not verified.