CLAUDE_CODE_MAX_OUTPUT_TOKENS has no effect on Opus 4.6 (capped at 32K)

Resolved 💬 3 comments Opened Feb 28, 2026 by jmpl-code Closed Mar 3, 2026

Bug Description

CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable has no effect when using Claude Opus 4.6 (claude-opus-4-6). The output is always capped at 32,768 tokens regardless of the value set.

Reproduction Steps

  1. Set export CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000
  2. Run claude --model claude-opus-4-6 --print --output-format json "Generate a large codebase..."
  3. Observe that stop_reason: max_tokens is returned with ~32K output tokens, ignoring the 64K setting

Expected Behavior

Setting CLAUDE_CODE_MAX_OUTPUT_TOKENS=64000 should allow up to 64K output tokens (Opus 4.6 supports 128K output via the API).

Actual Behavior

Output is always capped at 32,768 tokens. The stop_reason field in JSON output returns max_tokens, confirming the hard cap.

Additional Context: MAX_THINKING_TOKENS default

A related critical issue: MAX_THINKING_TOKENS defaults to 31,999 when using extended thinking. On a 32K output budget, this leaves only ~769 tokens for actual code output. This is the root cause of severe output truncation for code generation tasks.

Workaround: Setting export MAX_THINKING_TOKENS=4000 recovers ~28K tokens for actual output.

Impact

This is a blocking issue for multi-agent code generation pipelines where agents need to produce complete source files. The 32K cap combined with the 31,999 thinking default means agents produce truncated, incomplete code.

Environment

  • Claude Code CLI: latest (npm @anthropic-ai/claude-code)
  • Model: claude-opus-4-6
  • OS: Ubuntu 24.04 (Docker container)
  • Node.js: 20.x
  • Using --print --output-format json --dangerously-skip-permissions

Workarounds Currently Applied

  1. MAX_THINKING_TOKENS=4000 — Recovers usable output budget
  2. --continue loop to resume after max_tokens truncation
  3. Incremental retry pipeline at orchestrator level

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗