[BUG] Background Bash task launched by a subagent is killed when the subagent returns; the promised completion notification can never fire
What's wrong
Any long-running process a subagent dispatches with run_in_background: true is killed the moment the subagent ends its turn. The kill is silent, and the Bash tool result had just told the subagent "You will be notified when it completes" — so a coordinator subagent that backgrounds a 20-minute build and ends its turn expecting the wake loses the build mid-run and waits on a notification that cannot arrive. To the parent session this is indistinguishable from work in progress. We hit it twice in one production run (a coordinator subagent dispatching Codex CLI builds) before isolating it.
Environment
- Claude Code 2.1.220, macOS (Darwin 25.5.0), model claude-fable-5
- Subagent type:
general-purpose, spawned via the Task tool, foreground
Steps to reproduce
- From the main session, spawn a subagent instructed to:
- run, via Bash with
run_in_background: true(no trailing&):
````
echo "START $(date -u +%H:%M:%S)" >> /tmp/wake-test.log; sleep 60; echo "TASK_DONE $(date -u +%H:%M:%S)" >> /tmp/wake-test.log
- confirm
STARTis in the log, then end its turn immediately; - append
SUBAGENT_RESUMEDto the log if it is ever re-invoked.
- Wait 2 minutes. Inspect the log and the process table.
Observed (2/2 runs, identical)
STARTpresent — the task launched and can write to the path.TASK_DONEabsent and nosleepprocess alive — the task was killed within seconds of the subagent returning, well short of its 60-second lifetime.SUBAGENT_RESUMEDabsent — no wake ever reached the subagent.
Control, same session: the identical command backgrounded from the main session survives the turn boundary and fires the completion notification normally.
Expected
The model-facing contract should match the lifecycle. Today the tool result in subagent context says the task will run to completion and notify — both halves are false: the task dies with the subagent, and no notification path exists.
Ask
In subagent context, have the Bash tool result state the real contract: the task is terminated when the subagent finishes, so results must be collected before ending the turn. That one line closes the trap; whether to additionally resume subagents on task completion is a feature decision this report doesn't presume.
This looks like the successor to #23154, where a subagent's background tasks outlived it and accumulated as orphans — if the kill-at-return was added as that cleanup, the lifecycle is now fine and only the model-facing contract is stale. Adjacent but distinct (main-session notification delivery, not the subagent-side kill): #21165, #21048, #59962.