Expand description
Core message types for Claude communication.
This module defines the primary message structures used in the Claude protocol:
ClaudeInput- Messages sent to ClaudeClaudeOutput- Messages received from ClaudeContentBlock- Different types of content within messages
§Message Flow
- Create a
ClaudeInputwith your query - Send it to Claude via a client
- Receive
ClaudeOutputmessages in response - Handle different output types (System, Assistant, Result)
§Example
use claude_codes::{ClaudeInput, ClaudeOutput};
// Create an input message
let input = ClaudeInput::user_message("Hello, Claude!", uuid::Uuid::new_v4());
// Parse an output message
let json = r#"{"type":"assistant","message":{"role":"assistant","content":[]}}"#;
match ClaudeOutput::parse_json(json) {
Ok(output) => println!("Got: {}", output.message_type()),
Err(e) => eprintln!("Parse error: {}", e),
}Structs§
- Anthropic
Error - API error message from Anthropic.
- Anthropic
Error Details - Details of an Anthropic API error.
- ApiRetry
Message - Assistant
Message - Assistant message
- Assistant
Message Content - Nested message content for assistant messages
- Assistant
Usage - Usage information for assistant messages
- Auth
Status Message - Background
Task Info - Background
Tasks Changed Message - Cache
Creation Details - Detailed cache creation information
- Citation
- A citation attached to a
TextBlock, linking generated text back to a source. - Code
Change Published Message code_change_publishedsystem message — the session is now associated with a published code change (a pull/merge request). Fires on creation and whenever the session contributes to an existing one, so bind on every event; re-emission for the same URL is possible and idempotent. Values are scraped from captured command output — treat them as a binding hint and verify against the forge before routing authenticated requests.- Code
Execution Tool Result Block - Result from server-side code execution.
- Command
Info - Command
Lifecycle Message command_lifecyclemessage — the fate of a queued command (slash command or queued user prompt):queuedwhen the inbound message enters the command queue,startedwhen it drains into a turn, then exactly one terminal state (completed,cancelled, ordiscarded). Commands enqueued without a client-supplied uuid emit no lifecycle events. Not a strict pairing — a terminal state may arrive for acommand_uuidthat never emittedstarted, and internally-enqueued commands skipqueued.- Commands
Changed Message - Compact
Boundary Message - Compact boundary message - marks where context compaction occurred
- Compact
Metadata - Metadata about context compaction
- Container
Upload Block - Container file upload content block.
- Control
Request - Control request from CLI (tool permission requests, hooks, etc.)
- Control
Request Message - Wrapper for outgoing control requests (includes type tag)
- Control
Request Progress Message - Control
Response - Control response to CLI
- Control
Response Message - Wrapper for outgoing control responses (includes type tag)
- Conversation
Reset Message - Deferred
Tool Use - Tool use deferred by a terminal result.
- Elicitation
Complete Message - Failed
Persisted File - Fallback
Block - Model fallback content block.
- Fallback
Model - A model reference inside a
FallbackBlock. - Files
Persisted Message - Frame
Audit - The result of auditing a single raw frame for full typed coverage.
- GetUsage
Response - Typed payload returned by the CLI
get_usagecontrol request. - Hook
Callback Request - Hook callback request
- Hook
Progress Message - Hook
Response Message - Hook
Started Message - Image
Block - Image content block (follows Anthropic API structure)
- Image
Source - Image source information
- Informational
Message - Init
Message - Init system message data - sent at session start
- Initialize
Request - Initialize request (SDK -> CLI)
- Local
Command Output Message - McpHttp
Server Config - MCP HTTP server configuration
- McpMessage
Request - MCP message request
- McpMeta
- MCP metadata passed through on user-message wrappers.
- McpServer
Error - An MCP server config entry that failed validation, reported by system
init (e.g. a
urlentry with notype). The affected server is skipped and absent fromInitMessage::mcp_servers. - McpSse
Server Config - MCP SSE server configuration
- McpStdio
Server Config - MCP stdio server configuration
- McpTool
Result Block - MCP tool result content block.
- McpTool
UseBlock - MCP tool invocation content block.
- Memory
Paths - Memory paths reported by system init.
- Memory
Recall Item - Memory
Recall Message - Message
Content - Message content with role
- Message
Origin - Message provenance. The
kindfield is the stable discriminator; variant specific fields are preserved inextrafor forward-compatible access. - Mirror
Error Key - Mirror
Error Message - Model
Refusal Fallback Message - Model
Refusal NoFallback Message - Model
Scoped Rate Limit - Model
Usage Entry - Usage and cost for a single model within a session, as found in
ResultMessage::model_usage. - Notification
Message - Overage
Period Utilization - Spend-cap utilization for an overage billing period.
- Parse
Error - Error type for parsing failures that preserves the raw input.
- Permission
- A permission to grant for “remember this decision” functionality.
- Permission
Denial - A record of a tool permission that was denied during the session.
- Permission
Denied Message - Permission
Rule - A rule within a permission grant.
- Permission
Suggestion - A suggested permission for tool approval.
- Persisted
File - Plugin
Diagnostic - Plugin load diagnostic reported by system init.
- Plugin
Info - Plugin info from the init message
- Plugin
Install Message - Preserved
Messages - Preserved
Segment - Prompt
Suggestion Message - Rate
Limit Event - Rate limit event from Claude CLI.
- Rate
Limit Info - Rate limit status information.
- Result
Message - Result message for completed queries
- Server
Tool Use - Server tool usage information
- Server
Tool UseBlock - Server-side tool use content block (e.g., web search, code execution).
- Session
State Changed Message - Status
Message - Status system message - sent during operations like context compaction
- Stream
Event Message - Subagent
Result - Token, timing, and tool-use accounting for a completed subagent (
Task) run. - Subagent
Retry - Retry state carried on a
ToolProgressMessagewhile a subagent API call is retried after an error. - Subagent
Tool Stats - Per-category tool-use counts for a subagent run, from
tool_use_result.toolStats. - Subagent
Usage Rollup - Session-level subagent token rollup — the
<subagent_tokens>/<agent_count>line items the Claude CLI renders in its terminal<usage>block. - Summarize
Metadata - Metadata attached when user-visible transcript content summarizes prior messages.
- System
Message - System message with metadata
- Task
Notification Message task_notificationsystem message — emitted once when a background task completes or fails.- Task
Patch - The partial update carried by a
TaskUpdatedMessage. Every field is optional because the CLI only sends the keys that changed. - Task
Progress Message task_progresssystem message — emitted periodically as a background agent task executes tools. Not emitted forlocal_bashtasks.- Task
Started Message task_startedsystem message — emitted once when a background task begins.- Task
Updated Message task_updatedsystem message — emitted when a background task’s state changes (e.g. transitions tocompleted). Carries a partialpatchof the fields that changed rather than the full task record.- Task
Usage - Cumulative usage statistics for a background task.
- Text
Block - Text content block
- Thinking
Block - Thinking content block
- Thinking
Tokens Message thinking_tokenssystem message — emitted as the model streams extended thinking, reporting the running estimate of thinking tokens consumed.- Tool
Caller - Provenance of a
ToolUseBlock— identifies who issued the tool call. - Tool
Permission Request - Tool permission request details
- Tool
Progress Message - Tool
Result Block - Tool result content block
- Tool
Result Meta - Display metadata for a
tool_resultblock carried on the user wrapper. - Tool
UseBlock - Tool use content block
- Tool
UseMeta - Display metadata for a tool-use block carried on the assistant wrapper.
- Tool
UseSummary Message - Transcript
Message - Raw preserved record for Claude Code transcript-only message types.
- Usage
Behavior - Usage
Behaviors - Usage
Info - Usage information for the request
- Usage
Model Usage - Usage
Rate Limit Window - Usage
Rate Limits - Usage
Session - User
Message - User message
- VcsState
Changed Message vcs_state_changedsystem message — a harness-observed shell command mutated repository state. A cache-invalidation signal, deliberately payload-free beyond classification: consumers re-read state (branch, head, PR status) instead of decoding the event.- WebSearch
Tool Result Block - Result from a web search server tool.
- Worker
Shutting Down Message
Enums§
- ApiError
Type - Known Anthropic API error types.
- ApiKey
Source - How the API key was sourced for the session.
- AskUser
Question Response Error - Errors that can occur when building an
AskUserQuestionresponse viaToolPermissionRequest::answer_questions. - Assistant
Error Kind - API error category attached to assistant wrapper frames.
- Claude
Input - Top-level enum for all possible Claude input messages.
- Claude
Output - Top-level enum for all possible Claude output messages
- Command
Lifecycle State - Lifecycle state carried by a
CommandLifecycleMessage. - Compaction
Trigger - What triggered a context compaction.
- Content
Block - Content blocks for messages
- Control
Request Payload - Control request payload variants
- Control
Response Payload - Control response payload
- Fast
Mode Disabled Reason - Why fast mode can’t serve right now, carried on
resultframes andsystem/init(CLI 2.1.219+). Absent when nothing blocks fast mode. - Image
Source Type - Encoding type for image source data.
- Init
Permission Mode - Permission mode reported in init messages.
- Known
System Event - Owned typed view over any known system message subtype.
- McpServer
Config - MCP Server configuration types
- Media
Type - MIME type for image content.
- Message
Role - Known message roles.
- Output
Style - Output formatting style for the session.
- Overage
Disabled Reason - Why overage billing is disabled.
- Overage
Status - Whether overage billing was accepted or rejected.
- Permission
Behavior - The behavior of a permission rule.
- Permission
Destination - Where a permission applies.
- Permission
Mode Name - Named permission modes that can be set via
setMode. - Permission
Result - Result of a permission decision
- Permission
Type - The type of a permission grant.
- Rate
Limit Error Code - Error code carried on a rate limit event when a request was refused.
- Rate
Limit Status - Current rate limit disposition.
- Rate
Limit Window - The time window a rate limit applies to.
- Result
Subtype - Result subtypes
- Status
Message Status - Status of an ongoing operation (e.g., context compaction).
- Stop
Reason - Reason why the assistant stopped generating.
- System
Subtype - Known system message subtypes.
- Task
Status - Completion status of a background task.
- Task
Type - The kind of background task.
- Tool
Result Content - Tool result content type
- VcsMutation
Kind - Mutation class carried by a
VcsStateChangedMessage.
Functions§
- assert_
fully_ wrapped - Panic with a detailed report unless
rawis fully wrapped. - audit_
frame - Audit a single raw frame (one parsed JSONL line) for full typed coverage.