CodeVetter
← All unpacks
CodeVetter · Repo Unpack evidence

openai/codex

Scanned commit a1f40f3f13 dated 2026-09-22 — last upstream commit. Generated by codevetter 1.12.0 on 2026-09-22.

github.com/openai/codex ↗ · 4000 files · 42.5 MB · scan capped

Codex CLI is a coding agent from OpenAI that runs locally on your computer.

Deep analysis by cli:grok via the grok CLI on 2026-09-22 (229s) — every claim below links to its cited source files.

Overview

Codex is OpenAI's local coding-agent CLI and library: a Rust workspace (`codex-rs`) that runs multi-turn agent sessions against model providers, executes tools under an OS sandbox and approval policy, and persists transcripts as rollout JSONL. Users reach it through the `codex` binary (interactive TUI, `exec`, `resume`, MCP, app-server), a thin Node wrapper `@openai/codex`, and TypeScript SDKs. Distinctive pieces are the protocol-typed event stream, execpolicy/sandbox enforcement, and a large crate split that keeps the agent loop, TUI, and app-server JSON-RPC API apart.

System map

The repo is a pnpm/Bazel monorepo whose product lives in `codex-rs`. The `codex-cli` crate's `main.rs` dispatches subcommands into the TUI, non-interactive exec, MCP server, and app-server. `codex-core` owns the agent session, config, tools, models, and rollout persistence. `codex-app-server` exposes a JSON-RPC v2 API over stdio. Builds are Cargo via `just` plus Bazel CI. Storage is local files: `~/.codex/config.toml`, auth.json, and session rollout JSONL under `~/.codex/sessions`. External edges are the Responses/Chat Completions APIs, MCP servers, execve wrappers, and OS sandboxes (Seatbelt on macOS, bubblewrap/Landlock on Linux, restricted tokens on Windows).

Feature catalog

User-facing surface is the `codex` multitool plus the app-server JSON-RPC API and the SDK wrappers. Interactive mode is a full-screen TUI with composer, approval overlays, and slash commands. Headless mode is `codex exec` (and `codex review`) for scripts and CI. Account features cover ChatGPT device-code login, API-key login, and `codex login`. Tooling includes shell, unified exec, apply_patch, MCP servers, skills, web search, and an execpolicy command allow/deny language. Session features include resume, fork, compact, and forking a thread for review.

Data flow

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.

Behavior traces

Three flows dominate. Startup parses CLI args, loads config and auth, builds a Codex session, and either enters the TUI event loop or the exec one-shot loop. A primary turn submits user input, streams a model response, dispatches tool calls under approval and sandbox, and records rollout items until `TurnComplete`. Persistence is continuous during the turn (rollout appends) and finalized on shutdown or resume. App-server clients follow the same core path after a JSON-RPC translation step.

Testing signals

Rust tests use `cargo nextest` through `just test -p <crate>`, not raw `cargo test`. Core favors integration tests in `codex-rs/core/tests` (and `core/suite`) built on `core_test_support::responses`, which mounts SSE fixtures with `wiremock` and drives a `TestCodex`. The TUI uses `insta` snapshot tests. App-server tests speak the public JSON-RPC API via `TestAppServer`. CI is Bazel-first (`blocking-ci.yml`, `bazel.yml`) plus `cargo-deny`, codespell, and CLA checks. Python tooling under `scripts/` has its own pytest setup. Large areas — real OS sandbox integration, live provider calls, and Seatbelt-under-Seatbelt — are intentionally skipped when `CODEX_SANDBOX` or `CODEX_SANDBOX_NETWORK_DISABLED` is set.

Risk map

The highest-risk surfaces are command execution, the sandbox policy resolver, auth token storage, and the app-server stdio API that can drive all of the above. `codex-core` is an explicit blast-radius hotspot the repo asks contributors not to grow. Large orchestration files (`chatwidget.rs`, `app.rs`, `chat_composer.rs`, `codex.rs`) are fragile coupling points. History compaction and context fragments can invalidate the model prompt cache or exceed token caps. Sandbox escapes are the security property the project exists to protect; tests often skip them under nested sandbox. Legacy v1 app-server methods still exist and must not gain new surface.

Extension points

Codex is extended by adding a tool spec and handler, an MCP server entry, a feature flag, a slash command, a CLI subcommand, or an app-server v2 method. Model providers plug in through `WireApi` and config `model_providers`. Skills, execpolicy rules, and sandbox policies are user-level extension points that do not require a fork. New crates are preferred over new modules in `codex-core`. Protocol extensions must update serde and ts-rs annotations together and regenerate schema fixtures.

Contributor handoff

Work in `codex-rs` unless the task is the Node launcher or the TS/Python SDK. Read AGENTS.md before editing. Prefer a new crate or a new module over growing `codex-core`, `chatwidget.rs`, or `app.rs`. Run `just fmt` after edits and `just test -p <crate>` for the crate you touched. Do not hand-edit generated schema without the just recipe. Do not touch sandbox env-var constants. Match existing clap, serde, and ratatui styles. Integration tests, not unit tests, are required for agent-loop changes.

Languages

LanguageFilesShare of source
Rust473979%
TypeScript76413%
JSON367docs/config
Python1983%
Markdown182docs/config
TOML1773%
SQL711%
YAML60docs/config

Start reading here

Probable source entrypoint: codex-rs/ — inferred from the directory tree and manifest, not the upstream docs.

Source roots

codex-rs/ (3494 files) sdk/ (121 files) third_party/ (60 files)

Source layout — codex-rs/

PathFiles
codex-rs/agent-graph-store/6
codex-rs/agent-identity/2
codex-rs/agent-roles/5
codex-rs/analytics/28
codex-rs/ansi-escape/3
codex-rs/app-server-client/5
codex-rs/app-server-daemon/31
codex-rs/app-server-protocol/55
codex-rs/app-server-protocol-noop-macros/2
codex-rs/Cargo.toml1
codex-rs/README.md1

Repository structure

Top-level pathFiles
codex-rs/3494
sdk/121
.github/113
third_party/60
scripts/58
patches/31
tools/30
bazel/23

Docs found: AGENTS.mdREADME.mddocs/CLA.mddocs/agents_md.mddocs/authentication.mddocs/config.mddocs/contributing.mddocs/example-config.mddocs/exec.mddocs/execpolicy.md

Package

package.json — codex-monorepo, 1 declared dependencies.

prettier

CI & config entrypoints

Structural health signals

Average score 5/10 across 96 analyzed source files; 96 hotspots surfaced.

These are deterministic review leads — size, churn, and structural signals — not proof of a bug in this project.

Recent history