Expand description
§claude-code
Unofficial Rust client for the Claude Code CLI.
This crate runs claude --print as a subprocess and provides type-safe access to the results.
It supports single-shot JSON responses, real-time streaming via stream-json, multi-turn
conversations, and structured output with JSON Schema.
§Quick Start
let client = claude_code::ClaudeClient::new(claude_code::ClaudeConfig::default());
let response = client.ask("Say hello").await?;
println!("{}", response.result);§Feature Flags
| Feature | Default | Description |
|---|---|---|
stream | Yes | Enables StreamEvent, streaming methods, and re-exports StreamExt. |
structured | Yes | Enables generate_schema for JSON Schema generation. |
tracing | Yes | Enables debug/error/info logging via tracing. |
Modules§
- effort
- Known values for the
--effortCLI option. - permission_
mode - Known values for the
--permission-modeCLI option.
Structs§
- Claude
Client - Claude Code CLI client.
- Claude
Config - Configuration options for Claude CLI execution.
- Claude
Config Builder - Builder for
ClaudeConfig. - Claude
Response - JSON response from the Claude CLI.
- Conversation
- Stateful multi-turn conversation wrapper around
ClaudeClient. - Default
Runner - Runs
claudeviatokio::process::Command. - Usage
- Token usage.
Enums§
- Claude
Error - Error types for claude-code.
- CliVersion
Status - Result of comparing the installed CLI version against
TESTED_CLI_VERSION. - Preset
- Preset defines the base set of CLI flags injected before
builder attributes and
extra_args. - Stream
Event stream - Event emitted from a stream-json response.
Constants§
- TESTED_
CLI_ VERSION - The Claude Code CLI version that this library was tested against.
Traits§
- Command
Runner - Trait abstracting CLI execution. Mockable in tests.
- Stream
Ext stream - An extension trait for the
Streamtrait that provides a variety of convenient combinator functions.
Functions§
- check_
cli - Checks that the
claudeCLI is available and returns its version string. - check_
cli_ version - Checks the installed
claudeCLI version againstTESTED_CLI_VERSION. - check_
cli_ version_ with_ path - Checks the CLI at the given path against
TESTED_CLI_VERSION. - check_
cli_ with_ path - Checks that the CLI at the given path is available and returns its version string.
- generate_
schema structured - Generates a JSON Schema string from a type implementing
JsonSchema.