CLAUDE_CODE_MAX_OUTPUT_TOKENS

Updated by

CLAUDE_CODE_MAX_OUTPUT_TOKENS sets the maximum output tokens Claude can produce per response for most requests; values above the model's cap are lowered to the cap. Default: Per model; for a model ID Claude Code does not recognize, 32000 (cap 128000). Values: Positive integer up to the model's output cap (64000, 64,000 and 6.4e4 all parse). No k suffix: 64k reads as 64. 0, negative or non-numeric values fall back to the default. Present since v2.1.69 or earlier and still present in v2.1.332. It is listed in the official reference.

StatusPresent in v2.1.332
AddedPresent since v2.1.69 or earlier
DefaultPer model; for a model ID Claude Code does not recognize, 32000 (cap 128000)
ValuesPositive integer up to the model's output cap (64000, 64,000 and 6.4e4 all parse). No k suffix: 64k reads as 64. 0, negative or non-numeric values fall back to the default
CategoryContext and compaction
Official docsListed
Checked againstv2.1.330

How to set it

For one session, export it in the shell that starts Claude Code:

export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000
claude

64000 long single responses, such as large file writes, stop hitting the default cap.

To apply it to every session, add it to the env object of a settings file:

// ~/.claude/settings.json
{
  "env": {
    "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "64000"
  }
}

Known issues

  • "Claude's response exceeded the 32000 output token maximum" means the response hit the current cap. Raising the variable helps only up to the model's own cap. Source: issue #24055.
  • For a request sent without streaming (the non-streaming fallback), the variable cannot raise the limit, and the error message says so. Source: issue #24055.
  • Before v2.1.42, Opus 4.6 stayed clamped at 32000 even with a higher value set. Source: issue #24159.

Release notes that mention it

Related variables

Frequently asked questions

What does CLAUDE_CODE_MAX_OUTPUT_TOKENS do?

Sets the maximum output tokens Claude can produce per response for most requests; values above the model's cap are lowered to the cap.

What is the default value of CLAUDE_CODE_MAX_OUTPUT_TOKENS?

Per model; for a model ID Claude Code does not recognize, 32000 (cap 128000).

What values does CLAUDE_CODE_MAX_OUTPUT_TOKENS accept?

Positive integer up to the model's output cap (64000, 64,000 and 6.4e4 all parse). No k suffix: 64k reads as 64. 0, negative or non-numeric values fall back to the default.

Which Claude Code version has CLAUDE_CODE_MAX_OUTPUT_TOKENS?

Present since v2.1.69 or earlier and still present in v2.1.332.

How do I set CLAUDE_CODE_MAX_OUTPUT_TOKENS?

Export it before starting Claude Code (export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000), or add it to the "env" object in ~/.claude/settings.json to apply it to every session. 64000 long single responses, such as large file writes, stop hitting the default cap.

All variables, searchable: Claude Code environment variables.