# Data flow — openai/codex

> Canonical page: https://codevetter.com/unpack/codex/data-flow

# Data flow — openai/codex

Scanned commit a1f40f3f1326eff7c81b860a4f4e27c1be186e10 (2026-09-22). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

A user prompt enters either as a TUI `Op::UserTurn`, an exec submit, or an app-server `turn/start` params object. Core enqueues it on the session submission channel. `submission_loop` turns it into model input: prior rollout items plus a bounded developer/user context built from `core/context` fragments. The model streams Responses events; tool calls are dispatched by the tool router, their outputs are appended as function-call items, and the loop continues until the turn completes. Side effects (shell stdout, patch files, MCP results) are approved, sandboxed, then written back into the event stream and the rollout JSONL. Clients render `Event` values; nothing rewrites history except explicit compact, which summarizes and replaces older items under a size cap.
- `ModelClient::stream` posts to `/responses` or the Chat Completions endpoint. SSE frames are parsed into internal response items (`ResponseItem`) that the session converts into protocol events and rollout records. — [codex-rs/core/src/client.rs#L1-L220](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/core/src/client.rs#L1-L220) [codex-rs/core/src/client.rs#L400-L700](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/core/src/client.rs#L400-L700)
- Shell output crosses a sandbox boundary. The orchestrator builds a `SandboxCommand`, asks the approval policy (`AskForApproval` plus execpolicy), then `spawn`s via the platform sandbox. Stdout/stderr are captured, truncated, and emitted as `ExecCommandEnd`. — [codex-rs/core/src/sandboxing/mod.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/core/src/sandboxing/mod.rs) [codex-rs/core/src/tools/router.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/core/src/tools/router.rs) [docs/execpolicy.md](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/docs/execpolicy.md)
- The TUI does not own business state. `ChatWidget` subscribes to core `Event`s, maps them to ratatui lines, and submits `Op`s when the composer submits or an approval overlay resolves. Transcript rendering helpers live in `tui/src/history_cell.rs` and wrapping helpers in `tui/src/wrapping.rs`. — [codex-rs/tui/src/chatwidget.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/tui/src/chatwidget.rs) [codex-rs/tui/src/app.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/tui/src/app.rs) [codex-rs/tui/src/wrapping.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/tui/src/wrapping.rs)
- Auth data flows from `auth.json` or `CODEX_API_KEY` into `AuthManager::auth()`, which attaches a bearer token on `ModelClient` requests. Tokens are refreshed by the login crate; the CLI never puts the API key on the command line of the model request. — [codex-rs/login/src/auth/manager.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/login/src/auth/manager.rs) [docs/authentication.md](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/docs/authentication.md) [codex-rs/core/src/client.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/core/src/client.rs)
- Config override precedence is CLI flags over profile over project `.codex/config.toml` over user `config.toml` over system config. The resolved `Config` is the only object the session reads after startup. — [codex-rs/core/src/config/mod.rs](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/codex-rs/core/src/config/mod.rs) [docs/config.md](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/docs/config.md) [docs/example-config.md](https://github.com/openai/codex/blob/a1f40f3f1326eff7c81b860a4f4e27c1be186e10/docs/example-config.md)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
