[BUG] Subagent (Task tool) output silently truncated when final block is a tool_use — regression from #20190 persists in v2.1.139
Description
The Task tool drops most of a subagent's output when its message sequence ends with a tool_use block (or contains text → tool_use → text interleaving). The parent receives only the last text block before the terminal tool_use — which is often raw mid-investigation monologue, not the structured final report the subagent intended to return.
This is the same root cause documented in #20190 (closed and locked, originally reported on v2.1.19). The bug is still present in v2.1.139.
Root Cause (per #20190)
The CLI returns the last block only if it's a text block; if the last block is a tool_use, nothing is returned to the parent. -text → tool_use → text→ first text lost (truncation) -text → tool_use→ all text lost
Reproduction (v2.1.139)
- Spawn a subagent (e.g. via Task tool with
subagent_type: code-reviewer) and ask it for a structured Markdown report at the end. - Give it a task that requires interleaving analysis text with Read/Grep/Bash tool calls (e.g. "review this branch against this plan and produce a verdict in this exact format").
- The agent's transcript shows it correctly built up findings via tool_uses + analysis text.
- The returned result to the parent is the last
textblock before a terminal tool_use — which is the agent's mid-investigation internal reasoning, not the structured## Verdictit was prompted to produce.
Observed evidence
In one Task tool call, the returned content was a stream-of-consciousness paragraph ending with "...Let me also examine that..." followed by agentId: a07cdf575b9296133 (use SendMessage with to: '...' to continue this agent). The final structured report was never delivered to the parent, even though the agent had clearly been working toward one. The parent context (orchestrator) then has to redo the verification work itself, defeating the purpose of delegation.
Impact
- Subagents become unreliable for any task that involves tool_use → text patterns (which is nearly all real code-review, audit, or research tasks).
- Orchestrators waste tokens and time redoing the verification work the subagent already did.
- The "Output After Tools" workaround from #20190 is brittle: it requires modifying every subagent's system prompt to defer all output to a final text-only block, which is hard to enforce across
subagent_typedefinitions, and breaks the natural pattern of agents narrating their progress.
Expected behavior
The parent should receive the agent's full final assistant message (concatenated text blocks of the terminal message), not just the last text block before a tool_use. Alternatively, the harness should concatenate all text blocks across the agent's run, in order.
Environment
- Claude Code: v2.1.139
- Platform: macOS (darwin 25.4.0)
- Model: Claude Opus 4.7 (1M context) for parent; subagent inherited model
- Same bug reproduced on v2.1.19 per #20190; persists ~120 versions later.
References
- #20190 — original report (closed/locked, auto-closed by inactivity bot despite multiple confirmations)
- #17478, #16101 — flagged as duplicates by the duplicate-detection bot
Ask
Reopen tracking on this. The workaround is real but fragile, and the silent nature of the truncation (the agent thinks it produced output, the parent gets nothing) makes it especially expensive when it fires.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗