Codex CLI Guide: Setup, Models, MCP, and Daily Use
A practical June 2026 guide to Codex CLI for local repos, review, MCP, and scripted agent runs.
Last updated: June 23, 2026
Codex CLI is the fastest way to bring OpenAI's coding agent into a local repository. It lives in your terminal, reads the current project, edits files, runs commands, and keeps a transcript you can resume later.
The search query "codex cli" is broad, but the intent is usually practical:
- How do I install and start it?
- Which model should I use?
- Can it run tests and change files?
- Does it support MCP?
- When should I use CLI instead of the Codex app?
This guide answers those questions without treating the CLI as a chatbot in a terminal. The CLI is better understood as a local agent runner for code, tests, reviews, and repeatable developer workflows.
Quick answer
Use Codex CLI when your work already lives in Git, shell commands, test suites, and repo-local instructions. Use the Codex app when you want desktop worktrees, built-in Git controls, visual review, automations, browser testing, or non-code artifacts in the same interface.
| Need | Use Codex CLI | Use Codex app |
|---|---|---|
| Edit a local repo from terminal | Yes | Yes |
| Pipe prompts from scripts | Yes | No |
| Run quick code review from command line | Yes | Yes |
| Manage worktrees visually | No | Yes |
| Preview browser or artifact output | Limited | Yes |
| Run repeatable project automations | Yes with scripts | Yes with app automations |
| Work in CI or server scripts | Yes | No |
What Codex CLI does
Codex CLI starts an interactive terminal UI with access to the selected directory. From there, it can inspect files, propose edits, apply patches, run tests, and explain what changed. You can start a blank session with:
codex
Or pass the first task directly:
codex "Explain this repository and list the risky parts"
The official docs also describe codex exec for non-interactive runs. That matters for scripts, release checks, editorial gates, and recurring maintenance work.
Recommended model
OpenAI's Codex docs currently recommend gpt-5.5 for most Codex tasks. Use it when the work requires planning, multi-file edits, test interpretation, or long tool loops.
You can specify it at launch:
codex
For lighter work, the available model list depends on your plan or API key. The important habit is to match model strength to blast radius. Small copy edits and one-file fixes do not need the same budget as a migration, security review, or production incident.
MCP support
Codex CLI supports Model Context Protocol servers through the Codex config and codex mcp commands. This is where the CLI becomes more than a code editor. MCP lets Codex use approved tools for databases, docs, browser flows, analytics, and internal systems.
Good MCP use has three rules:
- Give Codex the smallest useful tool set.
- Keep secrets in the MCP server or environment, not in prompts.
- Write repo instructions that explain when each tool matters.
MCP is especially useful for tasks like "read the failing Sentry issue, inspect the related code, patch it, run tests, and draft the PR summary."
Daily workflow
A practical Codex CLI day looks like this:
- Pull the latest main branch.
- Start Codex in the target repo.
- Ask for a short plan.
- Let it inspect the exact files.
- Approve scoped edits.
- Run tests from the same terminal.
- Ask Codex to review the diff before commit.
For quick checks, use the review flow:
codex
/review
For automation, use codex exec:
codex exec "Update docs for the changed files and report any missing tests"
Codex CLI vs ChatGPT
ChatGPT is better when the work is broad thinking, writing, research, or file analysis without a repository. Codex CLI is better when the answer needs to become a code diff, a passing test, or a concrete change inside a local project.
| Task | Better surface |
|---|---|
| Explain a product idea | ChatGPT |
| Fix a failing test | Codex CLI |
| Draft a strategy memo | ChatGPT |
| Refactor a module | Codex CLI |
| Compare tools | ChatGPT or Codex app |
| Run a scripted repo check | Codex CLI |
Codex CLI vs Claude Code
Codex CLI and Claude Code both read code, edit files, run commands, and fit terminal-first workflows. The choice usually comes down to your surrounding stack.
Choose Codex CLI if you want OpenAI models, Codex app sync, codex exec, built-in Codex review flows, and a path into Codex cloud or app worktrees. Choose Claude Code if your team already standardizes on Claude, CLAUDE.md, Claude Code hooks, or Anthropic's Claude Code ecosystem.
I wrote the direct comparison here: Codex vs Claude Code.
Common mistakes
The biggest mistake is treating Codex CLI like a prompt box. It works better when the repository tells it how to behave.
Add project instructions. Keep test commands obvious. Document dangerous paths. Name your verification steps. If a human would need five minutes to learn the repo's conventions, the agent needs that context too.
The second mistake is asking for a huge change without checkpoints. Codex can handle large tasks, but you will get better results by splitting work into inspect, plan, edit, test, review, and commit.
FAQ
Is Codex CLI free?
Codex availability and limits depend on your ChatGPT plan or API key. Check the current OpenAI Codex pricing and auth docs before planning team rollout.
Does Codex CLI run locally?
The CLI runs in your local terminal against the selected project directory. Model calls still go to OpenAI unless you configure a supported alternative through the product's documented paths.
Can Codex CLI use MCP?
Yes. Codex supports MCP servers through its configuration and MCP commands. Use MCP for approved external tools, docs, databases, and internal systems.
Is Codex CLI better than the Codex app?
It is better for terminal automation, scripting, and CI-shaped work. The app is better for visual multitasking, worktrees, Git controls, automations, browser testing, and artifacts.
What should I read next?
Read the broader ChatGPT vs Codex vs Claude Code vs Claude Cowork vs Gemini vs Antigravity comparison if you are choosing a work surface, not just a terminal tool.
Related guides
ChatGPT vs Codex vs Claude Code
The broader AI workbench comparison for 2026.
Claude Code CLI vs Desktop
Where terminal workflows still beat desktop workflows.
Context engineering with MCP
How protocol-connected tools become useful work systems.
MemoryOS
The context layer for coding agents and knowledge work.