Complete reference for all Codex CLI commands, flags, and TUI slash commands.
Start an interactive Codex session with the Terminal User Interface.
codex [OPTIONS] [PROMPT]Arguments:
[PROMPT]- Optional initial user message to start conversation
Options:
Model & Provider:
-m, --model <MODEL>- Model to use (e.g.,gpt-5-codex,o3)--model-provider <PROVIDER>- Provider frommodel_providersconfig
Approval & Sandbox:
-a, --ask-for-approval <POLICY>- Approval policy:untrusted,on-failure,on-request,never--sandbox <MODE>- Sandbox mode:read-only,workspace-write,danger-full-access--full-auto- Shorthand for--sandbox workspace-write --ask-for-approval on-request--yolo- Shorthand for--dangerously-bypass-approvals-and-sandbox--dangerously-bypass-approvals-and-sandbox- No sandbox, no approvals (use with caution)
Working Directory:
-C, --cd <DIR>- Change working directory before starting--add-dir <DIR>- Add additional writable directory (can be specified multiple times)
Configuration:
-c, --config <KEY=VALUE>- Override config value (e.g.,-c model="o3")--profile <PROFILE>- Use specific profile from config.toml--skip-git-repo-check- Don't require Git repository
Input/Output:
-i, --image <PATH>- Attach image(s) to initial prompt (comma-separated)
Other:
-h, --help- Print help-V, --version- Print version
Examples:
# Basic interactive session
codex
# Start with a prompt
codex "Fix the build errors"
# Use specific model
codex --model o3 "Review this PR"
# Read-only mode
codex --sandbox read-only
# With image input
codex --image screenshot.png "Explain this error"
# Change working directory
codex --cd /path/to/project
# Multiple writable directories
codex --cd frontend --add-dir ../backend --add-dir ../sharedRun Codex in non-interactive mode for automation.
codex exec [OPTIONS] <PROMPT>
codex exec [OPTIONS] resume [RESUME_OPTIONS]Arguments:
<PROMPT>- User prompt to execute
Resume Subcommand:
codex exec resume [OPTIONS]
codex exec resume --last
codex exec resume <SESSION_ID>Options:
Model & Provider:
-m, --model <MODEL>- Model to use--model-provider <PROVIDER>- Provider from config
Approval & Sandbox:
-a, --ask-for-approval <POLICY>- Approval policy (typicallyneverfor exec)--sandbox <MODE>- Sandbox mode (default:read-only)--full-auto- Enable workspace writes with on-request approvals
Output:
--json- Output JSONL events instead of human-readable text-o, --output-last-message <FILE>- Write final message to file--output-schema <FILE>- JSON Schema for structured output
Configuration:
-c, --config <KEY=VALUE>- Override config value--profile <PROFILE>- Use specific profile--skip-git-repo-check- Don't require Git repository
Other:
-h, --help- Print help
Examples:
# Basic exec (read-only)
codex exec "Count lines of code in this project"
# With file edits
codex exec --full-auto "Fix linting errors"
# JSON output
codex exec --json "Analyze performance bottlenecks"
# Structured output
codex exec --output-schema schema.json "Extract project metadata"
# Save final message
codex exec -o result.txt "Summarize changes"
# Resume previous session
codex exec resume --last "Continue the refactoring"
codex exec resume 01933e84-1234-7890-abcd "Add more tests"Resume an interactive session in the TUI.
codex resume [OPTIONS]
codex resume --last
codex resume <SESSION_ID>Arguments:
<SESSION_ID>- UUID of session to resume (optional)
Options:
--last- Resume most recent session- All standard TUI options (
--model,--sandbox, etc.)
Examples:
# Show picker of recent sessions
codex resume
# Resume last session
codex resume --last
# Resume specific session
codex resume 01933e84-1234-7890-abcd-ef0123456789Authenticate with OpenAI/ChatGPT.
codex login [OPTIONS]Options:
--with-api-key- Read API key from stdin (for usage-based billing)
Examples:
# ChatGPT login (default)
codex login
# API key login
printenv OPENAI_API_KEY | codex login --with-api-key
# From file
codex login --with-api-key < my_key.txtNotes:
- ChatGPT login opens browser at
localhost:1455 - API key never appears in shell history (use stdin)
- Credentials stored in
~/.codex/auth.json
Manage Model Context Protocol servers.
codex mcp <SUBCOMMAND>Subcommands:
Add an MCP server to config.
codex mcp add [OPTIONS] <NAME> [--] <COMMAND> [ARGS]...Arguments:
<NAME>- Server identifier<COMMAND>- Launch command[ARGS]...- Command arguments
Options:
--env <KEY=VALUE>- Set environment variable (can be repeated)
Example:
codex mcp add docs -- npx -y @anthropic-ai/mcp-server-docs
codex mcp add my-server --env API_KEY=secret -- node server.jsList configured MCP servers.
codex mcp list [--json]Options:
--json- Output as JSON
Example:
codex mcp list
codex mcp list --json | jqShow details for one MCP server.
codex mcp get <NAME> [--json]Arguments:
<NAME>- Server identifier
Options:
--json- Output as JSON
Example:
codex mcp get docs
codex mcp get docs --json | jq .toolsRemove an MCP server from config.
codex mcp remove <NAME>Arguments:
<NAME>- Server identifier
Example:
codex mcp remove docsAuthenticate to an OAuth-enabled MCP server.
codex mcp login <NAME>Arguments:
<NAME>- Server identifier
Requirements:
- Server must support OAuth
experimental_use_rmcp_client = truein config
Example:
codex mcp login figmaLog out from an OAuth-enabled MCP server.
codex mcp logout <NAME>Arguments:
<NAME>- Server identifier
Example:
codex mcp logout figmaRun Codex as an MCP server.
codex mcp-serverExposes two tools:
codex- Run a Codex sessioncodex-reply- Continue a session
Example (with MCP Inspector):
npx @modelcontextprotocol/inspector codex mcp-serverSee Advanced Guide for details.
Test sandbox behavior on your platform.
codex sandbox macos [--full-auto] <COMMAND> [ARGS]...
codex sandbox linux [--full-auto] <COMMAND> [ARGS]...Aliases:
codex debug seatbelt(macOS)codex debug landlock(Linux)
Arguments:
<COMMAND>- Command to run in sandbox[ARGS]...- Command arguments
Options:
--full-auto- Useworkspace-writesandbox instead ofread-only
Examples:
# Test read-only sandbox (macOS)
codex sandbox macos ls /
# Test workspace-write sandbox (Linux)
codex sandbox linux --full-auto touch /tmp/test.txt
# Test network access (should fail in read-only)
codex sandbox macos curl https://example.comGenerate shell completion scripts.
codex completion <SHELL>Shells:
bashzshfish
Examples:
# Install Bash completions
codex completion bash > /usr/local/etc/bash_completion.d/codex
# Install Zsh completions
codex completion zsh > /usr/local/share/zsh/site-functions/_codex
# Install Fish completions
codex completion fish > ~/.config/fish/completions/codex.fishCommands available in the interactive TUI composer (type / to see menu).
Show session status and configuration.
/status
Displays:
- Model and provider
- Approval policy and sandbox mode
- Working directory and writable roots
- MCP server connection status
- Token usage (if available)
- Rate limits (if available)
Change model mid-session.
/model <MODEL_NAME>
Examples:
/model o3
/model gpt-5-codex
/model gpt-4o
Notes:
- Requires model to be supported by current provider
- Does not change provider
Change approval policy mid-session.
/approvals
Opens picker with options:
- Read Only
- Auto
- Full Access
Note: Also accessible via /sandbox alias
Initialize a new conversation (clear current session).
/init
Effect:
- Clears transcript
- Keeps same model, approval policy, sandbox mode
- Resets token count
Run a custom prompt from ~/.codex/prompts/.
/prompts:<name> [ARGS...]
Examples:
/prompts:draftpr feature_name=auth
/prompts:review FILE=src/main.rs FOCUS=error_handling
See Prompts Reference for details.
Composer:
Enter- Send messageCtrl+CorCmd+C- Copy selected textCtrl+VorCmd+V- Paste (including images)@- Trigger file searchTaborEnter- Select file from searchEsc- Cancel file search / Enter backtrack modeEscEsc- Enter edit previous message mode
Navigation:
↑/↓- Scroll transcriptPgUp/PgDn- Page up/downHome/End- Jump to top/bottom
Backtrack Mode:
Esc(in empty composer) - Prime backtrack modeEsc(repeatedly) - Navigate to older user messagesEnter- Select message to editEsc(in preview) - Cancel backtrack
Override default home directory (~/.codex).
export CODEX_HOME=/custom/path
codexOverride API key (exec mode only).
export CODEX_API_KEY=sk-...
codex exec "Task"API key for authentication (alternative to codex login).
export OPENAI_API_KEY=sk-...
printenv OPENAI_API_KEY | codex login --with-api-keyOverride OpenAI API base URL.
export OPENAI_BASE_URL=https://custom.api.endpoint
codexControl log verbosity.
export RUST_LOG=codex_core=debug
codexLevels:
error- Errors only (default for exec)warn- Warnings and errorsinfo- Info messages (default for TUI)debug- Debug messagestrace- Verbose trace
Disable colored output.
export NO_COLOR=1
codex exec "Task"codex exec:
0- Success1- Generic error2- Configuration error3- Authentication error4- API error5- Tool execution error130- Interrupted by user (Ctrl+C)
codex (TUI):
0- Normal exit1- Error during startup130- Interrupted by user (Ctrl+C)
When the same setting is specified in multiple places:
- Command-line flag (highest priority)
-c/--configflag (e.g.,-c model="o3")- Profile (via
--profileorprofilein config.toml) - config.toml (root level)
- Built-in default (lowest priority)
Example:
# config.toml has:
# model = "gpt-5"
# profile = "default"
#
# [profiles.fast]
# model = "gpt-4o"
codex --profile fast --model o3 "Task"
# Uses: o3 (flag overrides profile)
codex --profile fast "Task"
# Uses: gpt-4o (profile overrides config.toml root)
codex "Task"
# Uses: gpt-5 (config.toml root)codex --sandbox read-only "Review changes in this PR"codex --full-auto "Fix all build errors and run tests"codex --sandbox workspace-write "Add unit tests for src/auth.rs"codex resume --last
# In TUI, work on task
# Exit with Ctrl+D
cat ~/.codex/sessions/$(ls -t ~/.codex/sessions/ | head -1)/transcript.jsoncodex exec --json "Find security vulnerabilities" | jq '.items[] | select(.type == "agent_message")'codex --cd apps/frontend --add-dir ../backend --add-dir ../shared "Refactor API client"- Getting Started - Basic usage and tips
- Config Reference - Configuration options
- Sandbox & Approvals - Security model
- Exec Reference - Non-interactive mode details
- Custom Prompts - Slash command customization