feat: agent-claude-code reports real $usage from stream-json #83

Merged
xiaomo merged 1 commits from feat/77-claude-code-usage into main 2026-06-04 22:55:16 +00:00
Owner

What

Claude Code adapter now reports real token usage from stream-json output — not just placeholder nulls.

What is reported

  • turns — from num_turns in result line
  • inputTokens — from usage.input_tokens
  • outputTokens — from usage.output_tokens
  • duration — from duration_ms (converted to seconds)

Claude Code already parsed all this data into ClaudeCodeParsedResult — this PR just maps it to the Usage type.

Changes

  • claude-code.ts — build Usage from parsed result in processClaudeOutput
  • package.json — add @united-workforce/protocol dependency
  • tsconfig.json — add protocol reference

747 tests pass.

Note

Stacks on PR #82 (hermes usage). Both can merge independently.

Ref

Fixes #77
Refs #68

## What Claude Code adapter now reports **real** token usage from stream-json output — not just placeholder nulls. ## What is reported - `turns` — from `num_turns` in result line - `inputTokens` — from `usage.input_tokens` - `outputTokens` — from `usage.output_tokens` - `duration` — from `duration_ms` (converted to seconds) Claude Code already parsed all this data into `ClaudeCodeParsedResult` — this PR just maps it to the `Usage` type. ## Changes - `claude-code.ts` — build `Usage` from parsed result in `processClaudeOutput` - `package.json` — add `@united-workforce/protocol` dependency - `tsconfig.json` — add protocol reference 747 tests pass. ## Note Stacks on PR #82 (hermes usage). Both can merge independently. ## Ref Fixes #77 Refs #68
xiaoju added 2 commits 2026-06-04 22:40:55 +00:00
feat: agent-hermes reports $usage (turns + duration)
CI / check (pull_request) Successful in 1m40s
7681e8b8e2
- Count assistant turns from session messages
- Measure wall-clock duration per prompt call
- inputTokens/outputTokens remain 0 (ACP protocol doesn't expose token data yet)
- Both runPrompt and continueHermes report usage

Fixes #76
Refs #68
- Map parsed numTurns, inputTokens, outputTokens, durationMs to Usage type
- Add @united-workforce/protocol dependency + tsconfig reference
- 747 tests pass

Fixes #77
Refs #68
xiaomo approved these changes 2026-06-04 22:55:15 +00:00
xiaomo left a comment
Owner

LGTM

LGTM ✅
xiaomo merged commit 4283e6766b into main 2026-06-04 22:55:16 +00:00
xiaomo deleted branch feat/77-claude-code-usage 2026-06-04 22:55:16 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#83