Struct Config

Source
pub struct Config {
Show 16 fields pub system_prompt: Option<String>, pub model: Option<String>, pub mcp_config_path: Option<PathBuf>, pub allowed_tools: Option<Vec<String>>, pub stream_format: StreamFormat, pub non_interactive: bool, pub verbose: bool, pub max_tokens: Option<usize>, pub timeout_secs: Option<u64>, pub continue_session: bool, pub resume_session_id: Option<String>, pub append_system_prompt: Option<String>, pub disallowed_tools: Option<Vec<String>>, pub max_turns: Option<u32>, pub skip_permissions: bool, pub security_level: SecurityLevel,
}
Expand description

Configuration options for Claude AI client

The Config struct holds all configuration options for the Claude AI client, including model selection, system prompts, tool permissions, and output formatting.

§Examples

use claude_sdk_rs_core::{Config, StreamFormat};
use std::path::PathBuf;

// Default configuration
let config = Config::default();

// Custom configuration with builder pattern
let config = Config::builder()
    .model("claude-3-opus-20240229")
    .system_prompt("You are a helpful Rust programming assistant")
    .stream_format(StreamFormat::Json)
    .timeout_secs(60)
    .allowed_tools(vec!["bash".to_string(), "filesystem".to_string()])
    .build();

Fields§

§system_prompt: Option<String>

Optional system prompt to set the assistant’s behavior and context

This prompt is sent with every request to provide consistent context and instructions to Claude about how it should respond.

§model: Option<String>

Claude model to use for requests

Available models include:

  • claude-3-opus-20240229 - Most capable model
  • claude-3-sonnet-20240229 - Balanced performance and cost
  • claude-3-haiku-20240307 - Fastest and most cost-effective

If not specified, Claude CLI will use its default model.

§mcp_config_path: Option<PathBuf>

Path to Model Context Protocol (MCP) configuration file

MCP allows Claude to interact with external tools and data sources. This should point to a valid MCP config file containing server definitions.

§allowed_tools: Option<Vec<String>>

List of tools that Claude is allowed to use

Tools are specified using the format server_name__tool_name for MCP tools or simple names like bash for built-in tools. An empty list or None means all available tools are allowed.

§Examples

let tools = vec![
    "bash".to_string(),
    "filesystem".to_string(),
    "mcp_server__database_query".to_string(),
];
§stream_format: StreamFormat

Output format for Claude CLI responses

  • Text: Plain text output (default)
  • Json: Structured JSON with metadata
  • StreamJson: Line-delimited JSON messages for streaming
§non_interactive: bool

Whether to run Claude CLI in non-interactive mode

When true (default), Claude CLI won’t prompt for user input, making it suitable for programmatic use.

§verbose: bool

Enable verbose output from Claude CLI

When true, additional debugging information will be included in the CLI output. Useful for troubleshooting.

§max_tokens: Option<usize>

Maximum number of tokens to generate in the response

If not specified, Claude will use its default token limit. Setting this can help control response length and costs.

§timeout_secs: Option<u64>

Timeout in seconds for Claude CLI execution (default: 30s)

How long to wait for Claude CLI to respond before timing out. Increase this for complex queries that might take longer to process.

§continue_session: bool

Whether to continue the last session

When true, adds the --continue flag to resume the most recent conversation session. This allows for conversation continuity across multiple API calls.

§resume_session_id: Option<String>

Session ID to resume

When set, adds the --resume flag with the specified session ID to continue a specific conversation session. This allows for resuming conversations from a particular point.

§append_system_prompt: Option<String>

Additional system prompt to append

When set, adds the --append-system-prompt flag to extend the existing system prompt. Cannot be used together with system_prompt.

§disallowed_tools: Option<Vec<String>>

List of tools that Claude is NOT allowed to use

Tools are specified using the same format as allowed_tools. This provides fine-grained control over tool restrictions.

§max_turns: Option<u32>

Maximum number of conversation turns

When set, limits the conversation to the specified number of back-and-forth exchanges. Useful for controlling conversation length.

§skip_permissions: bool

Whether to skip permission prompts (default: true)

When true, adds the --dangerously-skip-permissions flag to bypass tool permission prompts. This is enabled by default for programmatic use but can be disabled for additional security.

§security_level: SecurityLevel

Security validation strictness level

Controls how strictly user input is validated for potential security threats.

  • Strict: Blocks most special characters and patterns
  • Balanced: Context-aware validation (default)
  • Relaxed: Only blocks obvious attack patterns
  • Disabled: No security validation (use with caution)

Implementations§

Source§

impl Config

Source

pub fn builder() -> ConfigBuilder

Create a new configuration builder

The builder pattern provides a fluent interface for creating configurations with custom settings.

§Examples
use claude_sdk_rs_core::{Config, StreamFormat};

let config = Config::builder()
    .model("claude-3-opus-20240229")
    .system_prompt("You are a helpful assistant")
    .stream_format(StreamFormat::Json)
    .timeout_secs(120)
    .build();
Source

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

Validate the configuration

Checks all configuration values for validity according to defined limits and constraints. Returns an error if any validation fails.

§Errors

Returns Error::InvalidInput if:

  • System prompt exceeds maximum length
  • Timeout is outside valid range
  • Max tokens exceeds limit
  • Tool names are invalid

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,