Crates.io | claude-codes |
lib.rs | claude-codes |
version | 0.2.1 |
created_at | 2025-08-23 16:16:47.028604+00 |
updated_at | 2025-08-28 19:54:44.467428+00 |
description | A tightly typed Rust interface for the Claude Code JSON protocol |
homepage | https://github.com/meawoppl/rust-claude-codes |
repository | https://github.com/meawoppl/rust-claude-codes |
max_upload_size | |
id | 1807650 |
size | 233,446 |
A tightly typed Rust interface for the Claude Code JSON protocol - unleashing the full power of Claude's capabilities in your Rust applications!
Claude Code represents a paradigm shift in how we interact with AI assistants programmatically. This library brings that same revolutionary experience to Rust developers, providing complete, type-safe access to Claude's extensive feature set. No more wrestling with raw JSON or hoping your messages are formatted correctly - we've done the heavy lifting so you can focus on building amazing things!
This isn't just another API wrapper. We've meticulously reverse-engineered and documented the Claude Code protocol through extensive testing, capturing real-world message flows and ensuring every feature works exactly as expected. The result? You get the same powerful capabilities that Claude Code uses internally, now available in your Rust applications with zero compromises.
This crate provides bindings for the Claude Code CLI, which is currently an unstable and rapidly evolving interface. But here's the exciting part: we're evolving right alongside it! Our test-driven approach means we catch protocol changes quickly and adapt, ensuring you're always working with the latest capabilities.
With claude-codes
, you have the power to:
The possibilities are limited only by your imagination!
cargo add claude-codes
use claude_codes::AsyncClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client (checks Claude CLI compatibility)
let mut client = AsyncClient::with_defaults().await?;
// Send a query and stream responses
let mut stream = client.query_stream("What is 2 + 2?").await?;
while let Some(response) = stream.next().await {
match response {
Ok(output) => println!("Got: {}", output.message_type()),
Err(e) => eprintln!("Error: {}", e),
}
}
Ok(())
}
use claude_codes::{SyncClient, ClaudeInput};
use uuid::Uuid;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client (checks Claude CLI compatibility)
let mut client = SyncClient::with_defaults()?;
// Send a query
let input = ClaudeInput::user_message("What is 2 + 2?", Uuid::new_v4());
let responses = client.query(input)?;
for response in responses {
println!("Got: {}", response.message_type());
}
Ok(())
}
use claude_codes::{AsyncClient, ClaudeInput};
use base64::{engine::general_purpose::STANDARD, Engine};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = AsyncClient::with_defaults().await?;
// Read and encode an image
let image_data = std::fs::read("my_diagram.png")?;
let base64_image = STANDARD.encode(&image_data);
// Send image with a question
let input = ClaudeInput::user_message_with_image(
base64_image,
"image/png".to_string(),
Some("What's shown in this diagram?".to_string()),
uuid::Uuid::new_v4(),
)?;
// Get Claude's analysis
client.send(&input).await?;
// ... process responses
Ok(())
}
use claude_codes::{Protocol, ClaudeOutput};
// Deserialize a JSON Lines message
let json_line = r#"{"type":"assistant","message":{...}}"#;
let output: ClaudeOutput = Protocol::deserialize(json_line)?;
// Serialize for sending
let serialized = Protocol::serialize(&output)?;
This library is already empowering developers to build incredible things:
Imagine a Rust analyzer that not only catches syntax errors but understands your intent. With claude-codes
, you can build tools that review PRs, suggest optimizations, and even explain complex code patterns - all with Claude's deep understanding.
Process thousands of images and documents with intelligent analysis. Whether you're building a content moderation system, a document classifier, or an accessibility tool that describes images, Claude's multimodal capabilities are now at your fingertips.
Create educational tools that adapt to users' understanding levels. Claude can explain concepts, answer questions, and provide personalized feedback - all through your Rust application's type-safe interface.
Rust's zero-cost abstractions and Claude's powerful AI create an unbeatable combination. Process millions of tokens without breaking a sweat, stream responses in real-time, and handle concurrent sessions with confidence.
Our strongly-typed interface catches errors at compile time, not runtime. No more debugging mysterious JSON parsing errors at 3 AM. The compiler is your friend, and we've made sure it knows exactly what Claude expects.
Built with the same attention to detail that makes Rust perfect for systems programming. Proper error handling, resource cleanup, and memory safety mean your Claude-powered applications can run 24/7 without surprises.
npm install -g @anthropic-ai/claude-cli
cargo add claude-codes
We're not just maintaining a library - we're building a movement of developers who believe AI should be accessible, type-safe, and powerful. Every contribution, bug report, and feature request helps make this vision a reality.
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:
claude --version
)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!
We believe that AI should amplify human capability, not replace it. By providing Rust developers with first-class access to Claude's capabilities, we're enabling a future where AI and systems programming work hand-in-hand to solve problems we couldn't tackle alone.
Every line of code in this library represents our commitment to that vision: making AI accessible, type-safe, and incredibly powerful for the Rust community.
This is just the beginning. As Claude's capabilities expand and the protocol evolves, we'll be right there - documenting, testing, and providing rock-solid Rust bindings for every new feature. Together, we're not just keeping up with the AI revolution - we're helping to shape it.
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
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.
Built with โค๏ธ by developers who believe in the power of type-safe AI
Special thanks to the Claude team for creating such an incredible AI assistant, and to the Rust community for being awesome.