Codex Command-Line Tool
Codex CLI is the official command-line tool, written in Rust; it is lightweight and efficient, ideal for terminal enthusiasts.
Install the CLI
Codex CLI supports macOS, Linux, and Windows (experimental).
npm install
Global installation via npm
Install using npm
npm
install
-g
@
openai
/
codex
Verify the installation
codex
--version
Install via Homebrew
Install via Homebrew
On macOS, use Homebrew
brew
install
codex
Update the CLI
Update the version
Update via npm
npm
install
-g
@
openai
/
codex
@
latest
Update via Homebrew
brew upgrade codex
First-time use
The first time you run Codex, it will guide you through authentication:
Launch Codex
Start the interactive interface
codex
Or specify an initial task
codex
"Explain this project structure"
Codex will open a browser for authentication:
- Sign in with a ChatGPT account
- Or use an OpenAI API Key
- After authorization, return to the terminal to continue
Interactive TUI
By default, the CLI enters Terminal User Interface (TUI) mode, providing an immersive experience.
TUI interface areas
| Area | Function |
|---|---|
| Message area | Displays conversation history, tool calls, and execution results |
| Input area | Bottom input box for sending prompts |
| Status bar | Displays the model, context usage, and thread information |
TUI mode settings
TUI configuration
~/.codex/config.toml
[tui]
Alternate screen mode
alternate_screen = "auto" # auto | always | never
Preserve scroll history when alternate screen is disabled
alternate_screen = "never"
Alternate screen mode lets Codex use a separate screen and restores the original terminal state on exit.
Approval mode
Approval mode controls Codex's confirmation behavior before performing actions.
Four modes
| Mode | Description | Behavior |
|---|---|---|
| suggest | Suggest mode | Codex offers suggestions but does not execute |
| auto-edit | Auto-edit | Automatically performs file edits; commands require confirmation |
| full-auto | Fully automatic | Automatically performs all actions (use with caution) |
| interactive | Interactive mode | Ask before sensitive operations (default) |
Set the Approval mode
Specify the mode on the command line
codex
--approval-mode
full-auto
Or switch within a session
/
approval full-auto
In full-auto mode, Codex automatically performs all actions, including deleting files; use with caution.
Sandbox mode
Sandbox mode restricts Codex's access to files and commands.
| Mode | File modification | Command execution | Network access |
|---|---|---|---|
| read-only | Forbid | Forbid | Forbid |
| workspace-write | Workspace only | Allowed | Forbid |
| danger-full-access | Allowed | Allowed | Allowed |
Set the Sandbox mode
Read-only mode
codex
--sandbox
read-only
Workspace-write mode (recommended)
codex
--sandbox
workspace-write
Full access mode (dangerous)
codex
--sandbox
danger-full-access
Slash commands
The CLI provides a rich set of slash commands:
| Command | Function |
|---|---|
/model |
Switch models (e.g. /model gpt-5.4-mini) |
/fast |
Toggle Fast mode |
/plan |
Enter plan mode |
/review |
Review code changes |
/new |
Start a new session |
/resume |
Resume a history session |
/fork |
Clone the current session into a new thread |
/compact |
Compact the context history |
/status |
Show session status |
/clear |
Clear the screen |
/quit |
Exit Codex |
Command usage examples
Slash commands
Switching models
/
model gpt-
5.4
-mini
Plan mode
/
plan Implement a user authentication system
View status
/
status
Shell command execution
Run Shell commands directly in the CLI:
Execute the command
Execute commands starting with !
!
ls
-la
Run git commands
!
git status
View processes
!
ps
aux
Command confirmation
Dangerous commands require confirmation:
- Delete files (rm)
- Terminate processes (kill)
- Modify system configuration
Image input
The CLI supports attaching images as context:
Attach an image
Attach a screenshot
codex
-i
screenshot.png
Attach a design mockup
codex
--image
design.png
"Implement the page based on this design"
Multiple images
codex
-i
img1.png
-i
img2.png
Image use cases
- Analyze error information from screenshots
- Convert UI design mockups to code
- Interpret chart data
Non-interactive mode (exec)
Use the exec command to run single tasks, suitable for scripts and CI/CD:
exec command
Run a single task
codex
exec
"Review the code and output a report"
Output to a file
codex
exec
"Generate a README"
-o
README.md
Use a specific model
codex
exec
-m
gpt-
5.4
-mini
"Analyze the project structure"
Full-auto mode
codex
exec
--full-auto
"Run the tests and fix failures"
Common exec parameters
| Parameters | Description |
|---|---|
-m |
Specify model |
-o |
Output to a file |
--full-auto |
Fully automatic execution |
--ephemeral |
Do not save session files |
--json |
JSON output format |
Keyboard shortcut
| Keyboard shortcut | Function |
|---|---|
Enter |
Send the message |
Shift+Enter |
Newline |
Ctrl+C |
Interrupt operation |
Ctrl+C (两次) |
Exit Codex |
Ctrl+D |
Exit (when input is empty) |
Ctrl+R |
Search history |
Up/Down |
Browse history |
Tab |
Autocompletion |
Esc Esc |
Edit the previous message |
Ctrl+O |
Copy the last response |
Common questions
Q: Windows support status?
Native Windows support is experimental; WSL2 is recommended for the best experience.
Q: How do I disable the alternate screen?
Use codex --no-alt-screen Or configure alternate_screen = "never"。
Q: Command not found?
Make sure PATH includes the npm global installation directory, or install via Homebrew.
Q: How do I view detailed logs?
Logs are located at ~/.codex/log/ directory.