claude-wrapper
A type-safe Claude Code CLI wrapper for Rust.
claude-wrapper provides a builder-pattern interface for invoking the claude CLI programmatically. Same design philosophy as docker-wrapper and terraform-wrapper: each CLI subcommand is a builder struct that produces typed output.
Quick Start
use ;
async
Design
Two-layer builder pattern:
Claudeclient - shared config (binary path, env vars, timeouts)- Command builders - per-subcommand options,
execute(&claude)returns typed output
The CLAUDECODE environment variable is automatically removed when spawning processes, preventing the "cannot be launched inside another Claude Code session" error.
Commands
QueryCommand
The primary command. Wraps claude -p (print mode) with all options:
let output = new
.model
.system_prompt
.output_format
.max_budget_usd
.permission_mode
.allowed_tools
.mcp_config
.effort
.max_turns
.no_session_persistence
.execute
.await?;
With structured JSON output:
let result = new
.execute_json
.await?;
println!;
println!;
println!;
Full option coverage:
| Method | CLI Flag | Description |
|---|---|---|
model() |
--model |
Model alias or full ID |
system_prompt() |
--system-prompt |
Replace default system prompt |
append_system_prompt() |
--append-system-prompt |
Append to default system prompt |
output_format() |
--output-format |
text, json, stream-json |
max_budget_usd() |
--max-budget-usd |
Spending cap |
permission_mode() |
--permission-mode |
default, acceptEdits, bypassPermissions, plan, auto |
allowed_tools() / allowed_tool() |
--allowed-tools |
Tool permission allow list |
disallowed_tools() |
--disallowed-tools |
Tool permission deny list |
tools() |
--tools |
Restrict available built-in tools |
mcp_config() |
--mcp-config |
MCP server config file path |
strict_mcp_config() |
--strict-mcp-config |
Only use MCP from --mcp-config |
add_dir() |
--add-dir |
Additional directories for tool access |
effort() |
--effort |
low, medium, high |
max_turns() |
--max-turns |
Maximum conversation turns |
json_schema() |
--json-schema |
Structured output validation |
agent() |
--agent |
Agent for the session |
agents_json() |
--agents |
Custom agents JSON definition |
continue_session() |
--continue |
Continue most recent conversation |
resume() |
--resume |
Resume by session ID |
session_id() |
--session-id |
Use specific session ID |
fork_session() |
--fork-session |
Fork when resuming |
fallback_model() |
--fallback-model |
Fallback when primary is overloaded |
no_session_persistence() |
--no-session-persistence |
Don't save session to disk |
dangerously_skip_permissions() |
--dangerously-skip-permissions |
Bypass permissions (sandbox only) |
file() |
--file |
File resources to download |
input_format() |
--input-format |
text or stream-json |
include_partial_messages() |
--include-partial-messages |
Partial chunks in stream-json |
settings() |
--settings |
Path to settings JSON |
MCP Commands
// List servers
let output = new.execute.await?;
// Get server details
let output = new.execute.await?;
// Add HTTP server
new
.transport
.scope
.execute.await?;
// Add stdio server with env vars
new
.server_args
.env
.execute.await?;
// Add from raw JSON
new
.scope
.execute.await?;
// Remove
new
.scope
.execute.await?;
MCP Config Builder
Generate .mcp.json files programmatically:
use McpConfigBuilder;
let path = new
.http_server
.stdio_server
.stdio_server_with_env
.write_to?;
Other Commands
// Version
let output = new.execute.await?;
// Auth status
let status = new.execute_json.await?;
assert!;
// Doctor (health check)
let output = new.execute.await?;
// Raw escape hatch
let output = new
.arg
.arg
.execute.await?;
Streaming
For --output-format stream-json with real-time event processing:
use ;
let cmd = new
.output_format;
let output = stream_query.await?;
Features
| Feature | Default | Description |
|---|---|---|
json |
Yes | JSON output parsing, execute_json(), McpConfigBuilder, streaming events |
Status
This is an early-stage spike. The API is functional but may change.
Implemented
Claudeclient builder (binary, working dir, env, timeout, global args)ClaudeCommandtraitQueryCommandwith full-poption coverage (28 options)McpListCommand,McpGetCommand,McpAddCommand,McpAddJsonCommand,McpRemoveCommand,McpAddFromDesktopCommand,McpResetProjectChoicesCommandPluginListCommand,PluginInstallCommand,PluginUninstallCommand,PluginEnableCommand,PluginDisableCommand,PluginUpdateCommand,PluginValidateCommandMarketplaceListCommand,MarketplaceAddCommand,MarketplaceRemoveCommand,MarketplaceUpdateCommandAgentsCommandAuthStatusCommandwithexecute_json()DoctorCommand,VersionCommandRawCommandescape hatchMcpConfigBuilderfor generating.mcp.jsonfilesstream_query()for streaming NDJSON output- Automatic
CLAUDECODEenv var removal - Working directory support (
Claude::builder().working_dir()andclaude.with_working_dir())
Not Yet Implemented
- Retry/backoff policies
- Process lifecycle management (restart loops for agent patterns)
License
MIT OR Apache-2.0