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 modelclaude-3-sonnet-20240229
- Balanced performance and costclaude-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 metadataStreamJson
: 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 patternsBalanced
: Context-aware validation (default)Relaxed
: Only blocks obvious attack patternsDisabled
: No security validation (use with caution)
Implementations§
Source§impl Config
impl Config
Sourcepub fn builder() -> ConfigBuilder
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();
Sourcepub fn validate(&self) -> Result<(), Error>
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<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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