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§
- Command
Output - Raw output from a claude CLI invocation.
Functions§
- die_
with_ parent_ supported - Whether
ClaudeBuilder::die_with_parentdoes 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 thesyncfeature. - 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_contentto 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.