claude-codes
A tightly typed Rust interface for the Claude Code JSON protocol.
⚠️ Important Notice: Unstable Interface
This crate provides bindings for the Claude Code CLI, which is currently an unstable and rapidly evolving interface. The underlying protocol and message formats may change without notice between Claude CLI versions.
Features
- Type-safe message encoding/decoding
- JSON Lines protocol support
- Async and sync I/O support
- Comprehensive error handling
- Stream processing utilities
- Automatic Claude CLI version compatibility checking
- Test-driven protocol discovery for handling new message types
Installation
Usage
Async Client
use AsyncClient;
async
Sync Client
use ;
Working with Raw Protocol
use ;
// Deserialize a JSON Lines message
let json_line = r#"{"type":"assistant","message":{...}}"#;
let output: ClaudeOutput = deserialize?;
// Serialize for sending
let serialized = serialize?;
Compatibility Reporting
-
Current tested version: Claude CLI 1.0.89
-
Compatibility reports needed: If you're using this crate with a different version of Claude CLI (whether it works or fails), please report your experience at:
When creating a compatibility report, please include:
- Your Claude CLI version (run
claude --version) - Whether the crate worked correctly or what errors you encountered
- Any message types that failed to deserialize
The crate will automatically warn you if you're using a newer Claude CLI version than what has been tested. You can work around version checks if needed (see documentation), but please report your results to help the community!
License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed under the Apache-2.0 license, without any additional terms or conditions.