[BUG] SubagentStop fires without corresponding SubagentStart for internal agents
Description
When using Claude Code hooks (SubagentStart / SubagentStop), orphaned SubagentStop events are fired without a corresponding SubagentStart. These orphaned events have an empty string for agent_type and no matching SubagentStart event exists in the hook log.
This may be a Claude Code-side issue rather than a network/transport problem, as the hook script logs show that the raw input received from Claude Code contains only SubagentStop for these agents, with no SubagentStart ever arriving.
Steps to Reproduce
- Configure a hook script that logs all
SubagentStartandSubagentStopevents - Use the
Tasktool to spawn a subagent (e.g., Explore or general-purpose) - Observe the hook event log
Observed Behavior
User-initiated subagents (e.g., Explore, general-purpose) correctly fire both SubagentStart and SubagentStop events. However, additional SubagentStop events appear for unknown internal agents that never had a SubagentStart:
22:38:44 SubagentStart agent_id=a41f69f agent_type=Explore # Normal pair
22:39:01 SubagentStop agent_id=a41f69f agent_type=Explore # Normal pair
22:39:07 SubagentStart agent_id=ac5ed77 agent_type=Explore # Normal pair
22:39:16 SubagentStop agent_id=ac5ed77 agent_type=Explore # Normal pair
22:39:30 SubagentStop agent_id=a25f01f agent_type="" # Orphaned! No SubagentStart
Key Characteristics of Orphaned Events
agent_typeis always an empty string""- No corresponding
SubagentStartevent is ever fired for theseagent_idvalues - They appear to be triggered by Claude Code's internal agents/processes, not user-initiated subagents
- This has been observed across multiple sessions and is consistently reproducible
Expected Behavior
Either:
- A
SubagentStartevent should also be fired for these internal agents, OR SubagentStopshould not be fired for internal agents that don't have a correspondingSubagentStart
Impact
- Applications monitoring agent lifecycle via hooks receive incomplete data
- Agent lifecycle tracking (spawn/stop pairing) becomes unreliable
- Hook consumers need to implement workarounds (filtering by empty
agent_typeor trackingagent_idsets)
Environment
- Claude Code version: latest (2026-02-21)
- OS: macOS (Darwin 25.1.0)
Related Issues
- #14859 - SubagentStart hook addition (partially implemented)
- #7881 - SubagentStop agent identification
- #6885 - Agent context detection in hook events
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗