PreToolUse hook input should include agent_id to identify subagent origin
Summary
PreToolUse hook input does not include agent_id or agent_type, making it impossible to distinguish which subagent triggered a tool call. This blocks any implementation of per-subagent permission isolation.
Current behavior
PreToolUseHookInput extends BaseHookInput and only provides:
session_id, transcript_path, cwd, permission_mode,
hook_event_name, tool_name, tool_input, tool_use_id
agent_id and agent_type are available in SubagentStart/SubagentStop but not in PreToolUse.
Expected behavior
PreToolUseHookInput should also carry agent_id and agent_type (matching the shape already used by SubagentStartHookInput) so that hook implementations can identify which agent — orchestrator or a named subagent — is making the tool call.
Why this matters
Without agent_id in PreToolUse, the only workaround is tracking active subagents via SubagentStart/SubagentStop and applying a union of all active subagents' permissions. This means:
- When two subagents for different users run in parallel (e.g.,
user-reader-user1anduser-reader-user2), the union allows either subagent to access both users' data. - True per-instance isolation is impossible at the hook level.
Concrete use case: A scheduling agent that spawns per-user subagents to read private calendar/contact data (users/{userId}/). The orchestrator should be blocked from reading any user data; each user-subagent should be restricted to its own user's directory. This is straightforward to implement if agent_id is available in PreToolUse, but currently requires accepting a weaker union-based enforcement model.
Related issues
- #14859 — agent hierarchy information missing from hook events
- #272 — subagent_id missing from PreToolUse
- #7881 — shared session IDs across main agent and subagents
Verified SDK version
@anthropic-ai/claude-agent-sdk v0.2.52
Confirmed by logging the full PreToolUse input from inside a file-based subagent's frontmatter hook — agent_id is absent even when the hook is defined on the subagent itself.
Proposed fix
Add agent_id: string and agent_type: string to PreToolUseHookInput (and likely all other tool lifecycle hook inputs: PostToolUse, PostToolUseFailure).
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗