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

+2 -2
View File
@@ -237,14 +237,14 @@ One JSON object per line on stdout. `type` is one of:
| type | fields |
|---|---|
| `session_start`, `turn_start`, `turn_end`, `agent_end` | none |
| `stream` | `event`: `{type: "text_delta", text}` · `{type: "thinking_delta", text}` · `{type: "tool_use_start", id, name}` · `{type: "done", message, stop, usage}` |
| `stream` | `event`: `{type: "text_delta", text}` · `{type: "thinking_delta", text}` · `{type: "tool_use_start", id, name}` · `{type: "done", message, stop, usage, usage_total?}` (`usage_total` only with `claude_cli`: sum over all requests of the run; `usage` there is the last request, the context size) |
| `message` | `message`: `{role, content: [{type: "text", text} \| {type: "tool_use", id, name, input} \| {type: "tool_result", tool_use_id, content, is_error}]}` |
| `tool_call` | `id`, `name`, `args` |
| `tool_result` | `id`, `name`, `args`, `content`, `is_error` (blocked calls: `is_error: true`, content `blocked: <reason>`) |
| `info` | `text` |
| `sub_usage` | `usage`: tokens spent by `task` subagents in the tools just run (already in the session total) |
| `injected` | `texts`: hook reports added to the conversation at turn end (lens diagnostics, affected tests) |
| `done` (last line) | `error` (null on success), `usage`, `session` |
| `done` (last line) | `error` (null on success), `usage`, `usage_total` (whole run; equals `usage` except with `claude_cli`), `session` |
### RPC (`hx --mode rpc`)