Claude Code usage

Harness Claude Code Usage Repro

Repro: @ai-sdk/harness-claude-code finish-step reports the whole turn's cumulative usage on the last step, not that step's own

Install

From source
git clone https://github.com/mattpocock/harness-claude-code-usage-repro.git

From the README

@ai-sdk/harness-claude-code: last-step finish-step usage is the whole turn's cumulative total, not that step's own usage

Minimal reproduction. npm install && npm run repro — no API key needed, it
drives the package's own bridge event-processing code against a synthetic
(but protocol-accurate) Claude Code CLI stream.

The bug

On any turn with two or more model calls (i.e. any turn with at least one
tool round trip before the final answer — subagents not required), the
finish-step part emitted for the last step reports the whole turn's
cumulative usage (every step summed) instead of that step's own usage.

Concretely, in packages/harness-claude-code/src/bridge/index.ts,
on the CLI's turn-ending result message:

streamEventState.pendingStepUsage is already sitting there with the right
value — the final step's own assistant message set it correctly (see
create-emit-stream-event.ts).
But a text-only final response never runs through closeStepIfReady() (that
only fires from tool-result handling or finishApprovalStep), so the step is
still open when result arrives — and harnessUsage (the cumulative total)
wins over pendingStepUsage (the correct, final-step-only value) because of
the ?? precedence.

Expected vs. actual

Given a turn with:
- step 1 (a Bash tool call): 1000 input / 50 output tokens
- step 2 (the final text answer): 1800 input / 70 output tokens *of its own*
- CLI's result.usage (cumulative): 2800 input / 120 output tokens

Why it matters

Anything consuming finish-step/finish to answer "how many tokens did the
model just use" — most obviously, a live "how full is the context window
right now" indicator — overcounts by the sum of every prior step in the turn,
on every ordinary multi-tool-call turn. It's easy to miss in testing because
a single-model-call turn…
Read the full README on GitHub

Details

Language
TypeScript
Last updated
19 August 2026

FAQ

What is Harness Claude Code Usage Repro?

Repro: @ai-sdk/harness-claude-code finish-step reports the whole turn's cumulative usage on the last step, not that step's own It is a usage for Claude Code, from mattpocock/harness-claude-code-usage-repro on GitHub.

How do I install Harness Claude Code Usage Repro?

Clone mattpocock/harness-claude-code-usage-repro from GitHub and follow the setup steps in its README.

Is Harness Claude Code Usage Repro popular?

mattpocock/harness-claude-code-usage-repro has 36 GitHub stars and 7 forks. It was last updated on 19 August 2026.

More usage & cost trackers

Browse the most popular Claude Code mods, all usage & cost trackers, or the skills and MCP server directories.