claude_code/lib.rs
1//! # claude-code
2//!
3//! **Unofficial** Rust client for the [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code).
4//!
5//! This crate runs `claude --print` as a subprocess and provides type-safe access to the results.
6//! It supports single-shot JSON responses, real-time streaming via `stream-json`, multi-turn
7//! conversations, and structured output with JSON Schema.
8//!
9//! ## Quick Start
10//!
11//! ```rust,no_run
12//! # #[tokio::main]
13//! # async fn main() -> Result<(), claude_code::ClaudeError> {
14//! let client = claude_code::ClaudeClient::new(claude_code::ClaudeConfig::default());
15//! let response = client.ask("Say hello").await?;
16//! println!("{}", response.result);
17//! # Ok(())
18//! # }
19//! ```
20//!
21//! ## Feature Flags
22//!
23//! | Feature | Default | Description |
24//! |---|---|---|
25//! | `stream` | Yes | Enables [`StreamEvent`], streaming methods, and re-exports [`StreamExt`]. |
26//! | `structured` | Yes | Enables [`generate_schema`] for JSON Schema generation. |
27//! | `tracing` | Yes | Enables debug/error/info logging via `tracing`. |
28
29#![cfg_attr(docsrs, feature(doc_cfg))]
30#![warn(missing_docs)]
31
32/// The Claude Code CLI version that this library was tested against.
33///
34/// This does not guarantee compatibility with this exact version only;
35/// it indicates the version used during development and testing.
36/// Older or newer CLI versions may work but have not been verified.
37pub const TESTED_CLI_VERSION: &str = "2.1.94";
38
39mod client;
40mod config;
41mod conversation;
42mod error;
43#[cfg(feature = "stream")]
44mod stream;
45#[cfg(feature = "structured")]
46mod structured;
47mod types;
48
49pub use client::{
50 ClaudeClient, CliVersionStatus, CommandRunner, DefaultRunner, check_cli, check_cli_version,
51 check_cli_version_with_path, check_cli_with_path,
52};
53pub use config::{ClaudeConfig, ClaudeConfigBuilder, Preset, effort, permission_mode};
54pub use conversation::Conversation;
55pub use error::ClaudeError;
56#[cfg(feature = "stream")]
57#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
58pub use stream::StreamEvent;
59#[cfg(feature = "structured")]
60#[cfg_attr(docsrs, doc(cfg(feature = "structured")))]
61pub use structured::generate_schema;
62#[cfg(feature = "stream")]
63#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
64pub use tokio_stream::StreamExt;
65pub use types::{ClaudeResponse, Usage};