pub struct CodexBuilder { /* private fields */ }Expand description
Builder for creating a Codex client.
All options are optional. By default the builder discovers the codex
binary via PATH.
Implementations§
Source§impl CodexBuilder
impl CodexBuilder
Sourcepub fn tested_cli_version_range(self, min: CliVersion, max: CliVersion) -> Self
pub fn tested_cli_version_range(self, min: CliVersion, max: CliVersion) -> Self
Override the tested-against CLI version range.
Defaults to the range this crate declares and verifies in CI. Set this only when you have validated a different range yourself; widening it does not make the wrapper work against versions it was not tested on.
Sourcepub fn binary(self, path: impl Into<PathBuf>) -> Self
pub fn binary(self, path: impl Into<PathBuf>) -> Self
Set an explicit path to the codex binary (skips PATH lookup).
Sourcepub fn working_dir(self, path: impl Into<PathBuf>) -> Self
pub fn working_dir(self, path: impl Into<PathBuf>) -> Self
Set the working directory for all commands.
Sourcepub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
Set a single environment variable for child processes.
Sourcepub fn envs(
self,
vars: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
) -> Self
pub fn envs( self, vars: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>, ) -> Self
Set multiple environment variables for child processes.
Sourcepub fn clear_env(self) -> Self
pub fn clear_env(self) -> Self
Clear the inherited environment before applying variables supplied by
env and envs.
By default, child processes inherit the wrapper process’s environment.
This opt-in is call-order independent: explicit variables survive
whether they are added before or after clear_env.
This controls the direct Codex child’s environment. It is not OS or same-user isolation: the child can still access files, process metadata, sockets, and other resources allowed to its user and sandbox.
Sourcepub fn timeout_secs(self, seconds: u64) -> Self
pub fn timeout_secs(self, seconds: u64) -> Self
Set the command timeout in seconds.
Sourcepub fn termination_grace(self, duration: Duration) -> Self
pub fn termination_grace(self, duration: Duration) -> Self
How long a cancelled run’s process group gets to exit before it is killed. Defaults to five seconds.
Applies to cancellable exec methods and buffered client timeouts. They
send SIGTERM, wait this long, send SIGKILL, and await the direct child.
A dropped future does not use it: Drop cannot wait, so it kills
immediately.
Sourcepub fn process_group(self, enabled: bool) -> Self
pub fn process_group(self, enabled: bool) -> Self
Whether each run gets its own process group. On by default.
With a group of its own, cancelling a run reaches the subprocesses codex spawned for tool use, not just codex itself (#78). That is the right contract for a supervisor that cancels programmatically.
Opting out puts the child in the parent’s group, so a terminal Ctrl-C reaches the whole run directly. Then a wrapper-side kill reaches only the direct child, and its subprocesses survive. That is the right contract for a terminal-attached host that shells out synchronously and treats the terminal as the supervisor.
Matches claude-wrapper’s option of the same name. No effect on
non-unix targets, which have no process groups.
Sourcepub fn arg(self, arg: impl Into<String>) -> Self
pub fn arg(self, arg: impl Into<String>) -> Self
Append a raw global argument passed before any subcommand.
When an exec command has a typed rollout budget, conflicting global
--enable/--disable rollout_budget arguments are suppressed at final
assembly. Codex applies feature toggles after config regardless of argv
order, so retaining one could silently defeat the typed protection.
Sourcepub fn config(self, key_value: impl Into<String>) -> Self
pub fn config(self, key_value: impl Into<String>) -> Self
Add a global config override (-c key=value).
Sourcepub fn enable(self, feature: impl Into<String>) -> Self
pub fn enable(self, feature: impl Into<String>) -> Self
Enable a feature flag globally (--enable <name>).
A rollout_budget toggle is suppressed for an exec command that has a
typed RolloutBudgetConfig.
Sourcepub fn disable(self, feature: impl Into<String>) -> Self
pub fn disable(self, feature: impl Into<String>) -> Self
Disable a feature flag globally (--disable <name>).
A rollout_budget toggle is suppressed for an exec command that has a
typed RolloutBudgetConfig.
Sourcepub fn retry(self, policy: RetryPolicy) -> Self
pub fn retry(self, policy: RetryPolicy) -> Self
Set a default RetryPolicy for all commands.