[FEATURE] Add agent instance ID headers to API requests
Problem
Claude Code has per-agent instance IDs internally (createAgentId() in AgentTool.tsx, stored in AsyncLocalStorage), but these are not included in outgoing API requests. This makes it impossible for proxies and observability tools to:
- Distinguish subagent requests from main agent requests
- Group requests by agent instance (parallel same-type agents get merged)
- Build agent invocation trees (who spawned whom)
Currently the only way to identify subagents is fragile substring matching on system prompt content, which breaks on prompt changes and fails entirely for anonymized/stripped traces.
Proposal
Add two headers to outgoing Anthropic API requests:
x-claude-code-agent-id: <unique ID per agent instance>
x-claude-code-parent-agent-id: <agent ID of the parent, absent for main>
The agentId and parent context already exist in the runWithAgentContext async local storage (agentId, parentSessionId, invokingRequestId). They just need to be forwarded to the API client layer.
Impact
This would enable deterministic agent identification for any proxy or logging tool sitting between Claude Code and the Anthropic API — no heuristics, no prompt parsing, works for anonymized traces.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗