Include agent_id in PostToolUse hook payloads for subagent attribution

Resolved 💬 4 comments Opened Feb 1, 2026 by kyzzen Closed Feb 1, 2026

Problem

When multiple subagents run in parallel, hooks cannot determine which subagent made a specific tool call. The PostToolUse payload includes tool details but no agent context.

Current behavior

SubagentStart and SubagentStop hooks receive agent_id in their payloads, but PostToolUse does not:

// SubagentStart - has agent_id ✓
{"hook_event_name": "SubagentStart", "agent_id": "a1fd75b", ...}

// PostToolUse - missing agent_id ✗
{"hook_event_name": "PostToolUse", "tool_name": "Read", "tool_input": {...}, ...}

Impact

With 3 parallel subagents, all tool operations get attributed to a single agent (whichever is on top of a tracking stack), making activity logs inaccurate:

{"type": "glob", "agent_id": "a50287d"}  // Actually from agent 1
{"type": "read", "agent_id": "a50287d"}  // Actually from agent 3
{"type": "glob", "agent_id": "a50287d"}  // Actually from agent 2

Proposed solution

Include agent_id in PostToolUse (and ideally all tool-related hook payloads) when the tool call originates from a subagent:

{
  "hook_event_name": "PostToolUse",
  "tool_name": "Read",
  "tool_input": {"file_path": "/path/to/file"},
  "agent_id": "a1fd75b",  // <-- Add this field
  "session_id": "...",
  ...
}

For main agent calls, agent_id could be "main" or omitted.

Use case

Building activity tracking/context systems that log which agent performed which operations. Accurate attribution is essential for debugging multi-agent workflows and understanding agent behavior patterns.

View original on GitHub ↗

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