Subagents hitting max_tokens lose all work — no partial result returned to parent

Resolved 💬 3 comments Opened Apr 6, 2026 by vmihalis Closed Apr 9, 2026

Problem

When a subagent (spawned via the Agent tool) hits its context window limit (max_tokens stop reason), the work is completely lost. The parent receives no partial result — just a failure. The cost of the entire subagent run is wasted.

Evidence from Telemetry

Across 366 sessions, we have 13 max_tokens events. Every single one is a scheduling-related agent that was doing complex multi-step work:

| Agent | Tools Used | Cost | Task |
|-------|-----------|------|------|
| rebuild-avail | 45 | $9.59 | Schedule rebuild with availability |
| rebuild-413 | 11 | $6.04 | Schedule rebuild with demand data |
| scheduling teammates (6x) | 34-44 | $3.56-$5.41 each | Schedule phases via team agents |

Total wasted: ~$50+ on work that produced zero output.

What Happens

  1. Parent spawns agent with a complex task
  2. Agent works for 5-20 minutes, makes 30-45 tool calls, reads/writes files
  3. Agent hits context limit
  4. Parent receives... nothing useful. The agent's accumulated knowledge, intermediate results, and progress are gone.

Expected Behavior

Options (any would help):

  1. Graceful checkpoint: When approaching context limit (~80%), the agent should be prompted to summarize its findings and return what it has. A partial result is infinitely more valuable than no result.
  1. Context budget awareness: Expose remaining context budget to the agent (via a system event or tool) so it can self-manage. Related to closed #17033 but that was about sessions — this is specifically about subagents.
  1. Partial result on max_tokens: Even if the agent can't run more turns, whatever it last produced (its final assistant message) should be returned to the parent as the result, tagged as incomplete.

Impact

Anyone running complex multi-step agents (scheduling, code generation, analysis) where the task naturally fills context. The current behavior punishes ambitious agent usage — you either keep tasks artificially small or accept that some runs will waste $5-10 with zero output.

Environment

  • Claude Code (CLI + Desktop)
  • Opus 4.6 (1M context)
  • Windows 11
  • Subagents spawned via Agent tool with maxTurns 25-50

View original on GitHub ↗

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