This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Codex is an AI coding assistant platform forked from OpenAI/codex with extensive enhancements (zapabob extensions). The core is a Rust workspace (codex-rs/) with 69 crates, plus a Next.js GUI (gui/), a Node.js CLI (codex-cli/), and supporting services.
Version: 3.1.0 | Rust edition: 2024 | Toolchain: 1.93.0
# Task runner (just) — working directory is automatically set to codex-rs/
just fmt # Format code (cargo fmt with imports_granularity=Item)
just clippy # Lint all crates
just fix -p <crate> # Auto-fix clippy issues for a specific crate
just test # Run all tests with cargo-nextest
just install # Fetch dependencies, show active toolchain
just fast-build [targets] # Differential build via scripts/fast_build.py
just fast-build-install # Differential build + install via scripts/fast_build.py
just upstream-sync # Fetch/merge upstream and run resolver
just codex # Run codex from source (cargo run --bin codex)
just exec "prompt" # Run codex exec mode
# Direct cargo commands (from codex-rs/)
cargo build --release -p codex-cli # Release build of CLI
cargo install --path cli --force # Install globally
cargo test -p codex-tui # Test a single crate
cargo test --all-features -p codex-core # Test with all features
cargo nextest run --no-fail-fast # Fast test runner (preferred)
cargo clippy -p codex-cli -- -D warnings # Lint a specific crate
# Snapshot tests (TUI uses insta)
cargo test -p codex-tui # Generate .snap.new files
cargo insta pending-snapshots -p codex-tui # Review pending
cargo insta accept -p codex-tui # Accept snapshots
# Dependency checks
cargo shear # Find unused dependencies
cargo deny check # License/security auditjust fast-build codex-cli codex-tui # Differential build
just fast-build-install codex-cli codex-tui # Differential build + install
.\fast_build.ps1 -Task fast-build-install # Windows wrapper around scripts/fast_build.pyjust bazel-codex # Run codex via Bazel
just bazel-test # Run all Bazel tests
just bazel-remote-test # Run tests with remote execution
just build-for-release # Remote release buildsnpm run dev # Dev server (0.0.0.0)
npm run build # Production build
npm run lint # ESLint
npm test # Playwright E2E tests
npm run test:headed # Headed browser testspnpm run format # Prettier check (JSON, MD, YAML, JS)
pnpm run format:fix # Prettier auto-fixThe workspace follows a layered architecture. Key crates and their roles:
cli— Binary entry point (codex). Subcommands: interactive TUI,exec,delegate,agent-create,research,resume, etc.tui— Terminal UI built with ratatui. Renders chat, execution cells, slash commands. Uses insta for snapshot testing.core— Central orchestration engine. Contains:agents/runtime.rs— Sub-agent execution runtimecodex.rs— Main Codex session lifecycleorchestration/— Resource management, task coordinationtools/— Tool specs and execution (shell, file ops, etc.)mcp_dynamic_loader/— Dynamic MCP server loadingmodels_manager/— Model family detection, presets, capabilitiessandboxing/— Platform-specific sandbox (macOS: Seatbelt, Linux: Landlock+seccomp, Windows: Job Objects)
backend-client— HTTP client for OpenAI API. Handles SSE streaming, retries, auth.protocol— Wire protocol types shared between CLI/TUI and app-server.app-server— WebSocket/SSE server for GUI communication. Implementsapp-server-protocol.app-server-protocol— Schema definitions (v2 protocol) for GUI<->server communication. Haswrite_schema_fixturesbinary to regenerate vendored schemas.mcp-server— Codex as an MCP server for external tool integration.config— Configuration types (~/.codex/config.tomlschema). Hascodex-write-config-schemabinary.state— SQLite-backed session/state persistence (via sqlx).exec/exec-server— Command execution layer.deep-research— Multi-source research with citations.supervisor— Agent supervision and lifecycle management.windows-sandbox-rs/linux-sandbox/process-hardening— Platform sandboxing.utils/— Shared utilities (paths, git, caching, sanitization, fuzzy-match, etc.).
User → CLI/TUI → Core Runtime → Backend Client → OpenAI API
↓
MCP Servers ← Tool Execution ← Sandbox Layer
↓
App Server → GUI (WebSocket/SSE)
Next.js 14 app with React, MUI 7, Three.js for 3D visualization, WebXR for VR/AR support. Communicates with the Rust app-server over WebSocket.
YAML-defined specialized agents (code-reviewer, test-gen, sec-audit, researcher, etc.) with token budgets and sandbox policies. Executed via codex delegate or codex delegate-parallel.
- Clippy is strict:
unwrap_usedandexpect_usedare denied (allowed in tests). See workspace lints incodex-rs/Cargo.toml. - Use inline format args:
println!("User {name}")notprintln!("User {}", name)(uninlined_format_args = "deny"). - Prefer iterators/method references over explicit loops/closures (
redundant_closure_for_method_calls = "deny"). - TUI colors: Use ANSI colors only.
Color::Rgb,Color::Indexed, hardcoded white/black/yellow are disallowed in clippy.toml. - Enhanced thresholds: max 5 function args, cognitive complexity 15, max 300 lines/function, error size 128 bytes.
unsafe,transmute,null,uninitialized,zeroedare disallowed.- Format:
cargo fmtwithedition = "2024". Theimports_granularity = "Item"flag is passed viajust fmtbut not in rustfmt.toml (unstable).
- Prettier: printWidth=80, semi=true, trailingComma="all", tabWidth=2.
- No
anytypes, novar. Useconstdefault,async/awaitover.then().
- Use
pretty_assertions::assert_eqfor better diffs. - Use
core_test_support::responseshelpers for mock SSE responses. - TUI: snapshot tests with
insta.
Three security levels available via --sandbox flag:
| Mode | Description |
|---|---|
read-only |
Default. Read files only. |
workspace-write |
Write within workspace directory. |
danger-full-access |
Full system access (requires explicit opt-in). |
OPENAI_API_KEY — Required for API access
RUST_LOG — Log level (e.g., "info", "debug")
CODEX_CONFIG_PATH — Override config location (default: ~/.codex/config.toml)
just write-config-schema # Regenerate config.toml JSON schema
just write-app-server-schema # Regenerate app-server protocol schemaGitHub Actions workflows run: multi-platform Rust builds (Linux/macOS/Windows, x64/ARM64), clippy, fmt, nextest, cargo-deny, codespell, Bazel tests, Playwright GUI tests, and security audits. The CI test profile (cargo-profile ci-test) uses opt-level = 0 and debug = 1 for faster compilation.