Skip to main content

SubprocessCliTransport

Struct SubprocessCliTransport 

Source
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:

  1. Using cli_path from ClaudeAgentOptions if provided
  2. Searching PATH for claude
  3. Checking common installation locations (~/.npm-global/bin/, /usr/local/bin/, etc.)

Fields§

§prompt: Prompt

The prompt type for this transport session.

§options: ClaudeAgentOptions

The agent options used to configure the CLI.

§cli_path: String

The resolved path to the CLI executable.

Implementations§

Source§

impl SubprocessCliTransport

Source

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();
Source

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"));

Trait Implementations§

Source§

impl Drop for SubprocessCliTransport

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Transport for SubprocessCliTransport

Source§

fn connect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Establishes the transport connection (e.g., spawns the subprocess).
Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 mut self, data: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes a string (typically a JSON line) to the CLI’s input stream.
Source§

fn end_input<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Signals that no more input will be sent (closes the input stream).
Source§

fn read_next_message<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reads the next JSON message from the CLI’s output stream. Read more
Source§

fn close<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes the transport connection and cleans up resources.
Source§

fn is_ready(&self) -> bool

Returns true if the transport is connected and ready for I/O.
Source§

fn into_split(self: Box<Self>) -> TransportSplitResult

Splits the transport into independent reader and writer halves. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more