Feature Request: Add parent_tool_use_id to hook payloads for nested span correlation
Summary
When building observability tooling for Claude Code (tracing, span correlation), there's no way to correlate subagent tool executions back to the parent Task that spawned them.
Current Behavior
Hook payloads inside a subagent context only include:
{
"session_id": "abc123",
"tool_use_id": "tu_456",
"tool_name": "Grep",
...
}
Requested Behavior
Add parent_tool_use_id to hook payloads when executing inside a subagent:
{
"session_id": "abc123",
"tool_use_id": "tu_456",
"parent_tool_use_id": "tu_123", // The Task's tool_use_id
"tool_name": "Grep",
...
}
Use Case
This enables building distributed tracing visualizations (similar to Jaeger/OpenTelemetry) that show nested spans:
Session s1
├── Tool:Read (t1)
├── Tool:Task (t2)
│ ├── Tool:Grep (t3, parent: t2) ← Need this link
│ └── Tool:Read (t4, parent: t2) ← Need this link
└── Tool:Write (t5)
Affected Hooks
All hooks that can fire inside a subagent context:
- PreToolUse
- PostToolUse
- PermissionRequest
- SubagentStop (should include the parent Task's tool_use_id)
- Notification
Context
Building lit-claude - a Claude Code hooks → NATS bridge for observability. Without parent context, we can only do flat span correlation, not nested hierarchies.
This follows the standard distributed tracing model where each span carries:
trace_id(= session_id) ✓ Already havespan_id(= tool_use_id) ✓ Already haveparent_span_id(= parent_tool_use_id) ✗ Missing
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗