pub struct SubprocessCliTransport {
pub prompt: Prompt,
pub options: ClaudeAgentOptions,
pub cli_path: String,
/* private fields */
}Expand description
Transport implementation that communicates with the Claude Code CLI via a subprocess.
Spawns the claude CLI as a child process, passing configuration via command-line
arguments and environment variables. Communication uses newline-delimited JSON
over stdin (input) and stdout (output).
§CLI discovery
The CLI binary is located by:
- Using
cli_pathfromClaudeAgentOptionsif provided - Searching
PATHforclaude - Checking common installation locations (
~/.npm-global/bin/,/usr/local/bin/, etc.)
Fields§
§prompt: PromptThe prompt type for this transport session.
options: ClaudeAgentOptionsThe agent options used to configure the CLI.
cli_path: StringThe resolved path to the CLI executable.
Implementations§
Source§impl SubprocessCliTransport
impl SubprocessCliTransport
Sourcepub fn new(prompt: Prompt, options: ClaudeAgentOptions) -> Result<Self>
pub fn new(prompt: Prompt, options: ClaudeAgentOptions) -> Result<Self>
Creates a new SubprocessCliTransport with the given prompt and options.
Resolves the CLI path immediately but does not start the subprocess.
Call connect() to spawn the process.
§Errors
Returns CLINotFoundError if the CLI executable cannot be located.
§Example
use claude_code::transport::subprocess_cli::{Prompt, SubprocessCliTransport};
let _transport = SubprocessCliTransport::new(Prompt::Messages, Default::default()).unwrap();Sourcepub fn build_command(&self) -> Result<Vec<String>>
pub fn build_command(&self) -> Result<Vec<String>>
Builds the complete command-line arguments for spawning the CLI process.
Translates all ClaudeAgentOptions fields into their corresponding CLI flags.
§Returns
A Vec<String> where the first element is the CLI path and the rest are arguments.
§Example
use claude_code::transport::subprocess_cli::{Prompt, SubprocessCliTransport};
let transport = SubprocessCliTransport::new(Prompt::Messages, Default::default()).unwrap();
let args = transport.build_command().unwrap();
assert!(args.iter().any(|arg| arg == "--input-format"));