Repository navigation
Description
Summary
The CLI's Claude Code mode stream adapter discards token usage and cost, so any
consumer that renders run metrics from the JSON-line stream reports 0 in / 0 out / 0 total and no cost when running in Claude Code mode. The raw numbers already exist in
Claude's stream-json output; they are dropped on the floor.
In internal/infra/adapters/claude_code_client.go:
buildResponse()builds the response from accumulated content + tool calls only and
never setsresponse.Usage.- the streaming
createDeltaEvent()only emitschoicesdeltas, never a usage-bearing
chunk. transformMessage'scase "result"collapses Claude'sresultmessage - which
carriestotal_cost_usd, cumulativeusage,num_turns, andduration_ms- into a
baremessage_stop/doneevent, throwing the numbers away.ClaudeCodeMessage.TotalCostUSD
is parsed but referenced nowhere else.
Net effect: in cmd/agent.go, response.Usage == nil on every turn, so
processSyncResponse never accumulates tokens, requestCount stays 0, assistant lines
carry no token_usage, and emitSessionStats() returns early - no session_stats
line is emitted. (Tool-call metrics are unaffected because they do not depend on usage.)
Proposed fix
- Parse the
usageobject off each Claudeassistantmessage (input_tokens,
output_tokens,cache_creation_input_tokens,cache_read_input_tokens) and attach
it asresponse.Usage, soprocessSyncResponseaccumulates tokens and each assistant
line carriestoken_usage. - On the
resultmessage, surface the cumulativeusageandtotal_cost_usdso
requestCount > 0andemitSessionStats()emits asession_statsline. For a
subscription run the cost can be reported as Claude'stotal_cost_usd(an
equivalent/retail value) or0with a "subscription" marker - but the token counts
should be the real values.
Context. This is the upstream dependency for full run-metrics parity in
inference-gateway/infer-action's new Claude Code subscription mode
(inference-gateway/infer-action#132). The action already degrades gracefully (tool-call
counts/failures render; token usage + cost are simply omitted) and will render identical
token/cost footers in Claude Code mode with no further action-side change once this
lands.
Source references: internal/infra/adapters/claude_code_client.go (buildResponse,
createDeltaEvent, transformMessage case "result", ClaudeCodeMessage.TotalCostUSD);
cmd/agent.go (processSyncResponse, emitSessionStats).
Acceptance Criteria
- In Claude Code mode, each
assistantstream line carriestoken_usagewith the
real input/output (and cache) token counts parsed from Claude'susage. -
processSyncResponseaccumulates tokens sorequestCount > 0and asession_stats
line is emitted at the end of a Claude Code run. - The
session_statsline carries cost (Claude'stotal_cost_usd, or0with a
subscription marker) so downstream consumers can render per-session cost. - inference-gateway/infer-action's result footer shows non-zero token usage (and
cost) for a Claude Code run with no action-side change.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
edenreich commentedon Jun 24, 2026
Filed alongside inference-gateway/infer-action#133, which adds the action-side Claude Code subscription mode. The action degrades gracefully (tool-call metrics render; token usage + cost omitted) until this lands.
chore(release): 0.123.0 [skip ci]
inference-gateway-releaser commentedon Jun 24, 2026
🎉 This issue has been resolved in version 0.123.0 🎉
The release is available on:
Your semantic-release bot 📦🚀