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.
- Assistant
Message - Assistant message
- Assistant
Message Content - Nested message content for assistant messages
- Assistant
Usage - Usage information for assistant messages
- Cache
Creation Details - Detailed cache creation information
- Compact
Boundary Message - Compact boundary message - marks where context compaction occurred
- Compact
Metadata - Metadata about context compaction
- Control
Request - Control request from CLI (tool permission requests, hooks, etc.)
- Control
Request Message - Wrapper for outgoing control requests (includes type tag)
- Control
Response - Control response to CLI
- Control
Response Message - Wrapper for outgoing control responses (includes type tag)
- Hook
Callback Request - Hook callback request
- Image
Block - Image content block (follows Anthropic API structure)
- Image
Source - Image source information
- Init
Message - Init system message data - sent at session start
- Initialize
Request - Initialize request (SDK -> CLI)
- McpHttp
Server Config - MCP HTTP server configuration
- McpMessage
Request - MCP message request
- McpSse
Server Config - MCP SSE server configuration
- McpStdio
Server Config - MCP stdio server configuration
- Message
Content - Message content with role
- 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
Rule - A rule within a permission grant.
- Permission
Suggestion - A suggested permission for tool approval.
- Plugin
Info - Plugin info from the init 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
- Status
Message - Status system message - sent during operations like context compaction
- System
Message - System message with metadata
- Task
Notification Message task_notificationsystem message — emitted once when a background task completes or fails.- 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
Usage - Cumulative usage statistics for a background task.
- Text
Block - Text content block
- Thinking
Block - Thinking content block
- Tool
Permission Request - Tool permission request details
- Tool
Result Block - Tool result content block
- Tool
UseBlock - Tool use content block
- Usage
Info - Usage information for the request
- User
Message - User message
Enums§
- ApiError
Type - Known Anthropic API error types.
- ApiKey
Source - How the API key was sourced for the session.
- Claude
Input - Top-level enum for all possible Claude input messages
- Claude
Output - Top-level enum for all possible Claude output messages
- 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
- Image
Source Type - Encoding type for image source data.
- Init
Permission Mode - Permission mode reported in init messages.
- 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 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