MAX_THINKING_TOKENS is global — causes subagent crashes when main agent uses a higher-cap model

Resolved 💬 4 comments Opened Feb 21, 2026 by georgmagi Closed Mar 24, 2026

Problem

MAX_THINKING_TOKENS is a single global env var that applies uniformly to the main agent and all subagents, regardless of each agent's model. This causes silent subagent failures when the main agent uses a model with a higher output token ceiling than the subagent model.

Concrete scenario

| Agent | Model | Max output tokens | MAX_THINKING_TOKENS | Result |
|-------|-------|-------------------|---------------------|--------|
| Main session | claude-opus-4-6 | 128,000 | 95,000 | Works fine |
| Explore subagent | claude-sonnet-4-5 | 64,000 | 95,000 | Crashes — 0 tool uses, empty result |

The user sets MAX_THINKING_TOKENS=95000 to maximize Opus thinking depth. Subagents spawned with model: "sonnet" (which has a 64k output cap) silently fail because 95k exceeds Sonnet's hard limit. The subagent shows 0 tool uses · Done with no useful output and no error message surfaced to the user or the parent agent.

Why this matters

Many workflows deliberately use mixed models — e.g., Opus for the main session and architectural planning, Sonnet for fast codebase exploration. This is even a recommended pattern. But a single global thinking budget makes it impossible to optimize for both:

  • Set it high (95k) → Sonnet subagents crash
  • Set it low (50k) → Opus main agent is artificially constrained to ~39% of its thinking capacity

Expected behavior

The thinking budget should respect per-model output token limits. Options:

  1. Per-model thinking token settings — e.g., MAX_THINKING_TOKENS_OPUS=95000, MAX_THINKING_TOKENS_SONNET=30000
  2. Automatic clamping — Claude Code clamps budget_tokens to min(MAX_THINKING_TOKENS, model_max_output - reserved_output) before sending the API request, so subagents silently degrade instead of crashing
  3. Percentage-based — e.g., THINKING_BUDGET_PCT=75 allocates 75% of each model's max to thinking

Option 2 seems like the lowest-friction fix — it requires no user-facing config changes and just prevents the crash.

Actual behavior

Subagent API call is made with a budget_tokens (or max_tokens) value exceeding the model's hard cap → API returns a 400 error → subagent reports 0 tool uses · Done with no diagnostic info to the parent agent.

Reproduction

  1. Set MAX_THINKING_TOKENS=95000 in ~/.claude/settings.json env block
  2. Use Opus as the main model
  3. Spawn an Explore agent (which uses Sonnet): Task tool with subagent_type=Explore
  4. Observe: agent completes instantly with 0 tool uses

Environment

  • Claude Code on Windows 11
  • Main model: claude-opus-4-6
  • Subagent model: claude-sonnet-4-5 (specified via model: "sonnet" in Task tool)
  • MAX_THINKING_TOKENS: 95000
  • CLAUDE_CODE_MAX_OUTPUT_TOKENS: 32000

View original on GitHub ↗

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