Skip to main content

ClientConfig

Struct ClientConfig 

Source
pub struct ClientConfig {
Show 27 fields pub prompt: String, pub cli_path: Option<PathBuf>, pub cwd: Option<PathBuf>, pub model: Option<String>, pub fallback_model: Option<String>, pub system_prompt: Option<SystemPrompt>, pub max_turns: Option<u32>, pub max_budget_usd: Option<f64>, pub max_thinking_tokens: Option<u32>, pub allowed_tools: Vec<String>, pub disallowed_tools: Vec<String>, pub permission_mode: PermissionMode, pub can_use_tool: Option<CanUseToolCallback>, pub resume: Option<String>, pub hooks: Vec<HookMatcher>, pub mcp_servers: McpServers, pub message_callback: Option<MessageCallback>, pub env: HashMap<String, String>, pub verbose: bool, pub output_format: String, pub extra_args: BTreeMap<String, Option<String>>, pub connect_timeout: Option<Duration>, pub close_timeout: Option<Duration>, pub read_timeout: Option<Duration>, pub default_hook_timeout: Duration, pub version_check_timeout: Option<Duration>, pub stderr_callback: Option<Arc<dyn Fn(String) + Send + Sync>>,
}
Expand description

Configuration for a Claude Code SDK client session.

Use ClientConfig::builder() to construct.

Fields§

§prompt: String

The prompt text to send to Claude.

§cli_path: Option<PathBuf>

Path to the Claude CLI binary. If None, auto-discovered via find_cli().

§cwd: Option<PathBuf>

Working directory for the Claude process.

§model: Option<String>

Model to use (e.g., "claude-sonnet-4-5").

§fallback_model: Option<String>

Fallback model if the primary is unavailable.

§system_prompt: Option<SystemPrompt>

System prompt configuration.

§max_turns: Option<u32>

Maximum number of agentic turns before stopping.

§max_budget_usd: Option<f64>

Maximum USD budget for the session.

§max_thinking_tokens: Option<u32>

Maximum thinking tokens per turn.

§allowed_tools: Vec<String>

Explicitly allowed tool names.

§disallowed_tools: Vec<String>

Explicitly disallowed tool names.

§permission_mode: PermissionMode

Permission mode for the session.

§can_use_tool: Option<CanUseToolCallback>

Callback invoked when the CLI requests tool use permission.

§resume: Option<String>

Resume an existing session by ID.

§hooks: Vec<HookMatcher>

Lifecycle hooks to register for the session.

§mcp_servers: McpServers

External MCP server configurations.

§message_callback: Option<MessageCallback>

Optional message callback for observe/filter.

§env: HashMap<String, String>

Extra environment variables to pass to the CLI process.

§verbose: bool

Enable verbose (debug) output from the CLI.

§output_format: String

Output format. Defaults to "json" for SDK use.

§extra_args: BTreeMap<String, Option<String>>

Arbitrary extra CLI flags to pass through to the Claude process.

Keys are flag names (without the -- prefix). Values are optional:

  • Some("value") produces --key value
  • None produces --key (boolean-style flag)

Uses BTreeMap to guarantee deterministic CLI arg ordering across invocations (important for reproducible test snapshots).

§Example

use std::collections::BTreeMap;
use claude_cli_sdk::ClientConfig;

let config = ClientConfig::builder()
    .prompt("hello")
    .extra_args(BTreeMap::from([
        ("replay-user-messages".into(), None),
        ("context-window".into(), Some("200000".into())),
    ]))
    .build();
§connect_timeout: Option<Duration>

Deadline for process spawn + init message. None = wait forever.

Default: Some(30s).

§close_timeout: Option<Duration>

Deadline for child.wait() during close. On expiry the process is killed. None = wait forever.

Default: Some(10s).

§read_timeout: Option<Duration>

Per-message recv deadline. None = wait forever (default).

This is for detecting hung/zombie processes, not for limiting turn time — Claude turns can legitimately take minutes.

§default_hook_timeout: Duration

Fallback timeout for hook callbacks when HookMatcher::timeout is None.

Default: 30 seconds.

§version_check_timeout: Option<Duration>

Deadline for the --version check in check_cli_version(). None = wait forever.

Default: Some(5s).

§stderr_callback: Option<Arc<dyn Fn(String) + Send + Sync>>

Optional callback for CLI stderr output.

Implementations§

Source§

impl ClientConfig

Source

pub fn builder() -> ClientConfigBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>

Create a builder for building ClientConfig. On the builder, call .prompt(...), .cli_path(...)(optional), .cwd(...)(optional), .model(...)(optional), .fallback_model(...)(optional), .system_prompt(...)(optional), .max_turns(...)(optional), .max_budget_usd(...)(optional), .max_thinking_tokens(...)(optional), .allowed_tools(...)(optional), .disallowed_tools(...)(optional), .permission_mode(...)(optional), .can_use_tool(...)(optional), .resume(...)(optional), .hooks(...)(optional), .mcp_servers(...)(optional), .message_callback(...)(optional), .env(...)(optional), .verbose(...)(optional), .output_format(...)(optional), .extra_args(...)(optional), .connect_timeout(...)(optional), .close_timeout(...)(optional), .read_timeout(...)(optional), .default_hook_timeout(...)(optional), .version_check_timeout(...)(optional), .stderr_callback(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of ClientConfig.

Source§

impl ClientConfig

Source

pub fn validate(&self) -> Result<()>

Validate the configuration, returning an error for invalid settings.

Checks:

  • If cwd is set, it must exist and be a directory.

This is called automatically by Client::new().

Source

pub fn to_cli_args(&self) -> Vec<String>

Build the CLI argument list for spawning the Claude process.

This does NOT include the binary path itself — just the arguments.

Source

pub fn to_env(&self) -> HashMap<String, String>

Build the environment variable map for the CLI process.

Merges self.env with any SDK-internal env vars needed.

Trait Implementations§

Source§

impl Debug for ClientConfig

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

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
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> 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
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.
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