Purpose: This page documents the prerequisites, repository structure, and local build commands needed to contribute to Codex. For information about the CI/CD pipeline and automated builds, see CI Pipeline and Release Pipeline. For testing strategies and test harness usage, see Testing Infrastructure.
The Codex CLI is implemented in Rust and requires a recent stable Rust toolchain:
edition = "2024" in workspace)The repository uses the 2024 edition of Rust, configured at the workspace level in codex-rs/Cargo.toml74 Individual crates inherit this setting unless overridden.
Platform targets: The CI builds for 8 platforms (see rust-ci.yml for the complete matrix), but for local development you only need your native target. Common targets:
aarch64-apple-darwin (Apple Silicon), x86_64-apple-darwinx86_64-unknown-linux-gnu, x86_64-unknown-linux-muslx86_64-pc-windows-msvcOptional toolchain components:
cargo-nextest for faster test executionsccache for build caching (used in CI, optional locally)Sources: codex-rs/Cargo.toml1-76 README.md1-60 codex-rs/README.md1-102
The repository includes TypeScript packages for the npm distribution wrapper and shell-tool MCP server:
The workspace uses pnpm workspaces configured in pnpm-workspace.yaml1-13 with four packages:
codex-cli - npm distribution wrappercodex-rs/responses-api-proxy/npm - responses API proxy wrappersdk/typescript - TypeScript SDK (if present)shell-tool-mcp - MCP server for shell toolsSources: package.json1-26 pnpm-workspace.yaml1-13 codex-cli/package.json1-23
cmakeThe Rust workspace depends on OpenSSL for musl targets. For development on glibc-based systems (Ubuntu, Fedora, etc.), install:
Ubuntu/Debian:
Fedora/RHEL:
For musl targets (Alpine, static builds), the workspace uses vendored OpenSSL (see codex-rs/core/Cargo.toml126-131).
Landlock/seccomp dependencies: The seccompiler crate is used for Linux sandboxing. These are handled by Cargo automatically but require kernel support at runtime.
Sources: codex-rs/core/Cargo.toml116-143 .github/workflows/rust-ci.yml
The Codex repository is organized as a Cargo workspace (Rust) with an embedded pnpm workspace (TypeScript/Node.js):
Workspace configuration:
workspace.dependencies in codex-rs/Cargo.toml77-299Key crates:
| Crate | Purpose | Binary Name |
|---|---|---|
codex-cli | Multitool CLI entry point, dispatches to TUI/Exec/AppServer | codex |
codex-tui | Interactive terminal UI via ratatui | codex-tui (standalone) |
codex-exec | Headless automation mode | codex-exec (standalone) |
codex-core | Session management, model client, tool execution | (library only) |
codex-app-server | JSON-RPC 2.0 API for IDE integration | (library only) |
codex-protocol | Shared protocol types (Op, Event, Config) | (library only) |
Sources: codex-rs/Cargo.toml1-375 pnpm-workspace.yaml1-13 codex-rs/README.md92-102
The repository uses patched forks of crossterm, ratatui, and tungstenite via Git patches in codex-rs/Cargo.toml362-374 These are handled automatically by Cargo; no submodule initialization is needed.
This installs dependencies for:
codex-cli (npm wrapper)shell-tool-mcp (MCP server)responses-api-proxy (proxy wrapper)Sources: README.md12-44 codex-rs/README.md5-14
From the codex-rs/ directory:
The default build produces:
target/debug/codex - main CLI binarytarget/debug/codex-tui - standalone TUI binarytarget/debug/codex-exec - standalone exec binaryBuild profiles:
cargo build): Fast compilation, includes debug symbolscargo build --release): Optimized, stripped symbols (see codex-rs/Cargo.toml348-356)
codegen-units = 1 for maximum optimizationstrip = "symbols" to minimize binary sizecargo build --profile ci-test): Optimized for fast CI runs (see codex-rs/Cargo.toml357-360)For static binaries (used in CI), add the musl target and build:
The workspace configures vendored OpenSSL for musl targets automatically (see codex-rs/core/Cargo.toml126-131).
Ad-hoc signing is automatic on macOS. For distribution, the release pipeline uses Apple notarization (see rust-release.yml).
The default MSVC toolchain works out of the box. The workspace includes Windows-specific dependencies like windows-sys for sandbox support (see codex-rs/core/Cargo.toml133-139).
The CI uses sccache for distributed build caching. For local development, you can optionally install it:
Sources: codex-rs/Cargo.toml348-375 codex-rs/core/Cargo.toml1-173 .github/workflows/rust-ci.yml
From the repository root:
codex-cli: This package is a thin npm wrapper that downloads platform-specific binaries. It has no build step—binaries are vendored during the release process.
shell-tool-mcp: TypeScript MCP server with build/test scripts:
Configuration in shell-tool-mcp/package.json22-30
Sources: shell-tool-mcp/package.json1-42 codex-cli/package.json1-23 package.json1-26
After building, the codex binary is available at:
The app server expects JSON-RPC 2.0 messages on stdin (stdio mode) or WebSocket connections (ws mode). For testing, use the debug client:
Sources: codex-rs/cli/src/main.rs1-1093 codex-rs/README.md51-73
Verify the build produces a working binary:
Some crates have integration tests in tests/ directories:
For detailed testing strategies, including TestCodex harness and mock servers, see Testing Infrastructure.
Sources: codex-rs/core/Cargo.toml144-169 shell-tool-mcp/package.json22-30
| Task | Command |
|---|---|
| Build all Rust crates | cargo build (from codex-rs/) |
| Build release binary | cargo build --release |
| Run tests | cargo test |
| Run clippy lints | cargo clippy |
| Format Rust code | cargo fmt |
| Install locally | cargo install --path cli |
| Build TypeScript | pnpm --filter <package> run build |
| Format TypeScript | pnpm run format |
RUST_LOG: Control tracing output (e.g., RUST_LOG=codex_core=debug,codex_tui=info)RUSTC_WRAPPER: Set to sccache for build cachingCODEX_HOME: Override default config directory (default: ~/.codex)CODEX_RS_SSE_FIXTURE: Path to SSE fixture for offline tests (see codex-rs/core/src/flags.rs1-7)Adding a Rust dependency:
[workspace.dependencies] in codex-rs/Cargo.toml77-299 if sharedCargo.toml with { workspace = true }cargo update <crate> to update Cargo.lockAdding a TypeScript dependency:
package.jsonpnpm install from repository rootpnpm-lock.yamlSources: codex-rs/Cargo.toml77-375 pnpm-workspace.yaml1-13 codex-rs/core/src/flags.rs1-7
Issue: error: failed to run custom build command for openssl-sys
Issue: error: package collision in the lockfile
Cargo.lock and run cargo build to regenerateIssue: ERR_PNPM_NO_MATCHING_VERSION
package.json engines)Issue: Lockfile is up to date, resolution step is skipped
--frozen-lockfile in CI; use pnpm install (without flag) for local developmentIssue: codex: command not found after cargo build
codex-rs/target/debug/codex, not in PATH. Use cargo install --path cli to install to ~/.cargo/binIssue: Authentication errors when running locally
./target/debug/codex login to authenticate with ChatGPT or API keySources: codex-rs/core/Cargo.toml126-131 package.json20-24 README.md12-44
Refresh this wiki