Codex CLI commands: the ones that matter, with examples
The Codex CLI commands, flags and slash commands you will use, checked against version 0.166.0, and which of them spend tokens on a 5abeer key.
Codex CLI has three kinds of commands: subcommands such as codex exec, flags such as --model, and slash commands such as /review that you type inside a session. This guide covers the ones you will use most, checked against Codex CLI 0.166.0, with examples that run on a 5abeer key.
Which Codex CLI commands do you need first?#
Most work in Codex comes down to eight commands. Add --help to any of them for the full options:
codex # open the interactive terminal UI
codex "explain this repository" # open it with a first prompt
codex exec "run the tests and fix any failure" # run one task without the UI
codex resume --last # reopen the latest session in this folder
codex review --uncommitted # review the changes you haven't committed
codex mcp list # list the MCP servers you added
codex doctor # check the install, config and sign-in
codex update # update Codex to the latest releaseOpenAI released 0.166.0 on 29 October 2026, and it was still the latest stable release when we checked on 2 November 2026. Flags change between releases, so when one below doesn't match your copy, trust codex <command> --help.
What does each codex command do?#
Run Codex#
- `codex`: opens the terminal UI, with an optional first prompt in quotes.
- `codex exec`, or `codex e`: runs one task without the UI and exits, for scripts and CI. Pass
-to read the prompt from standard input. - `codex review`: reviews your
--uncommittedchanges, the diff against a--basebranch or one--commitwithout the UI, or follows review instructions you pass as a prompt.
Pick up past work#
- `codex resume`: reopens a saved session by id or name.
--lastpicks the latest one in this folder, and--allsearches every folder. - `codex fork`: copies a past session into a new chat, keeping the original.
- `codex exec resume`: continues a
codex execsession, optionally with a follow-up prompt. - `codex archive`, `codex unarchive` and `codex delete`: archive, restore or permanently delete a saved session.
Connect tools#
- `codex mcp`: manages the MCP servers in
~/.codex/config.toml:add,list,getandremove, plusloginandlogoutfor servers that use OAuth. - `codex plugin`: installs and manages Codex plugins.
- `codex features`: lists feature flags and turns them on or off in
config.toml.
Sign-in and upkeep#
- `codex login` and `codex logout`: sign in with a ChatGPT account or an OpenAI key, or sign out. A 5abeer key needs neither.
- `codex doctor`: checks the install, config, sign-in and runtime. Add
--jsonfor a report a script can read. - `codex update`: updates Codex when your installed release supports self-update. Otherwise, install it again as on the setup page.
- `codex cloud` and `codex apply`: run Codex cloud tasks, which OpenAI marks experimental, and apply their diffs locally. Codex cloud needs a ChatGPT sign-in, so neither works on an API key alone; see Codex CLI with an API key.
Which flags change how Codex works?#
These are the global flags you will use most:
- `--model`, `-m`: the model for this run. Use any id from the GPT table further down.
- `--sandbox`, `-s`: what the commands Codex runs may touch:
read-only,workspace-writeordanger-full-access. - `--ask-for-approval`, `-a`: when Codex stops to ask you:
on-request, ornever. - `--cd`, `-C`: the folder Codex treats as the project.
- `--add-dir`: one more folder Codex may write to.
- `--config`, `-c`: overrides one
config.tomlkey for this run, written askey=value. - `--profile`, `-p`: layers
~/.codex/profile-name.config.tomlon top of your main config. - `--search`: switches web search from the default cached index to live search.
- `--worktree`: starts in a new managed Git worktree, away from your current checkout.
--dangerously-bypass-approvals-and-sandbox, or --yolo, removes the sandbox and the approval prompts. Use it only in a container or virtual machine you can throw away.
codex exec accepts -m, -s, -C, -c and -p too, plus flags of its own:
- `--json`: prints events as newline-delimited JSON.
- `-o`, `--output-last-message`: writes the final message to a file.
- `--output-schema`: a JSON Schema file that the final answer must follow.
- `--ephemeral`: runs without saving session files.
- `--skip-git-repo-check`: lets it run outside a Git repository.
Which slash commands work inside a session?#
Type / in the terminal UI to open the list. These are the ones you will reach for most:
- `/model`: choose the model and the reasoning effort.
- `/permissions`: choose what Codex may do without asking, such as the Auto or Read Only preset.
- `/status`: shows the session's configuration and token usage.
- `/review`: reviews the changes in your working tree, focusing on behavior changes and missing tests.
- `/diff`: shows the Git diff, including untracked files.
- `/plan`: switches to Plan mode, where Codex proposes a plan before it changes code.
- `/init`: writes an
AGENTS.mdfile with instructions for Codex. - `/compact`: summarizes the conversation so it doesn't hit the context limit.
- `/new`, `/resume` and `/fork`: start a new chat, resume a saved one, or fork the current one.
- `/side`, or `/btw`: opens a side chat in a temporary fork, away from the main thread.
- `/mcp`: lists MCP tools.
/mcp loginwith a server name signs in to it. - `/import`: brings in your setup, the current project and recent chats from Claude Code.
- `/quit` or `/exit`: exits Codex.
Which commands spend tokens on a key?#
On a key you pay per token, so it helps to know which commands call the model:
| Calls the model | Doesn't call the model |
|---|---|
Your messages, codex with a prompt, codex exec | /status, /diff, /model, /permissions |
codex review and /review | codex mcp list, codex features list |
/init, which asks the model to write AGENTS.md | --help on any command |
/compact, which asks the model to summarize the chat |
/review uses the session's model unless you set review_model in config.toml. Every turn also resends the conversation so far, with the files and command output Codex read, so a long session costs more per turn. /status shows the running total, and /new starts a clean chat when a task is done.
Give scripts that run codex exec on every commit a key with its own spend limit, as in Control every key. A worked monthly cost is in Codex CLI with an API key.
How do you set defaults in config.toml?#
Codex reads ~/.codex/config.toml on every start. A project can add its own .codex/config.toml, which Codex loads only when you trust the project. These keys set the defaults that the flags above override:
model_reasoning_effort = "high"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
web_search = "cached"- `model_reasoning_effort`: how much the model reasons, such as
mediumorhigh. The levels on offer depend on the model. - `approval_policy`: the default for
-a. - `sandbox_mode`: the default for
-s. - `web_search`:
disabled,cached,indexedorlive. The default iscached.
Keep these lines above the first header in square brackets. In TOML, a key written under [model_providers.khabeer] belongs to that block, not to your settings.
How to run these commands on a 5abeer key#
On a 5abeer key, only the provider in config.toml changes. You don't need codex login, and codex cloud and codex apply still need a ChatGPT sign-in. Top up with one of the payment methods, create a key for the OpenAI provider as in Create a key, and save it in the KHABEER_API_KEY environment variable. Then put the model and model_provider lines above the first header in square brackets, and the provider block at the end of ~/.codex/config.toml:
model = "gpt-6.1-sol"
model_provider = "khabeer"
[model_providers.khabeer]
name = "5abeer"
base_url = "https://api.5abeer.ai/v1"
env_key = "KHABEER_API_KEY"
wire_api = "responses"
~/.codex/config.toml
Run codex exec "summarize this repository" in a project folder. A reply means the key and the base URL work. The full setup, with profiles that keep your ChatGPT sign-in, is in Codex CLI with an API key.
These are the newest GPT models, at our price per million tokens. Use any of these ids with -m or on the model line:
GPT-6.1 SolInput$0.60Output$3Context922K
GPT-6 AstraInput$3Output$15Context—
GPT-6 SolInput$0.60Output$3Context922K
Official price from the provider's page, checked October 19, 2026.
All models and pricesEvery model that runs in Codex is on the Codex CLI setup page, and the OpenAI API page puts our price next to the official one.
What do real examples look like?#
Run each one from your project folder:
codex exec -s read-only "where is the login flow handled?"codex exec -s workspace-write "run the tests and fix the first failure"codex exec -o summary.md "list the TODO comments in src/"codex review --uncommitted
codex review --base maincodex resume --lastcodex mcp add docs --url https://mcp.example.com/mcp --bearer-token-env-var DOCS_MCP_TOKEN
codex mcp add files -- npx -y @modelcontextprotocol/server-filesystem .codex -c 'model_reasoning_effort="high"' "plan the database migration"In CI, give the runner the same config.toml and set KHABEER_API_KEY from a secret, as in Claude Code GitHub Actions.
Common errors and fixes#
- Codex says the key is missing:
KHABEER_API_KEYisn't set in the shell or CI job that runs it. - `codex exec` won't run outside a Git repository: add
--skip-git-repo-check. - A spend limit stops a script: the key returns
API_KEY_QUOTA_EXHAUSTEDuntil you raise its limit. - Anything else in the setup: run
codex doctor. Our other error codes are in Errors and fixes.
FAQ#
Which Codex version does this guide cover?#
Codex CLI 0.166.0, released on 29 October 2026. Run codex --version to see yours, and codex update to move to the latest release.
What is the difference between codex and codex exec?#
codex opens the interactive terminal UI, where slash commands work. codex exec runs one task without it and exits.
Why doesn't /approvals work?#
Codex 0.166.0 has no /approvals command, though older guides may still show it. Use /permissions inside a session, or set -a and -s when you start Codex.
Do these commands work in ChatGPT?#
Not on the web: OpenAI notes that they don't apply to ChatGPT on the web. The ChatGPT desktop app has its own slash command list.
Can I use these commands on a 5abeer plan instead of a key?#
Yes for the local commands, if your plan includes Codex, as the Bundle plans and the GPT plan do. The 5abeer AI app sets Codex up on your plan with no key; see What each plan runs. Plans are for the supported apps. For your own code, create an API key.
Sources#
Checked on 2026-11-02:
- OpenAI: Developer commands, Codex CLI
- OpenAI: Configuration reference
- OpenAI: Model Context Protocol
- OpenAI: Authentication
- OpenAI: Slash commands in the ChatGPT desktop app
- GitHub: openai/codex release rust-v0.166.0
- GitHub: openai/codex, slash_command.rs at rust-v0.166.0
Get started#
If your plan includes Codex, the 5abeer AI app sets it up with no key. With a key, add the provider block above and run codex exec.
Related guides
- Run Codex CLI with an API key: the complete guideHow to run OpenAI's Codex CLI on an API key instead of a ChatGPT sign-in, what it costs per token, and how to set up a custom provider in config.toml.
- Claude Code commands: slash commands, CLI flags, shortcutsThe Claude Code commands worth knowing, from /init, /compact and /model to CLI flags such as -p and -c, keyboard shortcuts and your own commands.
- Which GPT model to use: Sol, Astra or Luna?Sol for most work, Astra for the hardest reasoning and coding, Luna for fast, high-volume tasks. How OpenAI's GPT models compare on cost and fit.
Ready to start?
Pick a plan that runs the official apps, or create an API key to use from your own code.