apiari-claude-sdk
Rust SDK for the Claude Code CLI. Spawns the claude binary as a subprocess and communicates via newline-delimited JSON (NDJSON) over stdin/stdout.
This is not a direct API client — the CLI handles authentication, tool execution, and permissions. The SDK provides typed Rust bindings over the streaming protocol.
How It Works
The SDK spawns claude with the streaming JSON protocol:
claude --print --output-format stream-json --input-format stream-json --verbose
It writes InputMessage objects (user text or tool results) to stdin and reads structured events from stdout. The CLAUDECODE env var is removed from the subprocess to prevent nested session blocking.
Key types: ClaudeClient (session factory), Session (live handle), Event (system/assistant/result/stream), ToolUse / ToolResult (tool protocol), SessionOptions (all CLI flags), StreamAssembler (partial message reassembly).
Quick Start
use ;
async
Features
- Spawn and manage multi-turn Claude CLI sessions
- Typed event stream:
System,Assistant,Result,Stream,RateLimit - Tool use/result protocol for custom tool handling
- Session resume, continue, and fork
- Stream assembler for partial/incremental message events
- Interrupt (
SIGINT) and graceful shutdown - Full
SessionOptionscovering all CLI flags
Requirements
The claude CLI must be installed and on $PATH, or provide a custom path via ClaudeClient::with_cli_path.