Skip to main content

CodexClientBuilder

Struct CodexClientBuilder 

Source
pub struct CodexClientBuilder { /* private fields */ }
Expand description

Builder for crate::CodexClient.

CLI parity planning and implementation history lives under docs/project_management/next/ (see docs/project_management/next/codex-cli-parity/) and the parity ADRs in docs/adr/.

Implementations§

Source§

impl CodexClientBuilder

Source

pub fn new() -> Self

Starts a new builder with default values.

Source

pub fn binary(self, binary: impl Into<PathBuf>) -> Self

Sets the path to the Codex binary.

Defaults to CODEX_BINARY when present or codex on PATH. Use this to pin a packaged binary, e.g. the path returned from crate::resolve_bundled_binary when your app ships Codex inside an isolated bundle.

Source

pub fn codex_home(self, home: impl Into<PathBuf>) -> Self

Sets a custom CODEX_HOME path that will be applied per command. Directories are created by default; disable via Self::create_home_dirs.

Source

pub fn create_home_dirs(self, enable: bool) -> Self

Controls whether the CODEX_HOME directory tree should be created if missing. Defaults to true when Self::codex_home is set.

Source

pub fn model(self, model: impl Into<String>) -> Self

Sets the model that should be used for every codex exec call.

Source

pub fn timeout(self, timeout: Duration) -> Self

Overrides the maximum amount of time to wait for Codex to respond.

Source

pub fn color_mode(self, color_mode: ColorMode) -> Self

Controls whether Codex may emit ANSI colors (--color). Defaults to ColorMode::Never.

Source

pub fn working_dir(self, dir: impl Into<PathBuf>) -> Self

Forces Codex to run with the provided working directory instead of a fresh temp dir.

Source

pub fn add_dir(self, path: impl Into<PathBuf>) -> Self

Requests that codex exec include one or more --add-dir flags when the probed binary supports them. Unsupported or unknown capability results skip the flag to avoid CLI errors.

Source

pub fn add_dirs<I, P>(self, dirs: I) -> Self
where I: IntoIterator<Item = P>, P: Into<PathBuf>,

Replaces the current add-dir list with the provided collection.

Source

pub fn image(self, path: impl Into<PathBuf>) -> Self

Adds an image to the prompt by passing --image <path> to codex exec.

Source

pub fn images<I, P>(self, images: I) -> Self
where I: IntoIterator<Item = P>, P: Into<PathBuf>,

Replaces the current image list with the provided collection.

Source

pub fn json(self, enable: bool) -> Self

Enables Codex’s JSONL output mode (--json).

Prompts are piped via stdin when enabled. Events include thread.started (or thread.resumed when continuing), turn.started/turn.completed/turn.failed, and item.created/item.updated with item.type such as agent_message or reasoning. Pair with .mirror_stdout(false) if you plan to parse the stream instead of just mirroring it.

Source

pub fn output_schema(self, enable: bool) -> Self

Requests the --output-schema flag when the probed binary reports support. When capability detection is inconclusive, the flag is skipped to maintain compatibility with older releases.

Source

pub fn quiet(self, enable: bool) -> Self

Suppresses mirroring Codex stderr to the console.

Source

pub fn mirror_stdout(self, enable: bool) -> Self

Controls whether Codex stdout should be mirrored to the console while also being captured. Disable this when you plan to parse JSONL output or tee the stream to a log file (see crates/codex/examples/stream_with_log.rs).

Source

pub fn json_event_log(self, path: impl Into<PathBuf>) -> Self

Tees each JSONL event line from crate::CodexClient::stream_exec into a log file. Logs append to existing files, flush after each line, and create parent directories as needed. crate::ExecStreamRequest::json_event_log overrides this default per request.

Source

pub fn config_override( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Adds a --config key=value override that will be applied to every Codex invocation.

Source

pub fn config_override_raw(self, raw: impl Into<String>) -> Self

Adds a preformatted --config key=value override without parsing the input.

Source

pub fn config_overrides<I, K, V>(self, overrides: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Replaces the config overrides with the provided collection.

Source

pub fn profile(self, profile: impl Into<String>) -> Self

Selects a Codex config profile (--profile).

Source

pub fn reasoning_effort(self, effort: ReasoningEffort) -> Self

Sets model_reasoning_effort via --config.

Source

pub fn reasoning_summary(self, summary: ReasoningSummary) -> Self

Sets model_reasoning_summary via --config.

Source

pub fn reasoning_verbosity(self, verbosity: ModelVerbosity) -> Self

Sets model_verbosity via --config.

Source

pub fn reasoning_summary_format(self, format: ReasoningSummaryFormat) -> Self

Sets model_reasoning_summary_format via --config.

Source

pub fn supports_reasoning_summaries(self, enable: bool) -> Self

Sets model_supports_reasoning_summaries via --config.

Source

pub fn auto_reasoning_defaults(self, enable: bool) -> Self

Controls whether GPT-5* reasoning defaults should be injected automatically.

Source

pub fn approval_policy(self, policy: ApprovalPolicy) -> Self

Sets the approval policy for Codex subprocesses.

Source

pub fn sandbox_mode(self, mode: SandboxMode) -> Self

Sets the sandbox mode for Codex subprocesses.

Source

pub fn full_auto(self, enable: bool) -> Self

Applies the --full-auto safety override unless explicit sandbox/approval options are set.

Source

pub fn dangerously_bypass_approvals_and_sandbox(self, enable: bool) -> Self

Applies the --dangerously-bypass-approvals-and-sandbox override.

Source

pub fn cd(self, dir: impl Into<PathBuf>) -> Self

Applies --cd <dir> to Codex invocations while keeping the process cwd set to working_dir.

Source

pub fn local_provider(self, provider: LocalProvider) -> Self

Selects a local provider backend (--local-provider).

Source

pub fn oss(self, enable: bool) -> Self

Requests the CLI --oss flag to favor OSS/local backends when available.

Source

pub fn enable_feature(self, name: impl Into<String>) -> Self

Adds a --enable <feature> toggle to Codex invocations.

Source

pub fn disable_feature(self, name: impl Into<String>) -> Self

Adds a --disable <feature> toggle to Codex invocations.

Source

pub fn search(self, enable: bool) -> Self

Controls whether --search is passed through to Codex.

Source

pub fn capability_overrides(self, overrides: CapabilityOverrides) -> Self

Supplies manual capability data to skip probes or adjust feature flags.

Source

pub fn capability_feature_overrides( self, overrides: CapabilityFeatureOverrides, ) -> Self

Convenience to apply feature overrides or vendor hints without touching versions.

Source

pub fn capability_feature_hints(self, features: CodexFeatureFlags) -> Self

Convenience to opt into specific feature flags while leaving other probes intact.

Source

pub fn capability_snapshot(self, snapshot: CodexCapabilities) -> Self

Supplies a precomputed capability snapshot for pinned or bundled Codex builds. Combine with write_capabilities_snapshot / read_capabilities_snapshot to persist probe results between processes.

Source

pub fn capability_version_override(self, version: CodexVersionInfo) -> Self

Overrides the probed version data with caller-provided metadata.

Source

pub fn capability_cache_policy(self, policy: CapabilityCachePolicy) -> Self

Controls how capability probes interact with the in-process cache. Use crate::CapabilityCachePolicy::Refresh to enforce a TTL/backoff when binaries are hot-swapped without changing fingerprints.

Source

pub fn bypass_capability_cache(self, bypass: bool) -> Self

Convenience to bypass the capability cache when a fresh snapshot is required. Bypass skips cache reads and writes for the probe.

Source

pub fn build(self) -> CodexClient

Builds the crate::CodexClient.

Trait Implementations§

Source§

impl Clone for CodexClientBuilder

Source§

fn clone(&self) -> CodexClientBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodexClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodexClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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