ClaudeCode.Content (ClaudeCode v0.36.3)
View SourceUtilities for working with content blocks in Claude messages.
Content blocks can be text, thinking, tool use requests, tool results, server tool invocations, MCP tool interactions, or compaction summaries. This module provides functions to parse and work with any content type.
Summary
Functions
Checks if a value is any type of content block.
Returns the type of a content block.
Parses a content block delta from a stream event into a typed map.
Types
@type delta() :: %{type: :text_delta, text: String.t()} | %{type: :input_json_delta, partial_json: String.t()} | %{type: :thinking_delta, thinking: String.t()} | %{type: :signature_delta, signature: String.t()} | %{type: :citations_delta, citation: map()} | %{type: :compaction_delta, content: String.t() | nil}
@type t() :: ClaudeCode.Content.TextBlock.t() | ClaudeCode.Content.ThinkingBlock.t() | ClaudeCode.Content.RedactedThinkingBlock.t() | ClaudeCode.Content.ToolUseBlock.t() | ClaudeCode.Content.ToolResultBlock.t() | ClaudeCode.Content.ServerToolUseBlock.t() | ClaudeCode.Content.ServerToolResultBlock.t() | ClaudeCode.Content.MCPToolUseBlock.t() | ClaudeCode.Content.MCPToolResultBlock.t() | ClaudeCode.Content.ImageBlock.t() | ClaudeCode.Content.DocumentBlock.t() | ClaudeCode.Content.ContainerUploadBlock.t() | ClaudeCode.Content.CompactionBlock.t()
Functions
Checks if a value is any type of content block.
@spec content_type(t()) :: :text | :thinking | :redacted_thinking | :tool_use | :tool_result | :server_tool_use | ClaudeCode.Content.ServerToolResultBlock.server_tool_result_type() | :mcp_tool_use | :mcp_tool_result | :image | :document | :container_upload | :compaction
Returns the type of a content block.
Parses a content block delta from a stream event into a typed map.
Examples
iex> ClaudeCode.Content.parse_delta(%{"type" => "text_delta", "text" => "Hi"})
{:ok, %{type: :text_delta, text: "Hi"}}
iex> ClaudeCode.Content.parse_delta(%{"type" => "future_delta"})
{:error, {:unknown_delta_type, "future_delta"}}