claude-codes
A typed Rust interface for the Claude Code JSON protocol.
Part of the rust-code-agent-sdks workspace.
Overview
This library provides type-safe bindings for communicating with the Claude CLI via its JSON Lines protocol. It handles message serialization, streaming responses, and session management.
Note: The Claude CLI protocol is unstable and may change between versions. This crate tracks protocol changes and will warn if you're using an untested CLI version.
Installation
Default (All Features)
Requires the Claude CLI (claude binary) to be installed and available in PATH.
Feature Flags
| Feature | Description | WASM-compatible |
|---|---|---|
types |
Core message types only (minimal dependencies) | Yes |
sync-client |
Synchronous client with blocking I/O | No |
async-client |
Asynchronous client with tokio runtime | No |
All features are enabled by default.
Types Only (WASM-compatible)
[]
= { = "2", = false, = ["types"] }
This gives you access to all typed message structures (ClaudeInput, ClaudeOutput, ContentBlock, etc.) without pulling in tokio or other native-only dependencies. Useful for frontend apps, shared type definitions, or any WASM context needing Claude protocol types.
Sync Client Only
[]
= { = "2", = false, = ["sync-client"] }
Async Client Only
[]
= { = "2", = false, = ["async-client"] }
Usage
Async Client
use AsyncClient;
async
Sync Client
use ;
use Uuid;
Sending Images
use ;
use ;
async
Raw Protocol Access
use ;
let json_line = r#"{"type":"assistant","message":{...}}"#;
let output: ClaudeOutput = deserialize?;
let serialized = serialize?;
Compatibility
Tested against: Claude CLI 2.1.47
The crate version tracks the Claude CLI version. If you're using a different CLI version, please report whether it works at: https://github.com/meawoppl/rust-code-agent-sdks/issues
License
Apache-2.0. See LICENSE.