# `ClaudeWrapper.Result`
[🔗](https://github.com/genagent/claude_wrapper_ex/blob/main/lib/claude_wrapper/result.ex#L1)

Result from a completed query execution.

Maps to the Rust `QueryResult` -- the parsed JSON output from
`--output-format json`.

# `t`

```elixir
@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
}
```

# `usage`

```elixir
@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.

# `from_json`

```elixir
@spec from_json(map()) :: t()
```

Parse a result from the JSON output of a query command.

# `stop_reason`

```elixir
@spec stop_reason(t()) :: String.t() | nil
```

The turn's stop reason (e.g. `"end_turn"`, `"max_tokens"`), read from
`extra["stop_reason"]`. Returns `nil` when absent.

# `structured_output`

```elixir
@spec structured_output(t()) :: map() | list() | nil
```

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.

# `usage`

```elixir
@spec usage(t()) :: usage() | nil
```

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
