claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Invalid env var CLAUDE_CODE_MAX_OUTPUT_TOKENS

Open kfirfer opened this issue 1 year ago • 13 comments

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)

kfirfer avatar Jul 23 '25 22:07 kfirfer

Yup hit this one too on 1.0.59!

centminmod avatar Jul 24 '25 00:07 centminmod

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

unset CLAUDE_CODE_MAX_OUTPUT_TOKENS

haryoiro avatar Jul 24 '25 00:07 haryoiro

This also works! "CLAUDE_CODE_MAX_OUTPUT_TOKENS": 32000

saumya-bjm avatar Jul 24 '25 04:07 saumya-bjm

Looks like they added validation and limited it to 32000

BarreiroT avatar Jul 24 '25 10:07 BarreiroT

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

eggntoast avatar Jul 25 '25 15:07 eggntoast

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.

lukepopp avatar Jul 26 '25 04:07 lukepopp

In my case. This happens when using MCP.

archmagece avatar Jul 30 '25 05:07 archmagece

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

earth-sol avatar Aug 04 '25 10:08 earth-sol

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.

Curator4 avatar Aug 12 '25 01:08 Curator4

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

github-actions[bot] avatar Aug 15 '25 21:08 github-actions[bot]

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

KnowhereFern avatar Aug 16 '25 19:08 KnowhereFern

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.

shawnm-anthropic avatar Aug 22 '25 19:08 shawnm-anthropic

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.

github-actions[bot] avatar Aug 31 '25 14:08 github-actions[bot]