claudecode/lib.rs
1//! # ClaudeCode-RS
2//!
3//! A Rust SDK for programmatically interacting with Claude Code.
4//!
5//! ## Quick Start
6//!
7//! ```rust,no_run
8//! use claudecode::{Client, SessionConfig, Model, OutputFormat};
9//!
10//! #[tokio::main]
11//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
12//! // Create a client
13//! let client = Client::new().await?;
14//!
15//! // Simple query
16//! let config = SessionConfig::builder("Hello, Claude!")
17//! .model(Model::Sonnet)
18//! .build()?;
19//!
20//! let result = client.launch_and_wait(config).await?;
21//! println!("Claude says: {}", result.content.unwrap_or_default());
22//!
23//! Ok(())
24//! }
25//! ```
26//!
27//! ## Streaming Events
28//!
29//! ```rust,no_run
30//! use claudecode::{Client, SessionConfig, OutputFormat, Event};
31//! use futures::StreamExt;
32//!
33//! #[tokio::main]
34//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
35//! let client = Client::new().await?;
36//!
37//! let config = SessionConfig::builder("Tell me a story")
38//! .output_format(OutputFormat::StreamingJson)
39//! .build()?;
40//!
41//! let mut session = client.launch(config).await?;
42//!
43//! // Process streaming events with type-safe pattern matching
44//! if let Some(mut events) = session.take_event_stream() {
45//! while let Some(event) = events.recv().await {
46//! match event {
47//! Event::Assistant(msg) => {
48//! println!("Claude: {:?}", msg.message.content);
49//! }
50//! Event::Result(result) => {
51//! println!("Total cost: ${:?}", result.total_cost_usd);
52//! }
53//! _ => {}
54//! }
55//! }
56//! }
57//!
58//! let result = session.wait().await?;
59//! Ok(())
60//! }
61//! ```
62
63#[cfg(not(unix))]
64compile_error!(
65 "claudecode_rs only supports Unix-like platforms (Linux/macOS). Windows is not supported."
66);
67
68pub mod client;
69pub mod config;
70pub mod error;
71pub mod mcp;
72pub mod probe;
73pub mod process;
74pub mod session;
75pub mod stream;
76pub mod types;
77
78// Re-export main types
79pub use client::Client;
80pub use config::{MCPConfig, MCPServer, SessionConfig, SessionConfigBuilder};
81pub use error::{ClaudeError, Result};
82pub use probe::CliCapabilities;
83pub use session::Session;
84pub use types::{
85 AssistantEvent, Content, ErrorEvent, Event, InputFormat, MCPStatus, Message, Model,
86 OutputFormat, PermissionMode, Result as ClaudeResult, ResultEvent, ServerToolUse, SystemEvent,
87 Usage,
88};
89
90// Version information
91pub const VERSION: &str = env!("CARGO_PKG_VERSION");