Comprehensive technical documentation for Codex CLI, OpenAI's terminal-based AI coding agent
This is a comprehensive technical documentation suite covering the implementation details and internals of Codex CLI - OpenAI's sophisticated, Rust-based terminal coding agent.
This documentation focuses on:
- Internal architecture and implementation details
- Rust source code analysis and patterns
- System internals that official docs don't cover
- Development guides for extending Codex
Official user documentation is available at:
- Official Docs: https://github.com/openai/codex/tree/main/docs
- Getting Started: Start there for usage instructions
These docs complement official documentation:
- Official Docs: How to use Codex (configuration, commands, features)
- This Suite: How Codex works internally (architecture, code, patterns)
Coverage: 23 in-depth documents • 250+ pages • 300+ code examples • 50+ architecture diagrams
Required Reading: 00 - Official vs Custom Documentation
Understand the difference:
- Official Docs (OpenAI) = How to use Codex → Go to official docs
- Custom Docs (This Suite) = How Codex works internally → You're here!
- Official Getting Started ← Start here for usage
- 01 - Overview ← Then read this for architecture overview
- 23 - Flow Diagrams ← Visual guides to understand flows
- 02 - Architecture - Complete system design
- 23 - Flow Diagrams - Visual flow references
- 10 - Implementation - Core implementation patterns
- Official config.md ← User configuration guide
- 08 - Configuration ← Internal config system details
- Official sandbox.md ← Security usage guide
- 07 - Security & Sandboxing ← Security implementation
- 06 - Tool System - Tool architecture deep-dive
- 11 - Tool Implementations - Real code examples
- 21 - Tool System Guide - Practical development guide
- Official exec.md ← How to use
codex exec - 22 - Exec Mode Internals ← Implementation details
Understand how Codex CLI is built and why it works the way it does.
| Document | Description | Best For |
|---|---|---|
| 01 - Overview | Introduction, capabilities, and quick start | First-time users |
| 02 - Architecture | System design, components, patterns | Architects, contributors |
| 10 - Implementation | Entry points, event loops, async patterns | Core developers |
How Codex processes prompts and communicates with language models.
| Document | Description | Best For |
|---|---|---|
| 03 - Prompt Processing | Prompt lifecycle and assembly | Understanding context flow |
| 04 - LLM Integration | Model clients, streaming, providers | API integrations |
| 05 - System Prompts | AGENTS.md, custom prompts, hierarchy | Customizing behavior |
The tool system that allows Codex to take actions.
| Document | Description | Best For |
|---|---|---|
| 06 - Tool System | Tool architecture, registry, execution | Building new tools |
| 11 - Tool Implementations | Detailed tool code and examples | Tool developers |
How Codex stays safe and how to configure it.
| Document | Description | Best For |
|---|---|---|
| 07 - Security & Sandboxing | Sandbox modes, approvals, safety | Security auditing |
| 08 - Configuration | Config files, env vars, CLI flags | Setup and deployment |
How Codex manages state and presents information.
| Document | Description | Best For |
|---|---|---|
| 09 - State Management | Sessions, history, diff tracking | Understanding state flow |
| 12 - UI Layer | Terminal UI, rendering, interactions | UI development |
Authentication, external integrations, and code reference.
| Document | Description | Best For |
|---|---|---|
| 13 - Authentication | Auth flows, token management | Auth integration |
| 14 - MCP Integration | Model Context Protocol support | MCP server authors |
| 15 - Code Reference | File index and code navigation | Finding implementations |
| 16 - Hidden Features | Undocumented commands, flags, env vars | Power users, developers |
| 17 - CLI Reference | Complete CLI commands and flags | Command-line users |
| 18 - MCP Development | Building MCP servers from scratch | MCP developers |
Automation, visual references, and optimization.
| Document | Description | Best For |
|---|---|---|
| 19 - Performance | Speed, cost, quality optimization | Tuning and optimization |
| 20 - State Management Guide | Practical state management guide | Session management |
| 21 - Tool System Guide | Practical tool development guide | Tool creators |
| 22 - Exec Mode Internals | Non-interactive automation implementation | CI/CD, scripting |
| 23 - Flow Diagrams | Complete visual flow references | Understanding system flows |
- Start with 01 - Overview for the big picture
- Read 02 - Architecture for system design
- Check 03 - Prompt Processing for request flow
- Explore 16 - Hidden Features for undocumented capabilities
- Read 08 - Configuration for all options
- Review 07 - Security & Sandboxing for security settings
- Check 13 - Authentication for auth setup
- Study 06 - Tool System for architecture
- Review 11 - Tool Implementations for examples
- Reference 15 - Code Reference for finding code
- Read 05 - System Prompts for prompt customization
- Learn about AGENTS.md files and custom prompts
- Check 08 - Configuration for behavior settings
- Discover 16 - Hidden Features for experimental flags and env vars
- Review 14 - MCP Integration for MCP protocol
- Check 04 - LLM Integration for provider support
- Study 13 - Authentication for auth patterns
- Read 02 - Architecture for design patterns
- Study 10 - Implementation for core code
- Review 15 - Code Reference for navigation
For those who want to use Codex effectively:
- 01 - Overview - Learn the basics
- 08 - Configuration - Customize your setup
- 05 - System Prompts - Create custom prompts
- 16 - Hidden Features - Unlock undocumented capabilities
- 07 - Security & Sandboxing - Understand safety
For those who want to contribute code:
- 02 - Architecture - Understand the design
- 10 - Implementation - Core implementation details
- 09 - State Management - How state works
- 06 - Tool System - Tool architecture
- 11 - Tool Implementations - Tool examples
For those building on top of Codex:
- 02 - Architecture - System design
- 04 - LLM Integration - API integration
- 14 - MCP Integration - MCP protocol
- 13 - Authentication - Auth patterns
- 06 - Tool System - Extension points
- Total Documents: 23 comprehensive guides
- Total Words: ~120,000 words
- Code Examples: 300+ with syntax highlighting
- Architecture Diagrams: 50+ ASCII art flow diagrams
- Tables & References: 80+ comparison tables
- Cross-References: 200+ internal links (+ official docs)
- Coverage: Architecture, Tools, Security, Config, State, UI, Integration, Hidden Features, CLI Reference, MCP Development, Performance Tuning, Exec Mode, Flow Diagrams
- ✅ Complete Architecture - Every component and interaction
- ✅ All Tools - Full tool system with implementation details
- ✅ Security Model - Sandboxing, approvals, and safety mechanisms
- ✅ Configuration - Every config option and environment variable
- ✅ Prompt System - How prompts are processed and customized
- ✅ State Management - Sessions, history, and diff tracking
- ✅ LLM Integration - All supported providers and APIs
- ✅ MCP Protocol - Model Context Protocol integration
- Codex Version: Latest development build
- Analysis: 150+ source files, 50,000+ LOC examined
- Rust Components:
codex-rs/core/,codex-rs/cli/,codex-rs/tui/ - System Prompts: All official prompts analyzed
- Validation: All code examples from actual source
Found an issue or want to improve the docs?
- For Documentation Issues: Open an issue describing what's unclear or incorrect
- For Code Questions: Check 15 - Code Reference first
- For Feature Requests: See 02 - Architecture to understand design constraints
| Property | Value |
|---|---|
| Documentation Version | 2.0.0 (Enhanced) |
| Codex CLI Version | Latest Development |
| Last Updated | October 25, 2025 |
| Format | GitHub-flavored Markdown |
| Cross-Referenced | ✅ Linked to official docs |
| Verified | ✅ Code examples checked against source |
Documentation: Technical analysis provided as-is
Codex CLI: Apache License 2.0 © OpenAI
- Official Codex Documentation - User guides from OpenAI (START HERE for usage)
- Codex GitHub Repository - Source code
- Model Context Protocol - MCP specification
- Official vs Custom Comparison - Complete comparison with detailed doc-by-doc analysis
- Analysis Results - Documentation analysis findings
- 00 - Official vs Custom - Understand the relationship
- 23 - Flow Diagrams - Visual system flows
- 15 - Code Reference - Source code navigation
Choose your path:
-
I'm a new user → Official Getting Started first, then 01 - Overview
-
I want to understand internals → 23 - Flow Diagrams then 02 - Architecture
-
I'm building tools/extensions → 06 - Tool System and 11 - Tool Implementations
-
I'm setting up CI/CD → Official exec.md then 22 - Exec Mode Internals
-
I want to see comparisons → Official vs Custom Comparison
Ready to dive in? Start with 23 - Flow Diagrams for visual overviews, or 01 - Overview for architecture introduction!