[BUG] Title: Nested sub-agents spawned by general-purpose agents are invisible and uncontrollable by both the parent session and the user
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When a top-level agent I spawn (via the Agent tool, general-purpose subagent type) itself calls the Agent tool internally to spawn its own child agents, those grandchild agents:
Are not surfaced to my session with any ID — I only receive a task-notification if/when one happens to report completion, with no way to enumerate siblings.
Continue running in the background even after the parent agent that spawned them has already finished and reported its own result back to me.
Are not listed by TaskList (returns empty — apparently a different tracker).
Cannot be stopped via TaskStop because I never have their task ID.
Are visible in the UI's "Background tasks" sidebar panel, but only stoppable manually by the user clicking a UI icon — there is no tool-level way for the assistant to discover or terminate them.
Impact: In this session, three such grandchild agents ran for over 90 minutes after their parent stage had already completed and been incorporated into the final result, silently burning ~180k+ tokens combined, with no notification to the user that this was happening, and no way for the assistant to clean them up. The user had to notice it themselves via the sidebar and manually stop each one.
What Should Happen?
Requested fix: Either (a) propagate child-agent IDs up to the spawning session so TaskList/TaskStop can see and terminate them, (b) auto-terminate orphaned grandchild agents once their parent agent has returned a final result, or (c) give the assistant a tool to enumerate and stop all background agents associated with the current session regardless of nesting depth.
Expected behavior: Either child agents spawned by a parent agent should be tracked and stoppable via the parent's session (TaskList/TaskStop), or they should be automatically terminated once the parent agent that spawned them returns its final result.
Error Messages/Logs
Steps to Reproduce
Here's a "Steps to Reproduce" section you can add to the issue:
---
Steps to Reproduce:
- Start a Claude Code session in a repo with at least two related sub-projects/docs (or any repo — the trigger is the task shape, not the repo).
- Ask the assistant to run a multi-stage investigative/audit task — e.g., "cross-check these docs against the actual source code and git history for accuracy" — where the natural approach is to delegate to a
general-purposesubagent via theAgenttool. - Have the assistant spawn a
general-purposeagent with an open-ended investigative prompt (e.g., "verify these claims against the code, re-diff these files, check git log for X and Y"). - Let that agent run to completion and report its result back to the main session.
- Open the "Background tasks" panel in the sidebar while the parent agent is running, and again after it reports completion.
Observed behavior:
- During step 4, the
general-purposeagent internally calls theAgenttool itself to spawn additional child agents to split up its investigation (observed: 3 such children from 2 parent stages in one session). - These child agents are not exposed to the main session with any ID — the assistant only learns about them if/when a
task-notificationhappens to arrive for one. - After the parent agent finishes and returns its result, its child agents are not stopped — they continue running independently in the background.
- The assistant's
TaskListtool returns empty (it queries a different, unrelated task tracker) andTaskStopcannot target them, since no ID was ever surfaced. - In the sidebar's "Background tasks" panel, these orphaned children remain visible under "Running" for 90+ minutes after the parent task that spawned them already completed, continuing to accrue tokens (observed ~180k tokens combined across 3 orphans in this session).
- The only way to stop them is for the user to manually click the stop icon on each row in the sidebar UI — there is no assistant-facing tool to detect or terminate them.
Expected behavior: Either child agents spawned by a parent agent should be tracked and stoppable via the parent's session (TaskList/TaskStop), or they should be automatically terminated once the parent agent that spawned them returns its final result.
Environment: Claude Code CLI, Sonnet 5, Windows 11, session using Agent tool with subagent_type: general-purpose for delegated multi-step research/audit tasks.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.202
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗