Skip to main content

ClaudeCliBuilder

Struct ClaudeCliBuilder 

Source
pub struct ClaudeCliBuilder { /* private fields */ }
Expand description

Builder for creating Claude CLI commands in JSON streaming mode

This builder automatically configures Claude to use:

  • --print mode for non-interactive operation
  • --output-format stream-json for streaming JSON responses
  • --input-format stream-json for JSON input
  • --replay-user-messages to echo back user messages

Implementations§

Source§

impl ClaudeCliBuilder

Source

pub fn new() -> Self

Create a new Claude CLI builder with JSON streaming mode pre-configured

Source

pub fn command<P: Into<PathBuf>>(self, path: P) -> Self

Set custom path to Claude binary

Source

pub fn prompt<S: Into<String>>(self, prompt: S) -> Self

Set the prompt for Claude

Source

pub fn debug<S: Into<String>>(self, filter: Option<S>) -> Self

Enable debug mode with optional filter

Source

pub fn verbose(self, verbose: bool) -> Self

Enable verbose mode

Source

pub fn dangerously_skip_permissions(self, skip: bool) -> Self

Skip all permission checks (dangerous!)

Source

pub fn allowed_tools<I, S>(self, tools: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add allowed tools

Source

pub fn disallowed_tools<I, S>(self, tools: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add disallowed tools

Source

pub fn mcp_config<I, S>(self, configs: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add MCP configuration

Source

pub fn append_system_prompt<S: Into<String>>(self, prompt: S) -> Self

Append a system prompt

Source

pub fn permission_mode(self, mode: PermissionMode) -> Self

Set permission mode

Source

pub fn continue_conversation(self, continue_conv: bool) -> Self

Continue the most recent conversation

Source

pub fn resume<S: Into<String>>(self, session_id: Option<S>) -> Self

Resume a specific conversation

Source

pub fn model<S: Into<String>>(self, model: S) -> Self

Set the model to use

Source

pub fn fallback_model<S: Into<String>>(self, model: S) -> Self

Set fallback model for overload situations

Source

pub fn settings<S: Into<String>>(self, settings: S) -> Self

Load settings from file or JSON

Source

pub fn add_directories<I, P>(self, dirs: I) -> Self
where I: IntoIterator<Item = P>, P: Into<PathBuf>,

Add directories for tool access

Source

pub fn ide(self, ide: bool) -> Self

Automatically connect to IDE

Source

pub fn strict_mcp_config(self, strict: bool) -> Self

Use only MCP servers from config

Source

pub fn session_id(self, id: Uuid) -> Self

Set a specific session ID (must be a UUID)

Source

pub fn oauth_token<S: Into<String>>(self, token: S) -> Self

Set OAuth token for authentication (must start with “sk-ant-oat”)

Source

pub fn api_key<S: Into<String>>(self, key: S) -> Self

Set API key for authentication (must start with “sk-ant-api”)

Source

pub fn permission_prompt_tool<S: Into<String>>(self, tool: S) -> Self

Enable bidirectional tool permission protocol via stdio

When enabled, Claude CLI will send permission requests via stdout and expect responses via stdin. Use “stdio” for standard I/O based permission handling.

§Example
use claude_codes::ClaudeCliBuilder;

let builder = ClaudeCliBuilder::new()
    .permission_prompt_tool("stdio")
    .model("sonnet");
Source

pub async fn spawn(self) -> Result<Child>

Spawn the Claude process

Source

pub fn build_command(self) -> Command

Build a Command without spawning (for testing or manual execution)

Source

pub fn spawn_sync(self) -> Result<Child>

Spawn the Claude process using synchronous std::process

Trait Implementations§

Source§

impl Clone for ClaudeCliBuilder

Source§

fn clone(&self) -> ClaudeCliBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClaudeCliBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClaudeCliBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.