Fix guides · Claude Code ·
Fix Claude Code "response exceeded the 32000 output token maximum"
API Error: Claude's response exceeded the 32000 output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.
Claude Code stopped because a single reply from Claude was longer than the output limit for that request. Usually Claude tried to write one huge file, a long report or a big code dump in one go. Your files are not damaged. Ask it to continue in smaller pieces, or raise CLAUDE_CODE_MAX_OUTPUT_TOKENS if your model allows a higher cap.
Common causes – and how to tell which one you have
1. Claude tried to write a huge file in one reply
How to tell: You asked for a whole app, a long page, a big data file or a full test suite, and the error appeared while Claude was writing it.
Fix: Ask for the file in parts, or for a skeleton first and the details in follow-up turns. Edits to existing files use far fewer tokens than rewriting them.
2. A long report, plan or explanation
How to tell: The task was "analyse the whole codebase" or "write full docs" and Claude kept writing text instead of code.
Fix: Ask for a short summary first, then let it write the details to a file section by section.
3. Your output limit is lower than the task needs
How to tell: The error keeps coming back on tasks that genuinely need long output, even after splitting.
Fix: Set CLAUDE_CODE_MAX_OUTPUT_TOKENS to a higher value in your shell or in the env section of .claude/settings.json and restart. Defaults and caps depend on the model; values above the cap are lowered to it.
4. A subagent or headless run hit the limit
How to tell: The error came from a Task/subagent or a claude -p script, not from your main chat.
Fix: Give the subagent a narrower task with a smaller expected output, and make scripts ask for results in parts or write them to files.
How to fix it
- Don't retry the exact same prompt. It will usually hit the limit again.
- Type something like "continue, but write the rest in smaller parts, one file per step".
- If the task really needs long replies, set CLAUDE_CODE_MAX_OUTPUT_TOKENS (for example export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000) before starting claude, or in the env block of .claude/settings.json.
- Restart Claude Code so the new value is used. Claude Code lowers a value above your model's cap to the cap.
- Split the task: ask for a plan first, then one file or one section per turn.
- Run claude update so you have the latest limits and fixes.
Using Cursor, Claude Code or Windsurf?
This is a Claude Code limit, not a bug in your project. Tell Claude Code to continue in smaller chunks and to use file edits instead of printing whole files. For big generation jobs, ask it to write a plan first and work through it step by step.
The “fix” to avoid
Retrying the same prompt or setting CLAUDE_CODE_MAX_OUTPUT_TOKENS to a huge number rarely helps on its own: values above the model's cap are lowered to the cap, and one giant reply is slower and harder to review. Split the work instead.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
You stopped with "API Error: Claude's response exceeded the 32000 output token maximum". Don't redo the whole answer. Continue from where you stopped, but split the work: first list the remaining files or sections, then write one file or section per reply. Use edits to change existing files instead of rewriting them in full, and don't paste whole files or long logs back into the chat. Keep each reply short enough to finish.
Questions people ask
Did I lose my work?
No. Files Claude already wrote or edited stay on disk. Only the reply that was too long was cut off.
Why does it say 32000 when I set a higher value?
Defaults and caps vary by model, and some request types (for example subagents) can use their own limit. Check that you restarted Claude Code after changing the variable and run claude update.
Is this the same as running out of context?
No. Context is how much Claude can read. This limit is how much it can write in one reply. For context problems, use /compact or start a new session.