Repository navigation
[STALE: REBASE FROM NEW FORK] feat(usage): log agentId from x-claude-code-agent-id - #16
vadymhimself wants to merge 1 commit into
Conversation
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Its title has been prefixed with |
…es rows
Claude Code subagents and teammates share the parent's session id and
metadata.user_id, so conversationId cannot attribute their tokens. The
x-claude-code-agent-id header is the one per-agent signal; log it as
agentId (shape ^a[\w-]{1,80}$), absent on the main agent or a bad value.
Co-Authored-By: Claude Code <noreply@anthropic.com>
8888251 to
895ea81
Compare
|
This PR is based on the superseded 2.65 gateway line. Rebuild the change from |
|
Trial evidence: before the merge the build ran 30.5 h on the laptop gateway and 24 h on the personal Mac Mini gateway, both with For new work:
Before opening a PR, use pinned Bun 1.4.4 with an isolated
Hosted-only behavior needs For this PR: not carried. Re-cut on 🤖 Generated with Claude Code |
Adds one field,
agentId, to Claude/v1/messagesusage rows (usage.jsonl and /api/logs), taken from thex-claude-code-agent-idheader.Why: Claude Code subagents and teammates send the parent's
x-claude-code-session-idandmetadata.user_id, soconversationIdcannot attribute their tokens (one conversation showed opus and sonnet rows). Probed locally against a fake server: only subagent requests carryx-claude-code-agent-id(a+ 16 hex); the main agent does not.agentIdFromHeaders(request-log-conversation.ts): value must match^a[\w-]{1,80}$, else absent.Test: one case in tests/claude-integration/claude-native-passthrough.test.ts (no header / valid / malformed, checked in /api/logs and in the persisted rows); fails without the src change.
bun teston that file + usage-log + request-log-conversation: 84 pass (on release/2.65.0-vadymhimself.15);bun x tsc --noEmitclean. No deploy or gateway roll in this PR.🤖 Generated with Claude Code