ClaudeCode.Message.PartialAssistantMessage (ClaudeCode v0.36.3)
View SourceRepresents a partial assistant message from the Claude CLI when using partial message streaming.
Partial assistant messages are emitted when include_partial_messages: true is enabled.
They provide real-time updates as Claude generates responses, enabling
character-by-character streaming for LiveView applications.
This type corresponds to SDKPartialAssistantMessage in the TypeScript SDK.
Event Types
message_start- Signals the beginning of a new messagecontent_block_start- Signals the beginning of a new content block (text or tool_use)content_block_delta- Contains incremental content updates (text chunks, tool input JSON, signatures, citations)content_block_stop- Signals the end of a content blockmessage_delta- Contains message-level updates (stop_reason, usage)message_stop- Signals the end of the message
Example Usage
ClaudeCode.query_stream(session, "Hello", include_partial_messages: true)
|> ClaudeCode.Stream.text_deltas()
|> Enum.each(&IO.write/1)JSON Format
{
"type": "stream_event",
"event": {
"type": "content_block_delta",
"index": 0,
"delta": {"type": "text_delta", "text": "Hello"}
},
"session_id": "...",
"parent_tool_use_id": null,
"uuid": "..."
}
Summary
Functions
Extracts text from a text_delta in a single match.
Extracts thinking from a thinking_delta in a single match.
Creates a new PartialAssistantMessage from JSON data.
Checks if this partial message is a text delta.
Types
@type event() :: %{type: event_type()} | %{ type: :content_block_start, index: non_neg_integer(), content_block: ClaudeCode.Content.t() } | %{ type: :content_block_delta, index: non_neg_integer(), delta: ClaudeCode.Content.delta() } | %{type: :content_block_stop, index: non_neg_integer()} | %{ type: :message_start, message: ClaudeCode.Message.AssistantMessage.message() } | %{ type: :message_delta, delta: ClaudeCode.Message.delta() | nil, usage: ClaudeCode.Usage.t() } | %{type: :message_stop}
@type event_type() ::
:message_start
| :content_block_start
| :content_block_delta
| :content_block_stop
| :message_delta
| :message_stop
Functions
Extracts text from a text_delta in a single match.
Returns {:ok, text} for text deltas, :error otherwise.
Extracts thinking from a thinking_delta in a single match.
Returns {:ok, thinking} for thinking deltas, :error otherwise.
Creates a new PartialAssistantMessage from JSON data.
Examples
iex> PartialAssistantMessage.new(%{
...> "type" => "stream_event",
...> "event" => %{"type" => "content_block_delta", "index" => 0, "delta" => %{"type" => "text_delta", "text" => "Hi"}},
...> "session_id" => "abc123"
...> })
{:ok, %PartialAssistantMessage{type: :stream_event, event: %{type: :content_block_delta, ...}, ...}}
Checks if this partial message is a text delta.