Result from a completed query execution.
Maps to the Rust QueryResult -- the parsed JSON output from
--output-format json.
Summary
Functions
Parse a result from the JSON output of a query command.
The turn's stop reason (e.g. "end_turn", "max_tokens"), read from
extra["stop_reason"]. Returns nil when absent.
The schema-validated structured output, read from
extra["structured_output"].
Token usage for the turn, read from extra["usage"].
Types
@type t() :: %ClaudeWrapper.Result{ cost_usd: float() | nil, duration_ms: non_neg_integer() | nil, extra: map(), is_error: boolean(), num_turns: non_neg_integer() | nil, result: String.t(), session_id: String.t() | nil }
@type usage() :: %{ input: non_neg_integer(), output: non_neg_integer(), cache_creation: non_neg_integer(), cache_read: non_neg_integer(), total: non_neg_integer() }
Normalized token usage from usage/1. total is throughput
(input + output + cache_creation) and excludes cache reads.
Functions
Parse a result from the JSON output of a query command.
The turn's stop reason (e.g. "end_turn", "max_tokens"), read from
extra["stop_reason"]. Returns nil when absent.
The schema-validated structured output, read from
extra["structured_output"].
Present (a JSON object or array) when the turn ran with a JSON schema
(claude's --json-schema); nil otherwise.
Token usage for the turn, read from extra["usage"].
Returns nil when the result carries no usage (e.g. some error
results). total is input + output + cache_creation -- it excludes
cache reads, which re-count context already tallied when it was first
cached (consistent with ClaudeWrapper.History.SessionSummary's
total_tokens).
iex> ClaudeWrapper.Result.usage(%ClaudeWrapper.Result{result: "", extra: %{}})
nil