ClaudeCodeOptionsBuilder

Struct ClaudeCodeOptionsBuilder 

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

Builder for ClaudeCodeOptions

Implementations§

Source§

impl ClaudeCodeOptionsBuilder

Source

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

Set system prompt

Source

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

Set append system prompt

Source

pub fn allowed_tools(self, tools: Vec<String>) -> Self

Set allowed tools (auto-approval permissions only)

IMPORTANT: This only controls which tool invocations bypass permission prompts. It does NOT disable or restrict which tools the AI can use. To completely disable tools, use disallowed_tools() instead.

Example: vec!["Bash(git:*)".to_string()] auto-approves git commands.

Source

pub fn allow_tool(self, tool: impl Into<String>) -> Self

Add a single allowed tool (auto-approval permission)

See allowed_tools() for important usage notes.

Source

pub fn disallowed_tools(self, tools: Vec<String>) -> Self

Set disallowed tools (completely disabled)

IMPORTANT: This completely disables the specified tools. The AI will not be able to use these tools at all. This is the correct way to restrict which tools the AI has access to.

Example: vec!["Bash".to_string(), "WebSearch".to_string()] prevents the AI from using Bash or WebSearch entirely.

Source

pub fn disallow_tool(self, tool: impl Into<String>) -> Self

Add a single disallowed tool (completely disabled)

See disallowed_tools() for important usage notes.

Source

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

Set permission mode

Source

pub fn add_mcp_server( self, name: impl Into<String>, config: McpServerConfig, ) -> Self

Add MCP server

Source

pub fn mcp_servers(self, servers: HashMap<String, McpServerConfig>) -> Self

Set all MCP servers from a map

Source

pub fn mcp_tools(self, tools: Vec<String>) -> Self

Set MCP tools

Source

pub fn max_turns(self, turns: i32) -> Self

Set max turns

Source

pub fn max_thinking_tokens(self, tokens: i32) -> Self

Set max thinking tokens

Source

pub fn max_output_tokens(self, tokens: u32) -> Self

Set max output tokens (1-32000, overrides CLAUDE_CODE_MAX_OUTPUT_TOKENS env var)

Source

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

Set model

Source

pub fn cwd(self, path: impl Into<PathBuf>) -> Self

Set working directory

Source

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

Enable continue conversation

Source

pub fn resume(self, id: impl Into<String>) -> Self

Set resume conversation ID

Source

pub fn permission_prompt_tool_name(self, name: impl Into<String>) -> Self

Set permission prompt tool name

Source

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

Set settings file path

Source

pub fn add_dirs(self, dirs: Vec<PathBuf>) -> Self

Add directories as working directories

Source

pub fn add_dir(self, dir: impl Into<PathBuf>) -> Self

Add a single directory as working directory

Source

pub fn extra_args(self, args: HashMap<String, Option<String>>) -> Self

Add extra CLI arguments

Source

pub fn add_extra_arg( self, key: impl Into<String>, value: Option<String>, ) -> Self

Add a single extra CLI argument

Source

pub fn control_protocol_format(self, format: ControlProtocolFormat) -> Self

Set control protocol format

Source

pub fn include_partial_messages(self, include: bool) -> Self

Include partial assistant messages in streaming output

Source

pub fn fork_session(self, fork: bool) -> Self

Enable fork_session behavior

Source

pub fn setting_sources(self, sources: Vec<SettingSource>) -> Self

Set setting sources

Source

pub fn agents(self, agents: HashMap<String, AgentDefinition>) -> Self

Define programmatic agents

Source

pub fn cli_channel_buffer_size(self, size: usize) -> Self

Set CLI channel buffer size

Controls the size of internal communication channels (message, control, stdin buffers). Default is 100. Increase for high-throughput scenarios to prevent message lag.

§Arguments
  • size - Buffer size (number of messages that can be queued)
§Example
let options = ClaudeCodeOptions::builder()
    .cli_channel_buffer_size(500)
    .build();
Source

pub fn tools(self, config: ToolsConfig) -> Self

Set tools configuration

Controls the base set of tools available to Claude. This is distinct from allowed_tools which only controls auto-approval permissions.

§Examples
// Enable specific tools only
let options = ClaudeCodeOptions::builder()
    .tools(ToolsConfig::list(vec!["Read".into(), "Edit".into()]))
    .build();
Source

pub fn betas(self, betas: Vec<SdkBeta>) -> Self

Add SDK beta features

Enable Anthropic API beta features like extended context window.

Source

pub fn add_beta(self, beta: SdkBeta) -> Self

Add a single SDK beta feature

Source

pub fn max_budget_usd(self, budget: f64) -> Self

Set maximum spending limit in USD

When the budget is exceeded, the session will automatically terminate.

Source

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

Set fallback model

Used when the primary model is unavailable.

Source

pub fn output_format(self, format: Value) -> Self

Set output format for structured outputs

Enables JSON schema validation for Claude’s responses.

§Example
let options = ClaudeCodeOptions::builder()
    .output_format(serde_json::json!({
        "type": "json_schema",
        "schema": {
            "type": "object",
            "properties": {
                "answer": {"type": "string"}
            }
        }
    }))
    .build();
Source

pub fn enable_file_checkpointing(self, enable: bool) -> Self

Enable file checkpointing

When enabled, file changes are tracked and can be rewound to any user message using ClaudeSDKClient::rewind_files().

Source

pub fn sandbox(self, settings: SandboxSettings) -> Self

Set sandbox configuration

Controls bash command sandboxing for filesystem and network isolation.

Source

pub fn plugins(self, plugins: Vec<SdkPluginConfig>) -> Self

Set plugin configurations

Source

pub fn add_plugin(self, plugin: SdkPluginConfig) -> Self

Add a single plugin

Source

pub fn user(self, user: impl Into<String>) -> Self

Set user identifier

Source

pub fn stderr_callback(self, callback: Arc<dyn Fn(&str) + Send + Sync>) -> Self

Set stderr callback

Called with each line of stderr output from the CLI.

Source

pub fn auto_download_cli(self, enable: bool) -> Self

Enable automatic CLI download

When enabled, the SDK will automatically download and cache the Claude Code CLI binary if it’s not found in the system PATH or common installation locations.

§Example
let options = ClaudeCodeOptions::builder()
    .auto_download_cli(true)
    .build();
Source

pub fn build(self) -> ClaudeCodeOptions

Build the options

Trait Implementations§

Source§

impl Debug for ClaudeCodeOptionsBuilder

Source§

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

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

impl Default for ClaudeCodeOptionsBuilder

Source§

fn default() -> ClaudeCodeOptionsBuilder

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

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,