Skip to content

[STALE: REBASE FROM NEW FORK] feat(usage): log agentId from x-claude-code-agent-id - #16

Draft
vadymhimself wants to merge 1 commit into
release/2.65.0-vadymhimself.15from
ops-low-r/gw-agent-id
Draft

vadymhimself wants to merge 1 commit into
release/2.65.0-vadymhimself.15from
ops-low-r/gw-agent-id

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Adds one field, agentId, to Claude /v1/messages usage rows (usage.jsonl and /api/logs), taken from the x-claude-code-agent-id header.

Why: Claude Code subagents and teammates send the parent's x-claude-code-session-id and metadata.user_id, so conversationId cannot attribute their tokens (one conversation showed opus and sonnet rows). Probed locally against a fake server: only subagent requests carry x-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.
  • Set in claude-messages.ts before native passthrough, so both paths are covered; carried through request-log.ts (type, addLog, usage append, hydration) and usage/log.ts (type, normalizer, 128-char cap).
  • No header, or a malformed one: no field. No other behaviour changes.
  • Not verified: that team teammates (as opposed to Agent-tool subagents) carry the header; check on the first rows after deploy.

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 test on that file + usage-log + request-log-conversation: 84 pass (on release/2.65.0-vadymhimself.15); bun x tsc --noEmit clean. No deploy or gateway roll in this PR.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 10, 2026
@github-actions github-actions Bot changed the title feat(usage): log agentId from x-claude-code-agent-id [WRONG BRANCH] feat(usage): log agentId from x-claude-code-agent-id Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (release/2.65.0-vadymhimself.15); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

…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>
@vadymhimself
vadymhimself changed the base branch from main to release/2.65.0-vadymhimself.15 November 10, 2026 16:40
@vadymhimself vadymhimself changed the title [WRONG BRANCH] feat(usage): log agentId from x-claude-code-agent-id [STALE: REBASE FROM NEW FORK] feat(usage): log agentId from x-claude-code-agent-id Nov 18, 2026
@vadymhimself

Copy link
Copy Markdown
Collaborator Author

This PR is based on the superseded 2.65 gateway line. Rebuild the change from port/ar-on-upstream-2026-11-18 (upstream-derived 2.100 AR overlay, PR #46): #46 . Do not rebase onto or merge the old release line. Preserve the new gateway quota/cache gate and re-run the affected regressions. The candidate is not deployed; do not publish or replace a running gateway without explicit approval.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant