pub struct ClaudeCodeOptionsBuilder { /* private fields */ }Expand description
Builder for ClaudeCodeOptions
Implementations§
Source§impl ClaudeCodeOptionsBuilder
impl ClaudeCodeOptionsBuilder
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Set system prompt
Sourcepub fn append_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn append_system_prompt(self, prompt: impl Into<String>) -> Self
Set append system prompt
Sourcepub fn allowed_tools(self, tools: Vec<String>) -> Self
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.
Sourcepub fn allow_tool(self, tool: impl Into<String>) -> Self
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.
Sourcepub fn disallowed_tools(self, tools: Vec<String>) -> Self
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.
Sourcepub fn disallow_tool(self, tool: impl Into<String>) -> Self
pub fn disallow_tool(self, tool: impl Into<String>) -> Self
Add a single disallowed tool (completely disabled)
See disallowed_tools() for important usage notes.
Sourcepub fn permission_mode(self, mode: PermissionMode) -> Self
pub fn permission_mode(self, mode: PermissionMode) -> Self
Set permission mode
Sourcepub fn add_mcp_server(
self,
name: impl Into<String>,
config: McpServerConfig,
) -> Self
pub fn add_mcp_server( self, name: impl Into<String>, config: McpServerConfig, ) -> Self
Add MCP server
Sourcepub fn mcp_servers(self, servers: HashMap<String, McpServerConfig>) -> Self
pub fn mcp_servers(self, servers: HashMap<String, McpServerConfig>) -> Self
Set all MCP servers from a map
Sourcepub fn max_thinking_tokens(self, tokens: i32) -> Self
pub fn max_thinking_tokens(self, tokens: i32) -> Self
Set max thinking tokens
Sourcepub fn max_output_tokens(self, tokens: u32) -> Self
pub fn max_output_tokens(self, tokens: u32) -> Self
Set max output tokens (1-32000, overrides CLAUDE_CODE_MAX_OUTPUT_TOKENS env var)
Sourcepub fn continue_conversation(self, enable: bool) -> Self
pub fn continue_conversation(self, enable: bool) -> Self
Enable continue conversation
Sourcepub fn permission_prompt_tool_name(self, name: impl Into<String>) -> Self
pub fn permission_prompt_tool_name(self, name: impl Into<String>) -> Self
Set permission prompt tool name
Sourcepub fn add_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn add_dir(self, dir: impl Into<PathBuf>) -> Self
Add a single directory as working directory
Sourcepub fn add_extra_arg(
self,
key: impl Into<String>,
value: Option<String>,
) -> Self
pub fn add_extra_arg( self, key: impl Into<String>, value: Option<String>, ) -> Self
Add a single extra CLI argument
Sourcepub fn control_protocol_format(self, format: ControlProtocolFormat) -> Self
pub fn control_protocol_format(self, format: ControlProtocolFormat) -> Self
Set control protocol format
Sourcepub fn include_partial_messages(self, include: bool) -> Self
pub fn include_partial_messages(self, include: bool) -> Self
Include partial assistant messages in streaming output
Sourcepub fn fork_session(self, fork: bool) -> Self
pub fn fork_session(self, fork: bool) -> Self
Enable fork_session behavior
Sourcepub fn setting_sources(self, sources: Vec<SettingSource>) -> Self
pub fn setting_sources(self, sources: Vec<SettingSource>) -> Self
Set setting sources
Sourcepub fn agents(self, agents: HashMap<String, AgentDefinition>) -> Self
pub fn agents(self, agents: HashMap<String, AgentDefinition>) -> Self
Define programmatic agents
Sourcepub fn cli_channel_buffer_size(self, size: usize) -> Self
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();Sourcepub fn tools(self, config: ToolsConfig) -> Self
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();Sourcepub fn betas(self, betas: Vec<SdkBeta>) -> Self
pub fn betas(self, betas: Vec<SdkBeta>) -> Self
Add SDK beta features
Enable Anthropic API beta features like extended context window.
Sourcepub fn max_budget_usd(self, budget: f64) -> Self
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.
Sourcepub fn fallback_model(self, model: impl Into<String>) -> Self
pub fn fallback_model(self, model: impl Into<String>) -> Self
Set fallback model
Used when the primary model is unavailable.
Sourcepub fn output_format(self, format: Value) -> Self
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();Sourcepub fn enable_file_checkpointing(self, enable: bool) -> Self
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().
Sourcepub fn sandbox(self, settings: SandboxSettings) -> Self
pub fn sandbox(self, settings: SandboxSettings) -> Self
Set sandbox configuration
Controls bash command sandboxing for filesystem and network isolation.
Sourcepub fn plugins(self, plugins: Vec<SdkPluginConfig>) -> Self
pub fn plugins(self, plugins: Vec<SdkPluginConfig>) -> Self
Set plugin configurations
Sourcepub fn add_plugin(self, plugin: SdkPluginConfig) -> Self
pub fn add_plugin(self, plugin: SdkPluginConfig) -> Self
Add a single plugin
Sourcepub fn stderr_callback(self, callback: Arc<dyn Fn(&str) + Send + Sync>) -> Self
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.
Sourcepub fn auto_download_cli(self, enable: bool) -> Self
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();Sourcepub fn build(self) -> ClaudeCodeOptions
pub fn build(self) -> ClaudeCodeOptions
Build the options
Trait Implementations§
Source§impl Debug for ClaudeCodeOptionsBuilder
impl Debug for ClaudeCodeOptionsBuilder
Source§impl Default for ClaudeCodeOptionsBuilder
impl Default for ClaudeCodeOptionsBuilder
Source§fn default() -> ClaudeCodeOptionsBuilder
fn default() -> ClaudeCodeOptionsBuilder
Auto Trait Implementations§
impl Freeze for ClaudeCodeOptionsBuilder
impl !RefUnwindSafe for ClaudeCodeOptionsBuilder
impl Send for ClaudeCodeOptionsBuilder
impl Sync for ClaudeCodeOptionsBuilder
impl Unpin for ClaudeCodeOptionsBuilder
impl !UnwindSafe for ClaudeCodeOptionsBuilder
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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