# `Codex.CLI.Session`
[🔗](https://github.com/nshkrdotcom/codex_sdk/blob/v0.11.0/lib/codex/cli/session.ex#L1)

Raw `codex` CLI subprocess session.

Sessions are useful for interactive or long-running commands such as:

- `codex`
- `codex resume`
- `codex fork`
- `codex app-server`
- `codex mcp-server`

The caller process receives raw `erlexec` messages for the spawned process:

- `{:stdout, os_pid, binary}`
- `{:stderr, os_pid, binary}`
- `{:DOWN, os_pid, :process, pid, reason}`

Use `collect/2` to accumulate output until the process exits.

# `result`

```elixir
@type result() :: %{
  command: [String.t()],
  args: [String.t()],
  stdout: String.t(),
  stderr: String.t(),
  exit_code: integer(),
  success: boolean()
}
```

# `t`

```elixir
@type t() :: %Codex.CLI.Session{
  args: [String.t()],
  command: [String.t()],
  os_pid: non_neg_integer(),
  pid: pid(),
  pty?: boolean(),
  receiver: pid(),
  stdin?: boolean()
}
```

# `close_input`

```elixir
@spec close_input(t()) :: :ok | {:error, term()}
```

Closes the subprocess stdin by sending EOF.

# `collect`

```elixir
@spec collect(t(), timeout()) :: {:ok, result()} | {:error, term()}
```

Collects stdout/stderr until the subprocess exits.

# `interrupt`

```elixir
@spec interrupt(t()) :: :ok | {:error, term()}
```

Interrupts the subprocess.

# `send_input`

```elixir
@spec send_input(t(), iodata()) :: :ok | {:error, term()}
```

Sends input bytes to the subprocess stdin.

# `start`

```elixir
@spec start(String.t(), [String.t()], keyword()) :: {:ok, t()} | {:error, term()}
```

Starts a raw subprocess session for `binary_path` and `args`.

# `stop`

```elixir
@spec stop(t()) :: :ok | {:error, term()}
```

Stops the subprocess.

---

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