ClaudeCode.Message.Result (ClaudeCode v0.1.0)

View Source

Represents a result message from the Claude CLI.

Result messages are the final message in a conversation, containing the final response, timing information, token usage, and cost.

Matches the official SDK schema for successful results:

{
  type: "result",
  subtype: "success",
  duration_ms: float,
  duration_api_ms: float,
  is_error: boolean,
  num_turns: int,
  result: string,
  session_id: string,
  total_cost_usd: float
}

And for error results:

{
  type: "result",
  subtype: "error_max_turns" | "error_during_execution",
  duration_ms: float,
  duration_api_ms: float,
  is_error: boolean,
  num_turns: int,
  session_id: string,
  total_cost_usd: float
}

Summary

Functions

Creates a new Result message from JSON data.

Type guard to check if a value is a Result message.

Types

t()

@type t() :: %ClaudeCode.Message.Result{
  duration_api_ms: float(),
  duration_ms: float(),
  is_error: boolean(),
  num_turns: non_neg_integer(),
  result: String.t(),
  session_id: ClaudeCode.Types.session_id(),
  subtype: ClaudeCode.Types.result_subtype(),
  total_cost_usd: float(),
  type: :result,
  usage: ClaudeCode.Types.usage()
}

Functions

new(json)

@spec new(map()) :: {:ok, t()} | {:error, atom() | {:missing_fields, [atom()]}}

Creates a new Result message from JSON data.

Examples

iex> Result.new(%{"type" => "result", "subtype" => "success", ...})
{:ok, %Result{...}}

iex> Result.new(%{"type" => "assistant"})
{:error, :invalid_message_type}

result_message?(arg1)

@spec result_message?(any()) :: boolean()

Type guard to check if a value is a Result message.