codex-rs directory is the root of a Cargo workspace containing the complete Rust implementation of Codex CLI.
Workspace Members
The workspace includes 60+ crates organized by functionality. All crate names are prefixed withcodex-.
Naming Convention: The
core folder contains the codex-core crate, tui contains codex-tui, etc.Core Crates
These crates form the foundation of Codex CLI:codex-core
Business Logic Library
The core business logic for Codex, designed as a reusable library crate.Responsibilities:
- Conversation and turn management
- Model interaction and streaming responses
- Tool execution and sandboxing coordination
- Configuration loading and validation
- Session state management
- macOS: Expects
/usr/bin/sandbox-exec(Seatbelt) - Linux: Expects binary to handle
codex-linux-sandboxarg0 - All: Supports
--codex-run-as-apply-patchfor virtual apply_patch CLI
codex-cli
Multitool CLI
The main CLI multitool that provides all Codex functionality via subcommands.Subcommands:
- Default (no subcommand) — Launches TUI
exec— Headless executionapp-server— JSON-RPC serversandbox— Sandbox testingmcp— MCP server managementconfig— Configuration utilities
codex-tui
Terminal User Interface
Fullscreen terminal interface built with Ratatui.Features:
- Real-time conversation rendering
- Interactive approvals and prompts
- Diff visualization
- Keyboard-driven navigation
- See TUI Architecture for details
codex-exec
Headless CLI
Non-interactive CLI for automation and programmatic use.Usage:Features:
- Non-interactive execution
- Output to stdout
- Ephemeral mode (no session persistence)
- RUST_LOG support for debugging
codex-app-server
JSON-RPC Server
JSON-RPC 2.0 server for IDE integrations (VS Code, etc.).Protocol:
- Bidirectional JSON-RPC over stdio or WebSocket
- Thread/Turn/Item primitives
- Streaming notifications
- Approval flows
- Official VS Code extension
- Custom integrations via protocol
Sandbox & Security Crates
Platform-specific sandboxing implementations:codex-linux-sandbox
codex-linux-sandbox
Linux sandboxing using Landlock and Bubblewrap.Components:
- Standalone
codex-linux-sandboxexecutable - Library exposing
run_main()for arg0 routing - Vendored bubblewrap for filesystem isolation
- Legacy: Landlock + mount protections
- Modern: Bubblewrap pipeline (feature gated)
- Read-only by default via
--ro-bind / / - Writable roots with
--bind - Protected paths (
.git,.codex) re-applied as read-only - PID namespace isolation via
--unshare-pid - Network isolation via
--unshare-net - Managed proxy mode with internal routing bridge
codex-process-hardening
codex-process-hardening
Cross-platform process hardening applied pre-main.Hardening Steps:
- Disable core dumps
- Disable ptrace attach (Linux/macOS)
- Remove dangerous environment variables
LD_PRELOADDYLD_*variables
codex-execpolicy & codex-execpolicy-legacy
codex-execpolicy & codex-execpolicy-legacy
Execution policy management for trusted commands.Purpose:
- Allow-lists for approved commands
- Session-scoped approvals
- Policy persistence
- Trust decision tracking
Protocol & Communication Crates
codex-protocol
Core protocol types and message definitions.Contents:
- Agent instructions and prompts
- System message templates
- Collaboration modes
- Personality presets
codex-app-server-protocol
App Server JSON-RPC schema and types.Features:
- TypeScript generation
- JSON Schema export
- Experimental API gating
- Wire format validation
codex-rmcp-client
Remote MCP (Model Context Protocol) client.Purpose:
- Connect to MCP servers
- Tool discovery and invocation
- Resource access
- OAuth flows
codex-mcp-server
Codex as an MCP server.Usage:
Integration Crates
Model Provider Integrations
Model Provider Integrations
- codex-lmstudio — LM Studio integration
- codex-ollama — Ollama integration
- codex-backend-client — OpenAI backend client
- codex-responses-api-proxy — Responses API proxy server
Configuration & State
Configuration & State
- codex-config — Configuration loading and validation
- codex-state — Session state management
- codex-cloud-requirements — Requirements.toml parsing
- codex-cloud-tasks — Task execution framework
Developer Experience
Developer Experience
- codex-login — Authentication flows
- codex-feedback — Feedback submission
- codex-hooks — Git hook management
- codex-skills — Skill discovery and loading
- codex-secrets — Secret management
Utility Crates
Theutils/ directory contains shared utilities:
Specialized Crates
File Operations
File Operations
- codex-file-search — File search and indexing
- codex-apply-patch — Patch application logic
Terminal & UI
Terminal & UI
- codex-ansi-escape — ANSI escape sequence handling
- codex-shell-command — Shell command parsing
- codex-shell-escalation — Privilege escalation
- codex-stdio-to-uds — stdio to Unix domain socket bridge
Observability
Observability
- codex-otel — OpenTelemetry integration
- codex-network-proxy — Network proxy support
Testing
Testing
- codex-test-macros — Test utilities
- app-server-test-client — App server test client
- debug-client — Debug client for testing
Workspace Configuration
The workspace uses shared configuration incodex-rs/Cargo.toml:
Edition & Versioning
Dependency Management
- All workspace crates share dependency versions
- Internal crates use path dependencies
- External dependencies locked in workspace
- Custom patches for ratatui, crossterm, tungstenite
Build Configuration
Linting
Workspace enforces strict Clippy lints:expect_used = "deny"unwrap_used = "deny"manual_*patterns denied- Format args must be inlined
- Redundant operations denied
Bazel Integration
The workspace supports Bazel builds alongside Cargo:runfilesintegration for test resourcescargo-binutility for binary location- Platform-specific build configurations
Next Steps
TUI Architecture
Deep dive into the Ratatui-based interface
Sandboxing
Platform-specific security implementations