claude-code - 💡(How to fix) Fix Feature request: Include parent sub-agent context in hook stdin [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45222Fetched 2026-04-09 08:10:27
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1
  • Background sub-agent tool calls don't appear on the ACP wire — only the parent Agent/Task tool call does
  • The hook system is the only visibility path for background sub-agent tool activity
  • The SubagentStop hook already fires per sub-agent — this request extends that attribution to PreToolUse and PostToolUse

Root Cause

  • Background sub-agent tool calls don't appear on the ACP wire — only the parent Agent/Task tool call does
  • The hook system is the only visibility path for background sub-agent tool activity
  • The SubagentStop hook already fires per sub-agent — this request extends that attribution to PreToolUse and PostToolUse

Code Example

{
  "tool_name": "Grep",
  "tool_input": { "pattern": "..." }
}

---

{
  "tool_name": "Grep",
  "tool_input": { "pattern": "..." },
  "parent_tool_call_id": "toolu_01G4DRTnHw4vqwHcSddaHn4u"
}
RAW_BUFFERClick to expand / collapse

Feature Request

Include sub-agent context in hook stdin so that tool calls from background sub-agents can be attributed to their parent.

Current Behavior

When a background sub-agent (launched via the Agent tool with run_in_background: true) executes tools like Grep, Read, or Glob, the PreToolUse hook fires with:

{
  "tool_name": "Grep",
  "tool_input": { "pattern": "..." }
}

No field identifies which sub-agent triggered this tool call.

Requested Behavior

Include the parent sub-agent's tool_call_id (or an equivalent session/sub-agent identifier) in the hook stdin:

{
  "tool_name": "Grep",
  "tool_input": { "pattern": "..." },
  "parent_tool_call_id": "toolu_01G4DRTnHw4vqwHcSddaHn4u"
}

Use Case

Hooks that need to track or log sub-agent activity cannot distinguish which concurrent background sub-agent triggered a given tool call. With a single background sub-agent this is unambiguous, but with multiple concurrent background sub-agents there is no way to attribute tool calls to the correct parent.

Context

  • Background sub-agent tool calls don't appear on the ACP wire — only the parent Agent/Task tool call does
  • The hook system is the only visibility path for background sub-agent tool activity
  • The SubagentStop hook already fires per sub-agent — this request extends that attribution to PreToolUse and PostToolUse

extent analysis

TL;DR

Modify the PreToolUse hook to include the parent sub-agent's context, such as tool_call_id, to attribute tool calls from background sub-agents to their parent.

Guidance

  • Identify the source of the tool_call_id or equivalent identifier for the parent sub-agent and ensure it is accessible when the PreToolUse hook is fired.
  • Update the hook stdin to include the parent_tool_call_id field, as shown in the requested behavior example.
  • Verify that the updated hook correctly attributes tool calls to the parent sub-agent by testing with multiple concurrent background sub-agents.
  • Consider extending this attribution to the PostToolUse hook for comprehensive tracking of sub-agent activity.

Example

No explicit code changes are implied in the issue, but the modification might involve updating the hook stdin construction to include the parent_tool_call_id field, similar to the requested behavior example:

{
  "tool_name": "Grep",
  "tool_input": { "pattern": "..." },
  "parent_tool_call_id": "toolu_01G4DRTnHw4vqwHcSddaHn4u"
}

Notes

The exact implementation details depend on the internal workings of the Agent tool and the hook system, which are not fully described in the issue.

Recommendation

Apply a workaround by modifying the PreToolUse hook to include the parent sub-agent's context, as this directly addresses the requested behavior and provides a clear path to attributing tool calls to their parent sub-agents.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING