Overview
Thecodex-tui crate implements the default interactive mode for Codex CLI, launched when you run codex without subcommands.
Technology Stack
- Ratatui 0.29.0 — Terminal UI framework
- Crossterm — Cross-platform terminal manipulation
- Custom patches — Forked ratatui and crossterm for color query support
Architecture Components
App State Management
The TUI follows a centralized state model:Rendering Pipeline
State Update
Events are processed and update the app state, potentially triggering
codex-core operations.Style System
The TUI follows strict style conventions defined incodex-rs/tui/styles.md:
Color Palette
Semantic Colors
Colors are used semantically, not decoratively:Cyan
User input, selection, status indicators
Green
Success messages and additions
Red
Errors, failures, deletions
Magenta
Codex agent identity
Styling Conventions
The TUI uses Ratatui’sStylize trait for concise styling:
Basic Patterns
Style Helper Priority
Prefer Stylize helpers
Use
.dim(), .bold(), .cyan(), .italic(), .underlined() instead of manual Style construction.Compactness Guidelines
FromAGENTS.md TUI styling rules:
Compactness: prefer one-line forms
Compactness: prefer one-line forms
- Prefer the form that stays on one line after rustfmt
- If only one of
Line::from(vec![...])orvec![...].into()avoids wrapping, choose that - If both wrap, pick the one with fewer wrapped lines
- Don’t refactor between equivalent forms without readability gain
Text Wrapping
The TUI uses dedicated wrapping utilities:Prefix helpers
Prefix helpers
For prefixing lines (e.g., bullet points), use
prefix_lines from line_utils:Key Components
Conversation View
The main conversation rendering:- Turn items — User messages, agent messages, reasoning
- Tool execution — Command output, file changes, MCP calls
- Approvals — Interactive prompts for commands/file changes
- Streaming — Real-time delta updates
Bottom Pane
Input and status area:- Input field — Multi-line text input
- Status indicators — Model, sandbox mode, approval policy
- Shortcuts — Quick action hints
codex-rs/tui/src/bottom_pane/AGENTS.md for implementation details.
Diff Visualization
Syntax-highlighted diffs for file changes:- syntect integration for syntax highlighting
- similar crate for diff generation
- Inline diff rendering with line numbers
- Collapse/expand for large changes
Testing Strategy
The TUI uses snapshot testing viainsta:
Snapshot Tests
Requirement: Any UI change must include corresponding snapshot coverage.
Why Snapshot Tests?
- Visual regression detection — Catch unintended UI changes
- Review-friendly — Diffs show exactly what changed visually
- Fast feedback — No need for manual UI testing
- Future-proof — Changes are explicit and reviewable
Development Workflow
FromAGENTS.md TUI development guidelines:
Performance Considerations
Efficient Rendering
- Frame diffing — Ratatui only updates changed cells
- Lazy evaluation — Widgets built on demand
- Scroll virtualization — Only render visible content
- Delta streaming — Incremental updates from
codex-core
Memory Management
- Bounded buffers — Limit conversation history in memory
- On-demand loading — Load full history from disk when needed
- String interning — Reuse common strings (status indicators, etc.)
Accessibility
Keyboard Navigation
All TUI functionality is keyboard-accessible:- Arrow keys — Navigation
- Tab/Shift+Tab — Focus cycling
- Enter — Submit/confirm
- Esc — Cancel/back
- Ctrl+C — Interrupt/exit
Screen Reader Support
Terminal content is naturally screen-reader friendly:- Plain text rendering
- Semantic color usage
- Clear status indicators
- No mouse-only interactions
Platform-Specific Behavior
Windows Terminal (WSL 2)
WhenWT_SESSION is set:
- Fall back to native Windows toast notifications
- OSC 9 sequences not implemented in Windows Terminal
- Approval prompts surface even when terminal is backgrounded
macOS Notifications
Supports custom notification scripts via config:terminal-notifier in docs.
Customization
The TUI respects terminal color schemes:- Uses ANSI colors (adapt to theme)
- No hardcoded RGB values
- Respects terminal background
- Works with light and dark themes
Custom colors are avoided to ensure compatibility across terminal themes.
Next Steps
Rust Crates
Explore the full workspace structure
Sandboxing
Platform-specific security isolation