[BUG] Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS

Status Fixed / completed
Maintainer reply None cached
Activity 13 comments · opened Jul 23, 2025 · closed Aug 22, 2025

version 1.0.59 (Claude Code)

error:

Error: Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: 64000
    at OU0 (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2699:18354)
    at r$B (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:1818:3011)
    at lu (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:1818:3081)
    at rvB (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2729:15752)
    at DbB (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2729:18219)
    at RM (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:65:19859)
    at Tv (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:42847)
    at Rv (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:38368)
    at YS (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:38296)
    at lM (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:38150)

  ERROR  Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: 64000

 file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2699:18354

 - OU0 (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2699:18354)
 - r$B (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:1818:3011)
 - lu (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:1818:3081)
 - rvB (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2729:15752)
 - DbB (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:2729:18219)
 - RM (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:65:19859)
 - Tv (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:42847)
 - Rv (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:38368)
 - YS (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:38296)
 - lM (file:///Users/dev345/.local/share/fnm/node-versions/v22.16.0/installation/lib/node_modules/@anthropic-ai/claude-code/cli.js:67:38150)

View original on GitHub ↗

13 Comments

centminmod · 1 year ago

Yup hit this one too on 1.0.59!

haryoiro · 1 year ago

I had the same issue and resolved it by unsetting the CLAUDE_CODE_MAX_OUTPUT_TOKENS.

unset CLAUDE_CODE_MAX_OUTPUT_TOKENS
saumya-bjm · 1 year ago

This also works!
"CLAUDE_CODE_MAX_OUTPUT_TOKENS": 32000

BarreiroT · 1 year ago

Looks like they added validation and limited it to 32000

eggntoast · 1 year ago

Im having the same issue, how do I solve this? Im novice in this whole scene and still learning..
Im running windows vs code, and claude inside wsl terminal.

Where do i input CLAUDE_CODE_MAX_OUTPUT_TOKENS": 32000 ? or unset CLAUDE_CODE_MAX_OUTPUT_TOKENS specifically?

I have tried adding it into the ".bashrc" file which is located in \\wsl$\Ubuntu\home\User\ but it didnt work.
I have also tried adding it into CLAUDE.md but didnt work.
Also tried adding it into "settings.json" which is located in \\wsl$\Ubuntu\home\User\.claude but no luck there either..

The only way i could get it to somewhat work was by going into this directory:
"file:///home/User/.claude/local/node_modules/@anthropic-ai/claude-code/" and opened the 9mb file "cli.js" in notepad++, scrolling all the way down to line 2902 which has exactly this code snippet:

{if(A.includes("3-5"))return 8192;if(A.includes("haiku"))return 8192;let B=process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS;if(B){let Q=parseInt(B,10);if(!isNaN(Q)&&Q>0&&Q<=32000)return Q;else throw new Error(Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: ${B})}return 32000}

i replaced that entire line with this instead:

{if(A.includes("3-5"))return 8192;if(A.includes("haiku"))return 8192;let B=process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS;if(B){let Q=parseInt(B,10);if(!isNaN(Q)&&Q>0&&Q<=999999999)return Q;else throw new Error(Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: ${B})}return 999999999}

And this made it finally work... now I can open WSL terminal in VS code and type "claude" to launch it again.
But after restarting VS code, its back to the same problem.. and i have to do this again.

Really any help would be appreciated :) and sorry for the noob stuff

lukepopp · 1 year ago

I'm using amazon bedrock for accessing anthropic models like Sonnet v4. Why is there an env limit of 32000 for CLAUDE_CODE_MAX_OUTPUT_TOKENS? This will have a negative impact on performance.

archmagece · 1 year ago

In my case.
This happens when using MCP.

earth-sol · 1 year ago

This is an issue with AWS Bedrock as well as direct Anthropic API.

Curator4 · 1 year ago

yeh I got API Error: Claude's response exceeded the 32000 output token maximum. To configure this behavior, set the CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.

but setting a new CLAUDE_CODE_MAX_OUTPUT_TOKENS in env gave me the same error as op.

github-actions[bot] · 1 year ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/4510

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

KnowhereFern · 1 year ago

Confirming that this issue is still present on the latest version:

Error: Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: 64000
at AL0 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1875:28634)

And in the code section I see:

javascriptfunction AL0(A){
  if(A.includes("3-5"))return 8192;
  if(A.includes("haiku"))return 8192;
  let B=process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS;
  if(B){
    let Q=parseInt(B,10);
    if(!isNaN(Q)&&Q>0&&Q<=32000)return Q;
    else throw new Error(`Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: ${B}`)
  }
  return 32000
}

The validation logic clearly shows:

It checks if the value is between 1 and 32,000 (Q>0&&Q<=32000)
if value of 64,000 exceeds this maximum
When the value is out of range, it throws the exact error

shawnm-anthropic · 1 year ago

This issue was fixed in Claude Code v1.0.85.

What changed: The hard error "Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS: 64000" that crashed Claude Code has been replaced with graceful validation that doesn't crash.

Current behavior:

  • Invalid values are handled without crashing
  • Run /doctor to see any environment variable validation issues

Please claude update to resolve this issue.

github-actions[bot] · 12 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.