Feature Request: Add agent context to hook events for filtering notifications by agent type
Summary
When using subagents (Task tool) or agent teams, hook notifications (e.g., Notification, Stop) fire for all agents indiscriminately. There is currently no way to filter or suppress hook execution based on the agent type (main agent vs. subagent vs. team member).
Use Case
When working with multiple subagents or team members running in parallel, the main agent's hook notifications get mixed with those from subagents and teammates. For example, if I have a Notification hook that sends a desktop notification when Claude needs input, I receive notifications for every subagent completion — which is noisy and not actionable since subagents report back to the main agent automatically.
I'd like to only receive notifications for the main agent's events, while suppressing them for subagents and non-lead team members.
Proposal
- Add agent context fields to hook event JSON, such as:
``json``
{
"agent_type": "main" | "subagent" | "teammate",
"agent_id": "abc123",
"parent_agent_id": "def456",
...existing fields
}
- Support matcher filtering by agent type in hook configuration:
``json``
{
"hooks": {
"Notification": [
{
"matcher": {
"agent_type": "main"
},
"command": "notify-send 'Claude needs attention'"
}
]
}
}
Current Workaround
It's possible to use SubagentStart/SubagentStop hooks to track subagent activity via external state files, and then check that state in the Notification hook command. However, this is fragile and heuristic-based.
Environment
- Claude Code CLI
- Hooks feature
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗