pub struct ClaudeCommand { /* private fields */ }Expand description
Builder for Claude Code CLI commands
§Example
use claude_runner_core::ClaudeCommand;
let result = ClaudeCommand::new()
.with_working_directory( "/home/user/project" )
.with_max_output_tokens( 200_000 )
.execute()?;Implementations§
Source§impl ClaudeCommand
impl ClaudeCommand
Sourcepub fn with_working_directory<P: Into<PathBuf>>(self, dir: P) -> Self
pub fn with_working_directory<P: Into<PathBuf>>(self, dir: P) -> Self
Set working directory for Claude Code execution
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_working_directory("/home/user/project");Sourcepub fn with_max_output_tokens(self, tokens: u32) -> Self
pub fn with_max_output_tokens(self, tokens: u32) -> Self
Set maximum output tokens (default: 200,000)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_max_output_tokens(200_000);Sourcepub fn with_continue_conversation(self, continue_: bool) -> Self
pub fn with_continue_conversation(self, continue_: bool) -> Self
Enable conversation continuation
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_continue_conversation(true);Sourcepub fn with_message<S: Into<String>>(self, message: S) -> Self
pub fn with_message<S: Into<String>>(self, message: S) -> Self
Set message to send to Claude
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_message("Explain this code");Sourcepub fn with_arg<S: Into<String>>(self, arg: S) -> Self
pub fn with_arg<S: Into<String>>(self, arg: S) -> Self
Add a single argument to the command
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_arg("--dangerously-skip-permissions");Sourcepub fn with_home(self, path: &Path) -> Self
pub fn with_home(self, path: &Path) -> Self
Override the HOME environment variable for process isolation
Sets HOME=<path> on the spawned process, directing it to use a different
home directory. Used by run_isolated() to prevent credential contamination.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_home( std::path::Path::new( "/tmp/isolated_home" ) );Sourcepub fn with_home_isolation(self) -> Self
pub fn with_home_isolation(self) -> Self
Configure the command for home-isolated subprocess invocations.
Suppresses --chrome injection — chrome is not needed for credential-only
subprocesses and adds unnecessary overhead (AC-41).
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_home( std::path::Path::new( "/tmp/isolated" ) )
.with_home_isolation();Sourcepub fn with_args<I, S>(self, args: I) -> Self
pub fn with_args<I, S>(self, args: I) -> Self
Add multiple arguments to the command
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_args(vec!["--dangerously-skip-permissions", "-c"]);Sourcepub fn with_bash_timeout_ms(self, timeout_ms: u32) -> Self
pub fn with_bash_timeout_ms(self, timeout_ms: u32) -> Self
Set default bash command timeout in milliseconds
Default: 3,600,000 ms (1 hour). Standard default: 120,000 ms (2 minutes).
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_bash_timeout_ms(3_600_000); // 1 hourSourcepub fn with_bash_max_timeout_ms(self, timeout_ms: u32) -> Self
pub fn with_bash_max_timeout_ms(self, timeout_ms: u32) -> Self
Set maximum bash command timeout in milliseconds
Default: 7,200,000 ms (2 hours). Standard default: 600,000 ms (10 minutes).
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_bash_max_timeout_ms(7_200_000); // 2 hoursSourcepub fn with_auto_continue(self, auto_continue: bool) -> Self
pub fn with_auto_continue(self, auto_continue: bool) -> Self
Enable or disable auto-continue mode
Default: true. Standard default: false. When true, enables programmatic automation without manual prompts.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_auto_continue(true);Sourcepub fn with_stdin_file(self, path: PathBuf) -> Self
pub fn with_stdin_file(self, path: PathBuf) -> Self
Set a file whose content is piped to the subprocess stdin
When set, execute() and execute_interactive() open the file and
attach it to the subprocess’s standard input via Stdio::from(file).
The file is opened at execution time — not at builder time — so dry-run
mode does not check file existence.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_stdin_file( std::path::PathBuf::from( "/tmp/input.txt" ) );Sourcepub fn with_unset_claudecode(self, unset: bool) -> Self
pub fn with_unset_claudecode(self, unset: bool) -> Self
Control whether CLAUDECODE is removed from the subprocess environment
Default: true (removes CLAUDECODE). Set to false to preserve
the variable in the subprocess, e.g. when the subprocess needs to
detect it is running inside a Claude Code session.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_unset_claudecode( false );Sourcepub fn with_telemetry(self, telemetry: bool) -> Self
pub fn with_telemetry(self, telemetry: bool) -> Self
Enable or disable telemetry
Default: false. Standard default: true. Disables usage data collection in automation contexts.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_telemetry(false);Source§impl ClaudeCommand
impl ClaudeCommand
Sourcepub fn with_auto_approve_tools(self, approve: bool) -> Self
pub fn with_auto_approve_tools(self, approve: bool) -> Self
Enable or disable auto-approval of tool executions
Default: false (inherits standard). Security-sensitive: requires explicit opt-in.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_auto_approve_tools(false); // Explicit denialSourcepub fn with_action_mode(self, mode: ActionMode) -> Self
pub fn with_action_mode(self, mode: ActionMode) -> Self
Set action mode for tool execution
Default: ActionMode::Ask (inherits standard).
§Example
use claude_runner_core::{ ClaudeCommand, ActionMode };
let cmd = ClaudeCommand::new()
.with_action_mode(ActionMode::Ask);Sourcepub fn with_log_level(self, level: LogLevel) -> Self
pub fn with_log_level(self, level: LogLevel) -> Self
Set logging verbosity level
Default: LogLevel::Info (inherits standard).
§Example
use claude_runner_core::{ ClaudeCommand, LogLevel };
let cmd = ClaudeCommand::new()
.with_log_level(LogLevel::Debug);Sourcepub fn with_temperature(self, temperature: f64) -> Self
pub fn with_temperature(self, temperature: f64) -> Self
Set model temperature
Default: 1.0 (inherits standard). Range: 0.0 to 1.0.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_temperature(0.7);Sourcepub fn with_skip_permissions(self, skip: bool) -> Self
pub fn with_skip_permissions(self, skip: bool) -> Self
Enable --dangerously-skip-permissions flag
When true, adds the --dangerously-skip-permissions flag to bypass
tool permission prompts. Use with caution in automated pipelines only.
Default: false.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_skip_permissions( true );Sourcepub fn with_allowed_tools<I, S>(self, tools: I) -> Self
pub fn with_allowed_tools<I, S>(self, tools: I) -> Self
Set allowed tools list (Pattern E: one flag + N space-separated values)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_allowed_tools( [ "bash", "read" ] );Sourcepub fn with_disallowed_tools<I, S>(self, tools: I) -> Self
pub fn with_disallowed_tools<I, S>(self, tools: I) -> Self
Set disallowed tools list (Pattern E: one flag + N space-separated values)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_disallowed_tools( [ "bash" ] );Sourcepub fn with_tools<I, S>(self, tools: I) -> Self
pub fn with_tools<I, S>(self, tools: I) -> Self
Set tools list (Pattern E: one flag + N space-separated values)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_tools( [ "bash" ] );Source§impl ClaudeCommand
impl ClaudeCommand
Sourcepub fn with_model<S: Into<String>>(self, model: S) -> Self
pub fn with_model<S: Into<String>>(self, model: S) -> Self
Set Claude model
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_model("claude-opus-4-5");Sourcepub fn with_api_key<S: Into<String>>(self, key: S) -> Self
pub fn with_api_key<S: Into<String>>(self, key: S) -> Self
Set API key via environment variable
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_api_key("sk-ant-...");Sourcepub fn with_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Enable verbose output
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_verbose(true);Sourcepub fn with_system_prompt<S: Into<String>>(self, prompt: S) -> Self
pub fn with_system_prompt<S: Into<String>>(self, prompt: S) -> Self
Set system prompt
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_system_prompt("You are a helpful coding assistant");Sourcepub fn with_sandbox_mode(self, sandbox: bool) -> Self
pub fn with_sandbox_mode(self, sandbox: bool) -> Self
Enable or disable sandbox mode
Default: true (inherits standard).
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_sandbox_mode(true);Sourcepub fn with_session_dir<P: Into<PathBuf>>(self, dir: P) -> Self
pub fn with_session_dir<P: Into<PathBuf>>(self, dir: P) -> Self
Set explicit session directory
Default: None (auto-detect). Overrides default session storage location.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_session_dir("/tmp/sessions");Sourcepub fn with_top_p(self, top_p: f64) -> Self
pub fn with_top_p(self, top_p: f64) -> Self
Set top-p sampling parameter
Default: None (inherits standard). Range: 0.0 to 1.0.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_top_p(0.9);Sourcepub fn with_top_k(self, top_k: u32) -> Self
pub fn with_top_k(self, top_k: u32) -> Self
Set top-k sampling parameter
Default: None (inherits standard).
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_top_k(40);Sourcepub fn with_dry_run(self, dry_run: bool) -> Self
pub fn with_dry_run(self, dry_run: bool) -> Self
Enable or disable dry-run mode
When true, execute() and execute_interactive() short-circuit without
spawning a real process. execute() returns describe_compact() as stdout
with exit code 0. Useful for inspecting what would be executed.
Default: false.
§Example
use claude_runner_core::ClaudeCommand;
let output = ClaudeCommand::new()
.with_message( "hello" )
.with_dry_run( true )
.execute()?;
assert!( output.stdout.starts_with( "env -u CLAUDECODE" ) );Sourcepub fn with_print(self, print: bool) -> Self
pub fn with_print(self, print: bool) -> Self
Force non-interactive print mode (-p)
When true, adds -p which forces non-interactive output and is required
for reliable programmatic execution when no TTY is attached.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_print( true );Sourcepub fn with_output_format(self, format: OutputFormat) -> Self
pub fn with_output_format(self, format: OutputFormat) -> Self
Set output format
§Example
use claude_runner_core::{ ClaudeCommand, OutputFormat };
let cmd = ClaudeCommand::new().with_output_format( OutputFormat::Json );Sourcepub fn with_input_format(self, format: InputFormat) -> Self
pub fn with_input_format(self, format: InputFormat) -> Self
Set input format
§Example
use claude_runner_core::{ ClaudeCommand, InputFormat };
let cmd = ClaudeCommand::new().with_input_format( InputFormat::StreamJson );Sourcepub fn with_include_partial_messages(self, include: bool) -> Self
pub fn with_include_partial_messages(self, include: bool) -> Self
Enable or disable partial message streaming
When true, adds --include-partial-messages for token-by-token streaming
with stream-json output format.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_include_partial_messages( true );Sourcepub fn with_replay_user_messages(self, replay: bool) -> Self
pub fn with_replay_user_messages(self, replay: bool) -> Self
Enable or disable replaying user messages on stdout
When true, adds --replay-user-messages.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_replay_user_messages( true );Sourcepub fn with_json_schema<S: Into<String>>(self, schema: S) -> Self
pub fn with_json_schema<S: Into<String>>(self, schema: S) -> Self
Constrain output to a JSON Schema
Adds --json-schema <schema> where schema is passed verbatim.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_json_schema( r#"{"type":"object"}"# );Sourcepub fn with_add_dir<S: Into<String>>(self, path: S) -> Self
pub fn with_add_dir<S: Into<String>>(self, path: S) -> Self
Add a directory to Claude’s accessible paths (Pattern F: repeated-flag)
Each call adds a --add-dir <path> pair. Call multiple times to add
multiple directories.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_add_dir( "/src" )
.with_add_dir( "/tests" );Sourcepub fn with_effort(self, level: EffortLevel) -> Self
pub fn with_effort(self, level: EffortLevel) -> Self
Set reasoning effort level
§Example
use claude_runner_core::{ ClaudeCommand, EffortLevel };
let cmd = ClaudeCommand::new().with_effort( EffortLevel::High );Sourcepub fn with_fallback_model<S: Into<String>>(self, model: S) -> Self
pub fn with_fallback_model<S: Into<String>>(self, model: S) -> Self
Set fallback model when the primary is unavailable
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_fallback_model( "claude-haiku-4-5" );Sourcepub fn with_max_budget_usd(self, amount: f64) -> Self
pub fn with_max_budget_usd(self, amount: f64) -> Self
Cap the API spend in USD for this session
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_max_budget_usd( 0.50 );Sourcepub fn with_mcp_config<I, S>(self, configs: I) -> Self
pub fn with_mcp_config<I, S>(self, configs: I) -> Self
Load MCP servers from JSON config files (Pattern F: repeated-flag per value)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_mcp_config( [ "/path/mcp.json" ] );Sourcepub fn with_strict_mcp_config(self, strict: bool) -> Self
pub fn with_strict_mcp_config(self, strict: bool) -> Self
Disable all non---mcp-config MCP servers
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_strict_mcp_config( true );Sourcepub fn with_settings<S: Into<String>>(self, settings: S) -> Self
pub fn with_settings<S: Into<String>>(self, settings: S) -> Self
Load a settings file or inline JSON string
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_settings( "/path/settings.json" );Sourcepub fn with_setting_sources<S: Into<String>>(self, sources: S) -> Self
pub fn with_setting_sources<S: Into<String>>(self, sources: S) -> Self
Filter which setting sources load
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_setting_sources( "local" );Sourcepub fn with_agent<S: Into<String>>(self, agent: S) -> Self
pub fn with_agent<S: Into<String>>(self, agent: S) -> Self
Override the agent for this session
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_agent( "reviewer" );Sourcepub fn with_agents<S: Into<String>>(self, json: S) -> Self
pub fn with_agents<S: Into<String>>(self, json: S) -> Self
Define custom agents as a single JSON string
CRITICAL: Takes a single JSON string — NOT an iterator. The entire agents
definition is one --agents <json> pair.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new()
.with_agents( r#"[{"name":"bot","model":"claude-opus-4-6"}]"# );Sourcepub fn with_plugin_dir<I, S>(self, dirs: I) -> Self
pub fn with_plugin_dir<I, S>(self, dirs: I) -> Self
Load plugins from directories (Pattern F: repeated-flag per value)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_plugin_dir( [ "/plugins" ] );Sourcepub fn with_resume(self, id: Option<&str>) -> Self
pub fn with_resume(self, id: Option<&str>) -> Self
Resume the most recent conversation, or a specific session by ID
with_resume(None)adds-r(resume most recent)with_resume(Some("uuid"))adds-r uuid(resume specific session)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_resume( None ); // most recent
let cmd = ClaudeCommand::new().with_resume( Some( "abc-123" ) ); // specificSourcepub fn with_session_id<S: Into<String>>(self, id: S) -> Self
pub fn with_session_id<S: Into<String>>(self, id: S) -> Self
Pin the session UUID for this invocation
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_session_id( "dead-beef-0000" );Sourcepub fn with_fork_session(self, fork: bool) -> Self
pub fn with_fork_session(self, fork: bool) -> Self
Create a new session ID on resume (fork)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_fork_session( true );Sourcepub fn with_no_session_persistence(self, no_persist: bool) -> Self
pub fn with_no_session_persistence(self, no_persist: bool) -> Self
Disable session persistence (do not save to disk)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_no_session_persistence( true );Sourcepub fn with_from_pr<S: Into<String>>(self, value: S) -> Self
pub fn with_from_pr<S: Into<String>>(self, value: S) -> Self
Resume a session linked to a PR
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_from_pr( "42" );Sourcepub fn with_append_system_prompt<S: Into<String>>(self, prompt: S) -> Self
pub fn with_append_system_prompt<S: Into<String>>(self, prompt: S) -> Self
Append text to the default system prompt (without replacing it)
Complementary to with_system_prompt() which replaces the system prompt.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_append_system_prompt( "Always respond in JSON" );Sourcepub fn with_permission_mode(self, mode: PermissionMode) -> Self
pub fn with_permission_mode(self, mode: PermissionMode) -> Self
Set fine-grained permission mode
§Example
use claude_runner_core::{ ClaudeCommand, PermissionMode };
let cmd = ClaudeCommand::new().with_permission_mode( PermissionMode::AcceptEdits );Sourcepub fn with_allow_dangerously_skip_permissions(self, allow: bool) -> Self
pub fn with_allow_dangerously_skip_permissions(self, allow: bool) -> Self
Allow the --dangerously-skip-permissions flag without activating it
Distinct from with_skip_permissions() which unconditionally activates it.
This method enables the option without triggering it.
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_allow_dangerously_skip_permissions( true );Sourcepub fn with_debug(self, filter: Option<&str>) -> Self
pub fn with_debug(self, filter: Option<&str>) -> Self
Enable debug output, with an optional category filter
with_debug(None)adds-d(all debug categories)with_debug(Some("mcp"))adds-d mcp(filtered)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_debug( None );
let cmd = ClaudeCommand::new().with_debug( Some( "mcp" ) );Sourcepub fn with_debug_file<S: Into<String>>(self, path: S) -> Self
pub fn with_debug_file<S: Into<String>>(self, path: S) -> Self
Redirect debug logs to a file
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_debug_file( "/tmp/debug.log" );Sourcepub fn with_betas<I, S>(self, betas: I) -> Self
pub fn with_betas<I, S>(self, betas: I) -> Self
Enable beta API headers (Pattern F: repeated-flag per beta)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_betas( [ "computer-use-2024-10-22" ] );Sourcepub fn with_brief(self, brief: bool) -> Self
pub fn with_brief(self, brief: bool) -> Self
Enable the SendUserMessage tool for sub-agents
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_brief( true );Sourcepub fn with_disable_slash_commands(self, disable: bool) -> Self
pub fn with_disable_slash_commands(self, disable: bool) -> Self
Disable all slash command skills
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_disable_slash_commands( true );Sourcepub fn with_file<I, S>(self, specs: I) -> Self
pub fn with_file<I, S>(self, specs: I) -> Self
Download file resources at startup (Pattern F: repeated-flag per spec)
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_file( [ "https://example.com/data.json" ] );Sourcepub fn with_worktree(self, name: Option<&str>) -> Self
pub fn with_worktree(self, name: Option<&str>) -> Self
Create a git worktree for the session (optional name)
with_worktree(None)adds-w(auto-name)with_worktree(Some("feature"))adds-w feature
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_worktree( None );
let cmd = ClaudeCommand::new().with_worktree( Some( "feature" ) );Sourcepub fn with_tmux(self, tmux: bool) -> Self
pub fn with_tmux(self, tmux: bool) -> Self
Create a tmux session for the worktree
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_tmux( true );Sourcepub fn with_ide(self, ide: bool) -> Self
pub fn with_ide(self, ide: bool) -> Self
Auto-connect to IDE on startup
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new().with_ide( true );Sourcepub fn with_chrome(self, enabled: Option<bool>) -> Self
pub fn with_chrome(self, enabled: Option<bool>) -> Self
Toggle Claude-in-Chrome integration (Pattern G: tri-state)
Some(true)→--chromeSome(false)→--no-chromeNone→ omit flag entirely (overridesSome(true)builder default; defers to Claude’s own config)
Builder default is Some(true) — --chrome is emitted unless explicitly overridden.
§Example
use claude_runner_core::ClaudeCommand;
// Default: chrome already on — no call needed
let cmd = ClaudeCommand::new();
// Explicitly disable chrome for this invocation
let cmd = ClaudeCommand::new().with_chrome( Some( false ) ); // --no-chrome
// Defer to Claude's own config (omit flag entirely, overrides default)
let cmd = ClaudeCommand::new().with_chrome( None ); // omitSource§impl ClaudeCommand
impl ClaudeCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Claude Code command builder
§Example
use claude_runner_core::ClaudeCommand;
let cmd = ClaudeCommand::new();Sourcepub fn describe_compact(&self) -> String
pub fn describe_compact(&self) -> String
Describe only the invocation line (no cd prefix)
Unlike describe(), this always returns a single line (without the leading cd /dir line).
When unset_claudecode is active (the default), the line starts with env -u CLAUDECODE claude ...;
when disabled via with_unset_claudecode(false), it starts with claude ....
§Critical: Implementation Must Use describe().lines().last()
Do NOT reconstruct the command from parts — that would diverge from the
actual command built by build_command(). The only correct implementation
is to delegate to describe() and extract the last line.
§Example
use claude_runner_core::ClaudeCommand;
// Default: CLAUDECODE is removed — invocation line starts with "env -u CLAUDECODE"
let compact = ClaudeCommand::new()
.with_working_directory( "/tmp" )
.with_skip_permissions( true )
.describe_compact();
assert!( compact.starts_with( "env -u CLAUDECODE" ) );
assert!( !compact.contains( "cd " ) );Sourcepub fn describe(&self) -> String
pub fn describe(&self) -> String
Describe the command line that would be executed
Returns a human-readable representation of the command. If a working
directory is set, the first line is cd /path/to/dir. The last line
is the claude invocation with all flags and arguments.
§Output Flag Order
The command-line flag order in the output is fixed by the implementation,
not by the order in which with_* builder methods are called. The order is:
env -u CLAUDECODEprefix (ifunset_claudecodeis true, the default)--dangerously-skip-permissions(ifskip_permissionsis true)--chromeor--no-chrome(fromchromefield; defaultSome(true)=--chrome)- custom args (in insertion order via
with_arg) -c(ifcontinue_conversationis true)"<message>"(if message is set)
This matters when writing tests that assert the exact output string (e.g. assert_eq!).
Use contains assertions for individual flags when order is not the subject of the test.
§Critical: Must Mirror build_command()
describe() reconstructs the command string independently of build_command(). Every CLI
flag that build_command() emits from a typed field (not from self.args) MUST also
appear in describe() at the corresponding position.
Typed-field flags (currently skip_permissions, chrome, continue_conversation) are
emitted directly in build_command() — NOT via self.args. Updating build_command()
without updating describe() causes dry-run output to diverge from the actual command.
Pitfall: always update both methods when adding a new typed-field CLI parameter.
§Example
use claude_runner_core::ClaudeCommand;
let desc = ClaudeCommand::new()
.with_working_directory( "/tmp" )
.with_skip_permissions( true )
.with_message( "hello" )
.describe();
assert!( desc.contains( "cd /tmp" ) );
assert!( desc.contains( "--dangerously-skip-permissions" ) );Sourcepub fn describe_env(&self) -> String
pub fn describe_env(&self) -> String
Describe environment variables that would be set
Returns one NAME=VALUE line per configured environment variable.
Only includes variables that have been explicitly set (via defaults
or builder methods). Omits None values.
§Example
use claude_runner_core::ClaudeCommand;
let env = ClaudeCommand::new().describe_env();
assert!( env.contains( "CLAUDE_CODE_MAX_OUTPUT_TOKENS=200000" ) );
assert!( env.contains( "CLAUDE_CODE_BASH_TIMEOUT=3600000" ) );Sourcepub fn execute(&self) -> Result<ExecutionOutput>
pub fn execute(&self) -> Result<ExecutionOutput>
Execute the Claude Code command and capture output (non-interactive mode)
This is the SINGLE execution point for non-interactive Claude Code process invocations.
For interactive sessions, use execute_interactive.
Returns ExecutionOutput with stdout, stderr, and exit code.
§Errors
Returns error if Claude Code binary not found in PATH or process fails to spawn.
§Example
use claude_runner_core::ClaudeCommand;
let result = ClaudeCommand::new()
.with_max_output_tokens( 200_000 )
.execute()?;
println!( "{}", result.stdout );Sourcepub fn execute_interactive(&self) -> Result<ExitStatus>
pub fn execute_interactive(&self) -> Result<ExitStatus>
Execute the Claude Code command in interactive mode (TTY attached)
This method allows Claude Code to take over the terminal for interactive sessions.
Unlike execute, this doesnt capture output and instead lets
Claude Code directly interact with the user’s terminal.
§Errors
Returns error if Claude Code binary not found in PATH or process fails to spawn.
§Example
use claude_runner_core::ClaudeCommand;
let exit_status = ClaudeCommand::new()
.with_max_output_tokens( 200_000 )
.execute_interactive()?;Source§impl ClaudeCommand
impl ClaudeCommand
Sourcepub fn spawn_piped(&self) -> Result<Child>
pub fn spawn_piped(&self) -> Result<Child>
Spawn the Claude Code process with piped stdout/stderr and return the Child handle.
Unlike execute, this method does not wait for the subprocess
to finish. The caller owns the Child and is responsible for calling
Child::wait or
Child::wait_with_output.
Used by run_isolated() to enable timeout-with-kill-and-partial-output handling.
§Errors
Returns io::Error on spawn failure. Check e.kind() == ErrorKind::NotFound to
detect a missing claude binary.
§Example
use claude_runner_core::ClaudeCommand;
let mut child = ClaudeCommand::new()
.with_message( "hello" )
.spawn_piped()?;
let output = child.wait_with_output()?;Sourcepub fn spawn_tty(&self) -> Result<Child>
pub fn spawn_tty(&self) -> Result<Child>
Spawn the Claude Code process with inherited TTY stdio and return the Child handle.
Unlike spawn_piped, stdout and stderr are inherited from the
parent process so Claude can use the terminal for interactive output. stdin is
either the provided --file content or inherited from the parent TTY.
The caller owns the Child and is responsible for calling
Child::wait after killing or waiting for the process.
Used by run_interactive in claude_runner when --timeout > 0 to enable
watchdog-kill while preserving the full TTY experience.
§Errors
Returns io::Error on spawn failure. Check e.kind() == ErrorKind::NotFound to
detect a missing claude binary.