Done.usage stays the last request (context size); usage_total is the sum
over all requests. Exposed in the NDJSON done line, RPC replies and hx stats.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
johannes
added 1 commit 2026-11-21 11:32:58 +00:00
Done.usage stays the last request (context size); usage_total is the sum
over all requests. Exposed in the NDJSON done line, RPC replies and hx stats.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JSON done line now emits usage_total, but the text-mode summary below still reads agent.usage() for pricing(...) cost. With claude_cli, usage is last-request context size, so cost and token totals may be wrong. Check whether it should use usage_total().
StreamEvent::Done gains usage_total. The README documents it as optional (usage_total?). Verify the field has #[serde(default, skip_serializing_if = "Option::is_none")]. Otherwise non-claude_cli providers emit "usage_total": null, and old persisted or RPC events may fail to deserialize. The updated roundtrip test only covers None.
New report line relies on total and turns, defined outside the visible diff. Confirm total sums every request per turn without double counting usage. Confirm the "in" figure (input + cache_read + cache_write) matches how the other stats lines compute input. The claude_cli test asserts input_tokens == 2, but no test covers this report line.
ifturns>0{let_=writeln!(s,"claude total over {turns} turns (all requests): {} in ({} cached) / {} out",total.input_tokens+total.cache_read_tokens+total.cache_write_tokens,total.cache_read_tokens,total.output_tokens);}
## PR Reviewer Guide 🔍
#### (Review updated until commit https://git.jokresner.de/johannes/hx/commit/0184627f272677e93e2c9303590ef84bf44b2100)
Here are some key observations to aid the review process:
<table>
<tr><td>⏱️ <strong>Estimated effort to review</strong>: 2 🔵🔵⚪⚪⚪</td></tr>
<tr><td>🧪 <strong>PR contains tests</strong></td></tr>
<tr><td>🔒 <strong>No security concerns identified</strong></td></tr>
<tr><td>⚡ <strong>Recommended focus areas for review</strong><br><br>
<details><summary><a href='https://git.jokresner.de/johannes/hx/src/branch/usage-total-claude-cli/crates/hx-cli/src/main.rs#L1336-L1340'><strong>Cost Uses Wrong Usage</strong></a>
JSON `done` line now emits `usage_total`, but the text-mode summary below still reads `agent.usage()` for `pricing(...)` cost. With `claude_cli`, `usage` is last-request context size, so cost and token totals may be wrong. Check whether it should use `usage_total()`.
</summary>
```rust
"usage": agent.usage(), "usage_total": agent.usage_total(), "session": path}),
);
}
let u = &agent.usage();
let cost = pricing(agent.model())
```
</details>
<details><summary><a href='https://git.jokresner.de/johannes/hx/src/branch/usage-total-claude-cli/crates/hx-ai/src/lib.rs#L349-L356'><strong>Serde Compatibility</strong></a>
`StreamEvent::Done` gains `usage_total`. The README documents it as optional (`usage_total?`). Verify the field has `#[serde(default, skip_serializing_if = "Option::is_none")]`. Otherwise non-`claude_cli` providers emit `"usage_total": null`, and old persisted or RPC events may fail to deserialize. The updated roundtrip test only covers `None`.
</summary>
```rust
let e = StreamEvent::Done {
message: m,
stop: StopReason::ToolUse,
usage: Usage::default(),
usage_total: None,
};
let s = serde_json::to_string(&e).unwrap();
assert_eq!(serde_json::from_str::<StreamEvent>(&s).unwrap(), e);
```
</details>
<details><summary><a href='https://git.jokresner.de/johannes/hx/src/branch/usage-total-claude-cli/crates/hx-core/src/stats.rs#L118-L126'><strong>Unverified Totals</strong></a>
New report line relies on `total` and `turns`, defined outside the visible diff. Confirm `total` sums every request per turn without double counting `usage`. Confirm the "in" figure (`input + cache_read + cache_write`) matches how the other stats lines compute input. The `claude_cli` test asserts `input_tokens == 2`, but no test covers this report line.
</summary>
```rust
if turns > 0 {
let _ = writeln!(
s,
"claude total over {turns} turns (all requests): {} in ({} cached) / {} out",
total.input_tokens + total.cache_read_tokens + total.cache_write_tokens,
total.cache_read_tokens,
total.output_tokens
);
}
```
</details>
</td></tr>
</table>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Done.usage stays the last request (context size); usage_total is the sum
over all requests. Exposed in the NDJSON done line, RPC replies and hx stats.
Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com
/review
PR Reviewer Guide 🔍
(Review updated until commit
0184627f27)Here are some key observations to aid the review process:
Cost Uses Wrong Usage
JSON
doneline now emitsusage_total, but the text-mode summary below still readsagent.usage()forpricing(...)cost. Withclaude_cli,usageis last-request context size, so cost and token totals may be wrong. Check whether it should useusage_total().Serde Compatibility
StreamEvent::Donegainsusage_total. The README documents it as optional (usage_total?). Verify the field has#[serde(default, skip_serializing_if = "Option::is_none")]. Otherwise non-claude_cliproviders emit"usage_total": null, and old persisted or RPC events may fail to deserialize. The updated roundtrip test only coversNone.Unverified Totals
New report line relies on
totalandturns, defined outside the visible diff. Confirmtotalsums every request per turn without double countingusage. Confirm the "in" figure (input + cache_read + cache_write) matches how the other stats lines compute input. Theclaude_clitest assertsinput_tokens == 2, but no test covers this report line.Persistent review updated to latest commit
0184627f27PR Code Suggestions ✨
No code suggestions found for the PR.
Pull request closed