Subagents are capped at 8000 output tokens while the main loop is not — high effort exhausts the budget on thinking alone, killing the agent before it emits anything

Status Open
Reported on v2.1.212
Maintainer reply None cached
Activity 7 comments · opened Jul 17, 2026

Version: 2.1.212 (also reproduced on every version back to 2.0.76)
Platform: macOS 15 (darwin arm64), M4 Max
Model: reproduced on claude-sonnet-5, claude-opus-4-8, claude-fable-5

Summary

Agents launched via the Agent/Task tool receive max_tokens: 8000, while the
main loop and claude -p on the same machine and model receive substantially more
(measured: 15,656 output tokens in a single response, no cap hit).

Because extended-thinking tokens count against max_tokens, a subagent running at
--effort xhigh can consume the entire 8000-token budget on thinking and die
with an API error before producing any output at all. The failure looks like the
agent crashing for no reason on its first response.

CLAUDE_CODE_MAX_OUTPUT_TOKENS does not apply (consistent with #25569), and the
error message misleadingly instructs the user to set the variable they already set.

Evidence

1. The subagent cap is exactly 8000 and is real

Across 640,330 assistant responses in local transcripts (2026-01-03 → 2026-07-17,
CC 2.0.76 → 2.1.212), output_tokens at a stop_reason: max_tokens never exceeds

  1. Distinct observed values at the stop:
[86, 256, 1583, 2275, 2318, 2361, 2404, 3635, 7996, 7997, 7998, 7999, 8000]
max = 8000   (n = 2,626 max_tokens stops)

claude-sonnet-5: 25,191 responses, max output_tokens = 8000, never once higher,
299 max_tokens stops.

2. The main loop is NOT capped at 8000

Same machine, same model, same minute:

$ claude -p "<hard reasoning task>" --model sonnet --effort xhigh --output-format json
  stop_reason: end_turn
  output_tokens: 15656          # ← nearly 2x the subagent cap, no error

3. CLAUDE_CODE_MAX_OUTPUT_TOKENS has no effect (A/B)

A: CLAUDE_CODE_MAX_OUTPUT_TOKENS=128000 → stop=end_turn, out_tokens=11,122
B: variable unset                       → stop=end_turn, out_tokens=11,198

4. High effort exhausts the budget on thinking alone

Identical prompt and model, only --effort varies:

| effort | output_tokens | answer text (chars) | vs 8000 cap |
|---|---|---|---|
| xhigh (run 1) | 15,656 | 11,760 | 195% — cannot complete |
| xhigh (run 2) | 10,012 | 5,258 | 125% — cannot complete |
| low (run 1) | 3,778 | 10,876 | 47% — completes |
| low (run 2) | 3,386 | 9,922 | 42% — completes |

At xhigh the great majority of the budget is thinking, and the request exceeds
8000 while still thinking — so a subagent dies having emitted nothing. The same
prompt at low finishes well inside the cap.

This is not an argument that effort is unnecessary. A blind judge scored the xhigh
answer higher than the low answer (36 vs 32 across correctness/depth/rigor). The
point is that a subagent currently cannot use high effort at all on a hard task:
the cap converts a better answer into no answer. Users are forced to trade reasoning
quality for the agent simply completing.

Reproduction

In a session with "effortLevel": "xhigh" in settings.json:

Agent(
  subagent_type: "general-purpose",
  model: "sonnet",
  prompt: "Design a distributed rate limiter giving exact per-key limits under
           network partition. Analyze at least five distinct failure modes, the CAP
           tradeoff each forces, and reconcile them. Be rigorous and complete."
)

Result:

Agent terminated early due to an API error: API Error: Claude's response exceeded
the 8000 output token maximum. To configure this behavior, set the
CLAUDE_CODE_MAX_OUTPUT_TOKENS environment variable.

The same prompt via claude -p --effort xhigh succeeds at 15,656 output tokens.

A second, simpler reproduction (count from 1 to 20000, one per line, no tools) also
dies at 8000 after one silent auto-recovery.

Impact

This is not a niche limit. Any subagent doing genuinely hard work at default effort
is liable to die before emitting a token, and the error gives the user no indication
that effort/thinking is what consumed the budget. In our fleet, six of eight
production subagents hit this at least once. The only agents that survived were ones
given prompts terse enough to suppress thinking, which is a workaround that costs
reasoning quality.

Notably, every public report of this error cites 32000, not 8000 — so the
8000 figure may be a regression or an unreported rollout.

Requests

  1. Apply CLAUDE_CODE_MAX_OUTPUT_TOKENS to Agent/Task requests, or add

CLAUDE_CODE_SUBAGENT_MAX_OUTPUT_TOKENS.

  1. Allow effort in agent frontmatter so a subagent's thinking budget can be

tuned independently of the session.

  1. Reserve thinking budget against max_tokens so an agent cannot spend 100% of

its output allowance thinking and emit nothing.

  1. Fix the error message: it should not instruct the user to set a variable that

is ignored on this code path, and should name effort/thinking as the consumer.

Related

  • #25569 — CLAUDE_CODE_MAX_OUTPUT_TOKENS not applied to subagent (Task tool) API calls
  • #24055 — error fires during extended thinking
  • #8775 — agent output-limit handoffs (closed as duplicate)

View original on GitHub ↗

4 Comments

kcarriedo · 1 month ago

This is a real production blocker. The asymmetry you documented - 8,000 output tokens for subagents vs 15,656 for the main loop on identical prompts - makes xhigh effort essentially unusable for complex delegation.

One angle worth noting: the extended-thinking token accounting is the sneaky part. The budget gets consumed before any output bytes land, so the agent "succeeds" at calling Claude but produces nothing the caller can use. The misleading CLAUDE_CODE_MAX_OUTPUT_TOKENS error message makes it worse because you follow the guidance and nothing changes.

A minimal mitigation some people have used: break the complex prompt into a chain of smaller subagent calls, each with a narrower scope that stays under 8k output. Not a fix for the root cause but it keeps the fleet running while waiting for the env var to be respected. The quality tradeoff you measured (36/40 vs 32/40 for xhigh vs low) matches what others in similar setups have found - the reasoning cut costs you accuracy.

The related issues you linked (#25569, #24055) suggest this has been a known edge for a while. Hope the 640k response sample is useful signal for the team to prioritize this.

kcarriedo · 1 month ago

The 8000 token cap on subagent output is a real footgun for anyone running agent fleets at scale. Your point about extended thinking exhausting the budget before any output lands is the exact failure mode that's hard to diagnose -- the error message sending people to CLAUDE_CODE_MAX_OUTPUT_TOKENS is actively misleading.

The "six of eight production subagents hit this at least once" stat is striking. What's your current workaround -- are you capping effort on subagent calls manually, or restructuring tasks to avoid high-effort subagent work entirely?

We're tracking this class of issue (subagent resource limits, observability gaps, fleet coordination) as part of building orchestration tooling on top of Claude Code. The mismatch between what the main loop gets and what subagents get seems like a foundational gap that compounds every time you go deeper in the agent tree.

kcarriedo · 27 days ago

The 8000-token subagent output cap interacts badly with extended thinking in a way that is hard to debug because the failure looks like an agent crash rather than a budget exhaustion. The symptom is a silent abort on the first response with no indication that thinking tokens consumed the entire budget before any output was emitted.

A pattern that has helped: set a thinking budget cap explicitly per subagent invocation rather than relying on the effort dial to self-limit. Something like:

await agent(prompt, {
  thinking: { type: 'enabled', budget_tokens: 3000 },
  label: 'subagent-name'
})

This at minimum keeps the thinking portion from racing to 8000 before output can start. It does not fix the root issue (subagents getting a different max_tokens ceiling than the main loop), but it makes the tradeoff explicit and predictable.

The asymmetry between main loop (~15k tokens) and subagent cap (8k) is worth tracking as a known constraint when designing multi-agent workflows. The workaround of using terse prompts to suppress thinking is a real quality loss, as the scoring data in this issue shows.

Tracking this issue - it is relevant to anyone running high-effort reasoning in subagent trees.

dsc-tommaso-celano · 25 days ago

bump, we encountered the same issue with our agentic loop setup.

Showing cached comments. Read the full discussion on GitHub ↗