Expand description
Rust SDK for the Claude CLI.
This crate wraps the claude command-line tool, communicating via
newline-delimited JSON (NDJSON) over stdin/stdout using the
--input-format stream-json --output-format stream-json protocol.
§Quick start
use apiari_claude_sdk::{ClaudeClient, SessionOptions};
let client = ClaudeClient::new();
let mut session = client.spawn(SessionOptions {
model: Some("sonnet".into()),
allowed_tools: vec!["Bash".into(), "Read".into()],
..Default::default()
}).await?;
session.send_message("List files in the current directory").await?;
while let Some(event) = session.next_event().await? {
match event {
apiari_claude_sdk::Event::Assistant { message, tool_uses } => {
for block in &message.message.content {
if let apiari_claude_sdk::types::ContentBlock::Text { text } = block {
print!("{text}");
}
}
// Handle tool_uses if needed...
drop(tool_uses);
}
apiari_claude_sdk::Event::Result(result) => {
println!("\nDone! Session: {}", result.session_id);
break;
}
_ => {}
}
}Re-exports§
pub use client::ClaudeClient;pub use client::Event;pub use client::Session;pub use error::Result;pub use error::SdkError;pub use session::PermissionMode;pub use session::SessionOptions;pub use streaming::AssembledEvent;pub use streaming::StreamAssembler;pub use tools::ToolResult;pub use tools::ToolUse;pub use types::AssistantMessage;pub use types::AssistantMessageContent;pub use types::ContentBlock;pub use types::InputMessage;pub use types::Message;pub use types::RateLimitEvent;pub use types::ResultMessage;pub use types::StreamEvent;pub use types::SystemMessage;pub use types::UserMessage;
Modules§
- client
- High-level client for spawning and interacting with Claude sessions.
- error
- SDK error types.
- session
- Session configuration and CLI argument building.
- streaming
- Partial event assembly for streaming responses.
- tools
- Tool use request/result protocol types.
- transport
- NDJSON stdin/stdout transport over a subprocess.
- types
- All message types from the Claude CLI stream-json protocol.