Background agents (run_in_background: true) terminate at ~20–30 tool uses with status: completed but mid-thought results, no signal for graceful wrap-up

Resolved 💬 1 comment Opened May 3, 2026 by R2calex Closed Jun 1, 2026

Summary

When dispatching subagents via the Agent tool with run_in_background: true, the agents are returning status: "completed" after ~20–30 tool uses, with their result field containing a sentence fragment that is clearly mid-work (e.g., "Let me verify:", "Now run the unit tests"). The agents have not actually finished the task they were given — they were terminated by the runtime.

There is no observable mechanism by which the agent can detect "approaching termination" and emit a structured wrap-up message (e.g., commit partial work, leave a note describing what remains).

Reproduction

  1. Dispatch a subagent (general-purpose, model sonnet or haiku) with isolation: "worktree" and run_in_background: true.
  2. Hand it a multi-step task whose natural completion would require ~30–50 tool uses (read several files, write tests, write implementation, run tests, write documentation, commit, push, open PR).
  3. Wait for completion notification.
  4. Inspect the returned result and usage.tool_uses count.

Observed across 5 dispatches in one session (different tasks, same pattern):

| Model | tool_uses | duration_ms | result snippet (visible mid-thought termination) |
|--------|-----------|-------------|--------------------------------------------------|
| sonnet | 29 | 189963 | "...Let me implement now. First, let me also check what \<helper\> returns to understand its mock interface:" |
| sonnet | 30 | 325535 | "...My changes are currently in the worktree. Let me verify:" |
| sonnet | 22 | 146084 | "Good. Now write the second document:" |
| sonnet | 21 | 179851 | "Now run the validator unit tests..." |
| haiku | 18 | 75270 | "Let me look at that method:" |

Expected behavior

Either:

  • (a) Document the cap explicitly and emit a system reminder to the agent at, say, 80% of cap utilization so the agent can wrap-up: commit partial work, write a status note, return a structured INCOMPLETE result with a clear list of what remains; or
  • (b) Provide a parent-side mechanism to extend an agent's budget mid-flight (the Agent tool docstring references "use SendMessage with the agent's ID" — but that tool is not available in this runtime, see separate issue).

Actual behavior

  • No prior signal; the agent is killed mid-tool-use chain
  • status is reported as completed (misleading — implies success), not truncated or terminated
  • The parent has to infer the termination from the mid-thought result snippet
  • Recovery requires relaunching with the partial work salvaged manually from the filesystem (which only works if the agent happened to write something to disk before termination)

Impact

For any non-trivial multi-step task (write tests + implement + verify + commit + PR), the success rate is effectively zero. Workaround is to split each task into 3+ micro-tasks of < 15 tool uses each, but that adds dispatch overhead and loses the benefit of giving an agent the full context to make local decisions.

Environment

  • Claude Code CLI
  • Linux (WSL2)
  • Subagents dispatched via Agent tool with subagent_type: general-purpose or Explore, run_in_background: true, isolation: "worktree"

Suggested next step

Confirm whether the cap is intentional (turn limit, token budget, time limit?) and document it. If intentional: add a near-cap signal so agents can emit structured incomplete results.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗