# `Codex.Exec`
[🔗](https://github.com/nshkrdotcom/codex_sdk/blob/v0.18.1/lib/codex/exec.ex#L1)

Process manager wrapping the `codex` binary via the shared CLI subprocess core.

This module is the implementation behind Codex's historical `:exec`
compatibility selector. That selector names the default core-backed exec JSONL
lane; it does not imply direct ownership of the Erlang `:exec` worker.

Provides blocking and streaming helpers that project core session events into
typed `%Codex.Events{}` structs.

# `exec_opts`

```elixir
@type exec_opts() :: %{
  optional(:codex_opts) =&gt; Codex.Options.t(),
  optional(:thread) =&gt; Codex.Thread.t(),
  optional(:turn_opts) =&gt; map(),
  optional(:continuation_token) =&gt; String.t(),
  optional(:attachments) =&gt; [Codex.Files.Attachment.t()],
  optional(:output_schema_path) =&gt; String.t(),
  optional(:tool_outputs) =&gt; [map()],
  optional(:tool_failures) =&gt; [map()],
  optional(:env) =&gt; map(),
  optional(:clear_env?) =&gt; boolean(),
  optional(:cancellation_token) =&gt; String.t(),
  optional(:timeout_ms) =&gt; pos_integer(),
  optional(:max_stderr_buffer_bytes) =&gt; pos_integer()
}
```

# `cancel`

```elixir
@spec cancel(String.t()) :: :ok
```

Cancels any in-flight exec sessions associated with the provided cancellation token.

# `review`

```elixir
@spec review(term(), exec_opts()) :: {:ok, map()} | {:error, term()}
```

Runs `codex exec review` and accumulates all emitted events.

# `review_stream`

```elixir
@spec review_stream(term(), exec_opts()) :: {:ok, Enumerable.t()} | {:error, term()}
```

Returns a lazy stream of events for `codex exec review`.

# `run`

```elixir
@spec run(String.t(), exec_opts()) :: {:ok, map()} | {:error, term()}
```

Runs codex in blocking mode and accumulates all emitted events.

# `run_stream`

```elixir
@spec run_stream(String.t(), exec_opts()) :: {:ok, Enumerable.t()} | {:error, term()}
```

Returns a lazy stream of events. The underlying process starts on first
enumeration and stops automatically when the stream halts.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
