Skip to main content

Crate claude_code

Crate claude_code 

Source
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

FeatureDefaultDescription
streamYesEnables StreamEvent, streaming methods, and re-exports StreamExt.
structuredYesEnables generate_schema for JSON Schema generation.
tracingYesEnables debug/error/info logging via tracing.

Modules§

effort
Known values for the --effort CLI option.
permission_mode
Known values for the --permission-mode CLI option.

Structs§

ClaudeClient
Claude Code CLI client.
ClaudeConfig
Configuration options for Claude CLI execution.
ClaudeConfigBuilder
Builder for ClaudeConfig.
ClaudeResponse
JSON response from the Claude CLI.
Conversation
Stateful multi-turn conversation wrapper around ClaudeClient.
DefaultRunner
Runs claude via tokio::process::Command.
Usage
Token usage.

Enums§

ClaudeError
Error types for claude-code.
StreamEventstream
Event emitted from a stream-json response.

Traits§

CommandRunner
Trait abstracting CLI execution. Mockable in tests.
StreamExtstream
An extension trait for the Stream trait that provides a variety of convenient combinator functions.

Functions§

check_cli
Checks that the claude CLI is available and returns its version string.
generate_schemastructured
Generates a JSON Schema string from a type implementing JsonSchema.