[BUG] Nested background subagents stuck showing "Running" indefinitely despite having no active task
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?
Description
When a background agent (spawned via the Agent tool with run_in_background: true) itself spawns further nested background agents (grandchildren, or deeper), some of those nested agents never transition from "Running" to "Completed" in the Background Tasks panel, even though they have already produced their final output and are no longer actively computing.
What Should Happen?
Expected Behavior
Once a background agent (at any nesting depth) produces its final response with no further tool calls, its task status should transition to "Completed" and the Background Tasks panel should reflect that promptly — without requiring an external SendMessage "nudge" to trigger the transition.
Actual Behavior
Deeply nested background agents can sit in an ambiguous "Running" state indefinitely (confirmed one 20+ minutes and counting) after they have actually finished — no compute is happening (0 token/tool usage on nudge), but the panel and task tracking system never mark them completed unless manually resumed. In one session, this affected roughly 28 out of ~50 spawned agents.
Impact
- The Background Tasks panel becomes cluttered with dozens of phantom "Running" entries that are actually idle, making it hard for users to tell what's genuinely still consuming resources.
- Users may (reasonably) worry about runaway token/cost usage from tasks that appear to be running for 20+ minutes, when in fact no computation is occurring.
- No data loss occurs (the parent agents already collected and used the child agents' results before those children became orphaned), but the UX and observability around background task lifecycle is misleading.
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
- Launch several
Agenttool calls withrun_in_background: trueand give each a task that involves reading many files (encourages the agent to itself spawn parallel sub-agents via theAgenttool to speed up research). - Some of these top-level agents will, as part of their own execution, launch further nested background agents (grandchildren) — sometimes without properly awaiting/blocking on them (e.g. one agent used a hand-rolled
until [ -s file1 ] && [ -s file2 ]; do sleep 5; doneBash polling loop to wait on two of its own children instead of a proper blocking mechanism). - After the top-level parent agents all report completion (and their results are fully usable/correct), the Background Tasks panel still shows many of the nested grandchild/great-grandchild agents as "Running", some for 20+ minutes.
- Sending a new message to one of these "Running" agents via
SendMessage(using the agentId) returns:"Agent had no active task; resumed from transcript in the background with your message."— confirming the agent was NOT actually computing anything. - When resumed this way, the agent typically responds within 5-15 seconds with 0 tool_uses, simply restating a conclusion it had already produced earlier in its transcript, then explicitly stops.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
Claude for Windows (desktop app), version 1.17377.1 (2b3ab4)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗