ClaudeCode.Message.UserMessage (ClaudeCode v0.36.3)

View Source

Represents a user message from the Claude CLI.

User messages typically contain tool results in response to Claude's tool use requests.

Matches the official SDK schema:

{
  type: "user",
  uuid?: string,
  message: MessageParam,  # from Anthropic SDK
  session_id: string,
  parent_tool_use_id?: string | null,
  tool_use_result?: object | null,  # Rich metadata about the tool result
  isSynthetic: boolean,             # Whether this is a synthetic message
  isReplay: boolean                 # Whether this is a replayed message
}

Summary

Functions

Creates a new UserMessage from JSON data.

Types

message_content()

@type message_content() :: String.t() | [ClaudeCode.Content.t()]

message_param()

@type message_param() :: %{
  content: message_content(),
  role: ClaudeCode.Message.role()
}

t()

@type t() :: %ClaudeCode.Message.UserMessage{
  is_replay: boolean(),
  is_synthetic: boolean(),
  message: message_param(),
  parent_tool_use_id: String.t() | nil,
  session_id: String.t(),
  tool_use_result: map() | String.t() | nil,
  type: :user,
  uuid: String.t() | nil
}

Functions

new(json)

@spec new(map()) :: {:ok, t()} | {:error, atom() | tuple()}

Creates a new UserMessage from JSON data.

Examples

iex> UserMessage.new(%{"type" => "user", "message" => %{...}})
{:ok, %UserMessage{...}}

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