Cost/token usage metrics missing documented agent.name/query_source="subagent" attribution for Agent-tool (Task) dispatches

Status Open
Reported on v2.1.220
Maintainer reply None cached
Activity 1 comment · opened Aug 3, 2026

Title: Cost/token usage metrics missing documented agent.name/query_source="subagent" attribution for Agent-tool (Task) dispatches

Environment:

  • Claude Code 2.1.220 (confirmed latest via claude update)
  • Telemetry: CLAUDE_CODE_ENABLE_TELEMETRY=1, OTEL_METRICS_EXPORTER=otlp, OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf, exported to Grafana Cloud (Mimir-backed Prometheus)

Expected (per monitoring-usage docs):
Cost counter (claude_code.cost.usage) and token counter (claude_code.token.usage) metrics carry an agent.name attribute ("Subagent type that issued the request... Absent when the request was not issued by a named subagent type"), and query_source should take one of "main", "subagent", or "auxiliary". Per the docs, this does not require the traces beta flag (CLAUDE_CODE_ENHANCED_TELEMETRY_BETA) — only the plain metrics exporter.

Actual:
Dispatched a subagent via the Agent tool with an explicit model override (model: opus) from within a telemetry-enabled main session (main session on Sonnet). Queried the Prometheus endpoint's /api/v1/label/model/values and /api/v1/label/query_source/values repeatedly over 150 seconds (2+ full 60-second metric export intervals) after the subagent call completed.

Result: only claude-sonnet-5 (the main session's model) and query_source="main" have ever been recorded, across all time — not just this test window. No claude-opus-5, no query_source="subagent", and no agent.name/skill.name label appears anywhere in the metric's full label set.

Repro:

  1. Enable telemetry per the docs, pointed at any OTLP-compatible metrics backend.
  2. From a main session, dispatch a subagent via the Agent/Task tool using a different model than the main session.
  3. Query the cost or token usage metric's label set for that time window — agent.name is absent, and query_source never shows "subagent".

Impact:
Makes it impossible to audit per-subagent cost or model attribution via OTel metrics, despite the docs presenting this as supported. Main-session-level cost/token/model totals work correctly; only the subagent breakdown is missing.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗