claude_cli: add usage_total for the whole run (#190)

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>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-21 12:24:11 +01:00
1 parent 0545702fe0
commit 32ae759703
13 files changed
+80 -10

No files matched your search

+1 -1
View File
@@ -1333,7 +1333,7 @@ async fn main() -> Result<()> {
if cli.mode == Mode::Json {
rpc::emit(
&serde_json::json!({"type": "done", "error": r.as_ref().err().map(|e| e.to_string()),
"usage": agent.usage(), "session": path}),
"usage": agent.usage(), "usage_total": agent.usage_total(), "session": path}),
);
}
let u = &agent.usage();
+2 -1
View File
@@ -114,7 +114,7 @@ pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()>
busy.store(false, std::sync::atomic::Ordering::SeqCst);
reply(
&id,
r.map(|m| json!({"message": m, "usage": a.usage()}))
r.map(|m| json!({"message": m, "usage": a.usage(), "usage_total": a.usage_total()}))
.map_err(|e| e.to_string()),
);
}));
@@ -130,6 +130,7 @@ pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()>
"model": a.model(), "session": a.session().path(), "head": a.session().head(),
"title": hx_core::session::title(&a.session().messages()),
"messages": a.session().messages().len(), "usage": a.usage(),
"usage_total": a.usage_total(),
"tools": a.tools.specs().into_iter().map(|t| t.name).collect::<Vec<_>>(),
})),
"messages" => Ok(json!(a.session().messages())),