Skip to main content

Module exec

Module exec 

Source
Expand description

Process spawning and execution for the claude CLI.

Builds and runs the child process behind every command: applies the Claude client’s binary path, working directory, environment, and timeout, scrubs the CLAUDECODE env var so nested runs are not detected as recursive, drains stdout/stderr without deadlocking, and maps failures onto Error via from_command_failure. Both the async (tokio) and blocking (sync feature) paths live here.

Every spawn places the child in its own process group on Unix, and every async spawn sets kill_on_drop(true). Dropping an in-flight execute future (a lost tokio::select! race, a caller-side timeout) SIGKILLs the whole group (via the crate-internal GroupKillGuard), so subprocesses the CLI spawned for tool use (shells, MCP servers, test runners) die with it rather than being reparented and running on. The same group-kill runs when a configured timeout fires, on both the async and blocking paths. The blocking paths cannot be dropped mid-flight, so they have no drop-side equivalent.

Consequence of the group split: the child no longer shares the host’s terminal process group, so terminal-generated signals (Ctrl-C) do not reach it directly; terminating a run is the wrapper’s job, via drop, timeout, or an explicit kill. Terminal-attached hosts that want the terminal to stay the supervisor can opt out with ClaudeBuilder::process_group(false), trading the tree kill away: kills then reach only the direct child.

Structs§

CommandOutput
Raw output from a claude CLI invocation.

Functions§

die_with_parent_supported
Whether ClaudeBuilder::die_with_parent does anything on this platform.
run_claude
Run a claude command with the given arguments.
run_claude_allow_exit_codes
Run a claude command and allow specific non-zero exit codes.
run_claude_allow_exit_codes_sync
Blocking mirror of run_claude_allow_exit_codes.
run_claude_sync
Blocking mirror of run_claude. Available with the sync feature.
run_claude_with_retry
Run a claude command with an optional per-command retry policy override.
run_claude_with_retry_sync
Blocking mirror of run_claude_with_retry.
run_claude_with_stdin_prompt
Run claude, writing stdin_content to the child’s stdin rather than passing the prompt as argv.
run_claude_with_stdin_prompt_sync
Blocking mirror of run_claude_with_stdin_prompt.