Codex CLI
What you'll learn
~15 min- Install Codex CLI via npm or pre-built binary
- Sign in with your ChatGPT account or set up an API key
- Run your first autonomous task in Suggest mode
- Understand the autonomy and sandbox policies
Codex Cloud at chatgpt.com/codex runs async coding tasks in a sandboxed cloud environment and opens PRs when done — no local install required. It’s included with ChatGPT Plus and Pro subscriptions.
See the Cloud Sandbox Cheat Sheet
for current pricing, or set up your sandbox.
By the end of this lesson, you’ll have Codex CLI installed and understand its unique strength: the ability to plan, execute, and iterate on tasks with minimal hand-holding.
What is Codex CLI?
Codex CLI is OpenAI’s open-source command-line coding agent, rewritten in Rust as of early 2026. It’s designed for autonomous task execution — you assign it a task, and it can plan, implement, test, and iterate with minimal guidance, but outputs still require human review. The default model is GPT-5.4 (also available: GPT-5.4-mini for faster/cheaper tasks, GPT-5.3-Codex).
Key features:
- Autonomous multi-step task execution
- Can work with git workflows (including branches) when used inside a git repository
- Sandboxed execution for safety
- Voice input (hold spacebar to dictate), web search, and MCP server support
- Session resume (
codex resume) to pick up where you left off codex execfor non-interactive scripting and CI pipelines- Subagents for parallel task execution
- Open source (Rust)
🔍Mental model: Codex as a junior colleague
Think of Codex CLI like delegating a task to a capable junior colleague. You wouldn’t explain every keystroke — you’d say “Build me a to-do list app” and let them figure out the implementation. Codex works the same way. In its most cautious mode, your colleague checks in before every step (“Should I use localStorage for persistence?”). In a middle mode, they handle file changes on their own but ask before running commands. In full-auto mode, they just deliver the finished result. Like a junior teammate, it can be very helpful but still needs supervision and review. Start cautious while you’re learning to trust the tool.
Codex CLI is under active development (rewritten in Rust in early 2026). If the install commands below don’t work, check the official Codex CLI repository or OpenAI’s documentation for the latest instructions.
Installation
Codex CLI’s sandboxing features work best on Linux/macOS/WSL. Native Windows support is still experimental — use WSL2 for the most reliable experience. The CLI instructions below assume WSL or macOS/Linux.
Step 1: Install Codex CLI
Option A — npm (if you already have Node.js):
npm install -g @openai/codexOption B — Homebrew (macOS):
brew install --cask codexOption C — Pre-built binary (no Node.js needed):
Download the latest binary for your platform from the Codex CLI releases page and add it to your PATH.
Verify (any install method):
codex --versionStep 2: Sign in
The easiest way to authenticate is with your ChatGPT account — no API key needed:
codexOn first launch, Codex will open a device-code sign-in flow in your browser. Sign in with your ChatGPT account and you’re done. This works with any ChatGPT plan (Plus, Pro, Business).
🔍Alternative: API key
If you prefer API-key authentication (or need it for CI/scripting), you can set an OpenAI API key instead:
- Go to platform.openai.com
- Create an account or sign in
- Navigate to API Keys and create a new secret key
- Set it as an environment variable:
export OPENAI_API_KEY="your-key-here"To make this permanent, add the export line to your shell config:
echo 'export OPENAI_API_KEY="your-key-here"' >> ~/.bashrcsource ~/.bashrc(If your shell is zsh — check with echo $SHELL — use ~/.zshrc instead.)
If you use an API key, never commit it to a git repository or share it publicly. Treat it like a password. If you accidentally expose it, revoke it immediately from the OpenAI dashboard and create a new one.
Codex CLI access is included with ChatGPT Plus ($20/mo), Pro ($200/mo), and Business ($30/user/mo) plans. Free and Go plan users get a limited trial. If you’re using API-key auth instead, standard API billing applies — check platform.openai.com/settings.
Your first interaction
Step 1: Create a project folder
mkdir hello-codex && cd hello-codexStep 2: Start Codex CLI
codexStep 3: Give it a task
Create a simple to-do list app in a single HTML file. It should:- Let users type a task and press Enter to add it- Show tasks in a list with checkboxes to mark as done- Have a "Clear completed" button- Dark theme, clean design- Save tasks to localStorage so they persist on refreshCodex will:
- Plan the implementation
- Create the file
- Write the code
- Verify it meets requirements
In Suggest mode, Codex will ask for your approval before each step. Type y to approve or n to reject. Use /mode to switch autonomy levels, or Ctrl+C to quit.
Step 4: Check the result
lscat index.htmlOpen in your browser to test the todo list functionality.
Codex CLI modes
Codex CLI controls autonomy through two independent policies — approval (when it asks permission) and sandbox (what it can access):
| Approval Policy | What it does | Best for |
|---|---|---|
| Untrusted | Asks before every action | Learning, careful work |
| On-request | Makes file changes automatically, asks before commands | General use |
| Never (full auto) | Executes everything autonomously | When you trust the task |
| Sandbox Policy | What it allows |
|---|---|
| Read-only | Can read files but not write |
| Workspace-write | Can write within your project directory |
| Danger-full-access | Unrestricted file and network access |
The --full-auto convenience flag still works as a shortcut. You can also use /mode suggest, /mode auto-edit, and /mode full-auto during a session — these map to the approval policies above.
Start with the most cautious settings while learning, then open up autonomy as you get comfortable. Full auto is best reserved for low-stakes prototypes where you can easily discard the results.
📊In Your Field: MIS / Businessclick to expand
Codex CLI’s autonomous execution model is particularly useful for MIS projects where you need to scaffold repetitive structures — like generating CRUD endpoints for a database, creating form validation logic, or building report templates. You can describe the business requirement (“Create an expense report form that calculates totals by category and exports to CSV”) and let Codex handle the implementation details. The Suggest mode is ideal here because you can review each step to make sure it matches your organization’s data standards.
🧬In Your Field: Biotechclick to expand
For bioinformatics workflows, Codex CLI’s sandboxed execution is a meaningful safety feature. When you ask it to “Write a Python script that processes all .fastq.gz files in a directory and generates quality reports,” it runs in an isolated environment — it won’t accidentally overwrite your precious sequencing data. Start in Suggest mode for any task that touches research data, and move to Auto-edit only for scaffolding new analysis scripts from scratch.
Tips
-
Be specific about requirements. Codex excels when you give it a clear, well-defined task. The more specific your instructions, the better the result.
-
Start with small tasks. Build confidence with simple, single-file tasks before trying multi-file projects.
-
Use the sandbox. Codex runs in a sandboxed environment for safety. Sandboxing reduces risk significantly, but always review actions — especially on important projects.
-
Review before accepting. In Suggest mode, Codex shows you what it wants to do before doing it. Use this to learn what good code looks like.
Power features
Mid-session mode switching
You do not have to restart Codex to change modes. Type /mode suggest, /mode auto-edit, or /mode full-auto at any point in the conversation. This lets you start careful and open up autonomy as you gain confidence in the task.
Sandbox
By default, Codex CLI uses a restricted execution environment controlled by the sandbox policy. The workspace-write default limits changes to your project directory. Network and file permissions depend on your configuration and OS. Even in full-auto mode, Codex is designed to contain changes within your project. Always verify sandbox behavior in your environment before relying on it for safety-critical work.
Voice input
Hold the spacebar to dictate your prompt instead of typing. Useful for describing complex tasks conversationally.
Session resume
Run codex resume to pick up a prior session where you left off — handy if you get interrupted or want to continue a multi-step task later.
Verify it works
Paste this exact command to confirm everything is set up correctly:
codex --versionYou should see a version number printed. If you get “command not found,” revisit the installation step above.
If the version check worked, try this — your first real interaction with Codex CLI:
codex "What is 2 + 2? Reply with just the number."If you see a response, congratulations — you’re ready to use Codex CLI for real work starting in Module 9.
When Things Go Wrong
Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.
You’ve now set up three AI CLI tools (Claude Code, Gemini CLI, and Codex CLI), with GitHub Copilot CLI in the next lesson. That’s not redundant — it’s strategic. Different tools excel at different tasks, and knowing when to reach for each one is a professional advantage that most people don’t have. The investment isn’t in any single tool. It’s in the orchestration skill that works across all of them.
Key Takeaways
- Multiple install options —
npm install -g @openai/codex,brew install --cask codex, or download a pre-built binary - Sign in with ChatGPT — device-code flow is the easiest auth; API key still works for CI/scripting
- Two policy axes — approval policy controls when Codex asks permission, sandbox policy controls what it can access
- The sandbox keeps you safe — Codex runs in isolation, so experimentation is low-risk
- Specificity wins — the more precise your task description, the better the result
- Review is learning — Suggest mode shows you how an AI approaches a problem step by step