Back to all posts
Codex CLI Guide: Setup, Models, MCP, and Daily Use

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.

June 23, 2026
6 min read
3 views
by Iwo Szapar

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.

NeedUse Codex CLIUse Codex app
Edit a local repo from terminalYesYes
Pipe prompts from scriptsYesNo
Run quick code review from command lineYesYes
Manage worktrees visuallyNoYes
Preview browser or artifact outputLimitedYes
Run repeatable project automationsYes with scriptsYes with app automations
Work in CI or server scriptsYesNo

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:

  1. Give Codex the smallest useful tool set.
  2. Keep secrets in the MCP server or environment, not in prompts.
  3. 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:

  1. Pull the latest main branch.
  2. Start Codex in the target repo.
  3. Ask for a short plan.
  4. Let it inspect the exact files.
  5. Approve scoped edits.
  6. Run tests from the same terminal.
  7. 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.

TaskBetter surface
Explain a product ideaChatGPT
Fix a failing testCodex CLI
Draft a strategy memoChatGPT
Refactor a moduleCodex CLI
Compare toolsChatGPT or Codex app
Run a scripted repo checkCodex 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.