[BUG] SubagentStop fires without corresponding SubagentStart for internal agents

Resolved 💬 6 comments Opened Feb 21, 2026 by TAATHub Closed Apr 3, 2026

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

  1. Configure a hook script that logs all SubagentStart and SubagentStop events
  2. Use the Task tool to spawn a subagent (e.g., Explore or general-purpose)
  3. 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_type is always an empty string ""
  • No corresponding SubagentStart event is ever fired for these agent_id values
  • 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:

  1. A SubagentStart event should also be fired for these internal agents, OR
  2. SubagentStop should not be fired for internal agents that don't have a corresponding SubagentStart

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_type or tracking agent_id sets)

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

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗