ClaudeCode.Message (ClaudeCode v0.1.0)
View SourceUtilities for working with messages from the Claude CLI.
Messages can be system initialization, assistant responses, user tool results, or final result messages. This module provides functions to parse and work with any message type.
Summary
Functions
Checks if a value is any type of message.
Returns the type of a message.
Parses a message from JSON data based on its type.
Parses a list of messages.
Parses a newline-delimited JSON stream from the CLI.
Types
@type t() :: ClaudeCode.Message.System.t() | ClaudeCode.Message.Assistant.t() | ClaudeCode.Message.User.t() | ClaudeCode.Message.Result.t()
Functions
Checks if a value is any type of message.
@spec message_type(t()) :: :system | :assistant | :user | :result
Returns the type of a message.
Parses a message from JSON data based on its type.
Examples
iex> Message.parse(%{"type" => "system", ...})
{:ok, %System{...}}
iex> Message.parse(%{"type" => "unknown"})
{:error, {:unknown_message_type, "unknown"}}
Parses a list of messages.
Returns {:ok, messages} if all messages parse successfully, or {:error, {:parse_error, index, error}} for the first failure.
Parses a newline-delimited JSON stream from the CLI.
This is the format output by the CLI with --output-format stream-json.