Skip to content

The Codex CLI is more than codex "prompt": it saves every session so codex resume and codex fork continue or branch one, it has dozens of slash commands in the terminal UI (TUI), and it runs codex review and codex exec from scripts. Every command and flag below was checked against Codex CLI 0.157.1 as of this page’s 2026-10-03 revision; the slash-command table was re-read against 0.162.1 on 2026-10-12.

This page is for developers who already run Codex in a terminal and keep paying the same tax: re-explaining context in a fresh session, losing a good thread when an experiment goes wrong, and reading the whole diff because nothing else tells them whether the change is right. Most of that tax disappears once you use the session commands, a handful of slash commands and a review gate. If you have not installed Codex yet, start with your first Codex task.

What you’ll walk away with from the Codex CLI

Section titled “What you’ll walk away with from the Codex CLI”
  • A session routine: named sessions you resume by name, forks for experiments, and a queue for follow-ups.
  • The slash commands that matter day to day, and when each one pays off.
  • The TUI keys for steering a running turn, queuing the next one and writing long prompts in your editor.
  • Four copy-paste prompts, and a review-and-test gate that checks the result so you do not read every line.
  • The traps in 0.157.1 that silently change behaviour, with the fix for each.

How do you continue a Codex session instead of re-explaining it?

Section titled “How do you continue a Codex session instead of re-explaining it?”

Codex writes every interactive session to disk. codex resume reopens one with its whole transcript, so the agent keeps the decisions, constraints and files from last time.

Terminal window
# Terminal: open the picker (sessions started in this directory)
codex resume
# Continue the most recent session
codex resume --last
# Search sessions from every directory, not only this one
codex resume --all
# Continue and send the next instruction in one step
codex resume --last "The plan is approved. Implement step 1 and run the tests."

The picker filters by working directory by default. When a session you know exists is missing, you started it somewhere else: add --all. Sessions started with codex exec are also hidden from the picker and from --last unless you pass --include-non-interactive.

Name sessions so you can find them next week

Section titled “Name sessions so you can find them next week”

A UUID is useless a week later. Inside the TUI, run /rename and give the thread a name such as payments-retry. From then on, codex resume, codex exec resume, codex exec fork, codex archive and codex queue accept the name wherever they accept a session ID (codex fork takes the UUID or --last):

Terminal window
codex resume payments-retry "CI is green again. Continue with the refund path."

Two more commands keep the list short: codex archive <name> hides a finished session and codex unarchive <name> brings it back, while codex delete <name> removes it for good. Inside the TUI, /archive and /delete do the same for the current session.

codex queue adds a message to an existing session’s queue without opening that session in your terminal. --thread takes the session UUID or its exact name:

Terminal window
codex queue --thread payments-retry --message "When the tests pass, update CHANGELOG.md."

How do you try an alternative without losing the original thread?

Section titled “How do you try an alternative without losing the original thread?”

codex fork copies a session’s transcript into a new thread and leaves the original untouched. In 0.157.1 it accepts a prompt, so you can branch and instruct in one command. Inside the TUI, /fork forks the current chat.

--worktree starts each fork in a new managed Git worktree; without it, both forks edit the same files. The worktree workflow is covered in Codex worktrees. Compare the forks on their test output and /diff, not on how confident the final message sounds.

Which Codex slash commands are worth learning?

Section titled “Which Codex slash commands are worth learning?”

Type / in the composer to see the full list for your version; there is no /help (checked in 0.157.1 and 0.162.1, slash_command.rs). These are the ones that change how a session goes. Descriptions are paraphrased from slash_command.rs at 0.157.1, and every row below was re-read against the 0.162.1 source on 2026-10-12.

CommandWhat it doesWhen to reach for it
/reviewReviews your current changes and reports issuesBefore every commit; accepts custom instructions inline
/diffShows the Git diff, including untracked filesBefore you accept a turn’s work
/statusShows the session configuration and token usageWhen the agent behaves as if it had a different model or permission
/modelChooses the model and reasoning effortA hard bug needs more effort; a rename needs less
/permissionsChooses what Codex is allowed to doYou started read-only and now want it to edit files
/compactSummarises the conversation to stay under the context limitLong sessions, before the agent starts forgetting constraints
/newStarts a new chat in the same TUIThe topic changed; old context would only mislead
/fork, /resume, /renameBranch, reopen or name threadsSee the sections above
/worktreeStarts or continues a conversation in a new managed worktreeYou want isolation without leaving the session; see Codex worktrees
/planSwitches to Plan modeAgree the approach before any file changes
/goalSets or views the goal for a long-running taskMulti-hour tasks that must not drift
/initCreates an AGENTS.md fileFirst session in a repository
/side, /btwOpens a side conversation in an ephemeral forkA quick question that should not pollute the main thread
/mcp, /skills, /pluginsLists MCP tools, skills and plugins; /mcp login <name> signs in to an OAuth server (0.161.0)Checking that an integration actually loaded
/approveApproves one retry of a recent auto-review denialAuto-review blocked a command you have checked
/copy, /exportCopies the last response or part of it; exports the conversation as MarkdownPasting a plan into a ticket or PR

Most commands, including /compact, /new, /init, /review and /plan, are unavailable while a turn is running. Press Esc to interrupt the turn first. /model, /permissions, /diff and /status work mid-turn, and so do /copy and /mcp; /worktree waits for the turn to end (checked in 0.157.1 and 0.162.1, slash_command.rs).

The 0.162.1 list also contains /daybreak (“turn Daybreak on or off”), which is hidden by default. Since 0.161.0 (2026-10-07) it needs --enable cli_daybreak or features.cli_daybreak = true, and daybreak = true alone is not enough; cli_daybreak is under development and off in 0.162.1 (checked 2026-10-12). For the security context, see Codex Security and the agents command center.

/review opens a menu of review targets. The same targets exist as flags on codex review, which runs the review without the TUI:

TargetIn the TUIFrom the shell
Work against a base branch/review → base branchcodex review --base main
Staged, unstaged and untracked changes/review → uncommitted changescodex review --uncommitted
One commit/review → a commitcodex review --commit <SHA>
Your own instructions/review Focus on…codex review "Focus on…"

In 0.157.1 the last row cannot be combined with the others from the shell: codex review rejects a custom prompt together with --uncommitted, --base or --commit (“the argument ‘—uncommitted’ cannot be used with ‘[PROMPT]’”). Pass either a target flag or your own instructions, not both.

To use a different model for reviews than for coding, set review_model in ~/.codex/config.toml:

~/.codex/config.toml
review_model = "gpt-6-sol"

Which model fits which job, with prices, is kept on the model hub.

Press ? in an empty composer to show the shortcuts for your build. These are the defaults in 0.157.1; you can remap them with /keymap.

KeyWhat it does
@Opens fuzzy file search; the chosen path goes into your message
! at the start of a lineRuns a local shell command; its output lands in the conversation
Enter while the agent worksSends your message into the running turn to steer it
Tab while the agent worksQueues your message for after the current turn
Esc while the agent worksInterrupts the turn
Esc twice when idleEdits your previous message
Ctrl+GOpens $VISUAL or $EDITOR to write a long prompt
Ctrl+RSearches your prompt history
Ctrl+TOpens the full transcript
Alt+, / Alt+.Lowers or raises reasoning effort

Enter versus Tab is the one to internalise. Enter corrects the agent now (“stop, that table is generated; edit the migration instead”). Tab lines up the next job without disturbing the current one (“then add the changelog entry”).

The ! prefix is the fastest way to give the agent evidence instead of your summary of it:

!npm test -- payments 2>&1 | tail -40

How do you give Codex a screenshot from the terminal?

Section titled “How do you give Codex a screenshot from the terminal?”

Attach images to the first prompt with -i or --image. Put the prompt before the flag, or use the = form: in 0.157.1 -i keeps taking arguments until the next flag, so a prompt written after it is read as another image path.

Terminal window
codex "The checkout button overlaps the total on a 375px viewport. Fix the CSS and tell me which rule caused it." -i broken-layout.png
codex --image=expected.png,actual.png "The first image is the design, the second is production. List every visual difference, then fix them."

In the TUI you can also paste an image from the clipboard into the composer. codex exec and codex resume accept the same multi-file -i; codex exec resume takes a single -i <FILE> (checked in 0.157.1).

codex exec runs one task without the TUI and exits, which makes it usable in scripts and Git hooks. The full treatment, including the JSONL event stream and CI, is on Run Codex non-interactively with codex exec. The three invocations you need most:

Terminal window
# Edit files inside the workspace sandbox
codex exec --sandbox workspace-write "Fix the lint errors reported by npm run lint, then rerun it"
# Pipe context in; stdin is appended to the prompt as a <stdin> block
git diff main...HEAD | codex exec "Write a PR description for this diff: summary, risks, test plan"
# Write only the final message to a file
codex exec -o release-notes.md "Draft release notes for the commits since the last tag"

When a script consumes the output, make Codex return JSON that matches a schema instead of prose:

endpoints.schema.json defines the shape the final message must take:

{
"type": "object",
"additionalProperties": false,
"required": ["endpoints"],
"properties": {
"endpoints": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["method", "path", "description"],
"properties": {
"method": { "type": "string", "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"] },
"path": { "type": "string" },
"description": { "type": "string" }
}
}
}
}
}

How do you know the result is right without reading every line?

Section titled “How do you know the result is right without reading every line?”

The CLI gives you the parts of a gate; you still decide what “done” means. A routine that works for day-to-day changes:

  1. State the check in the prompt. Every prompt on this page ends with a command the agent must run and report, such as the test command or npm run lint. A claim of success without that output is not success.

  2. Rerun the check yourself. Run the same test and type-check commands in your terminal, or with ! in the TUI. The agent’s transcript is a report, not evidence.

  3. Read the shape of the diff, not every line. /diff shows which files changed. A one-line bug fix that touches eight files needs a question before it needs a review.

  4. Run an independent review. Save the defect-only prompt above as review-prompt.txt and run codex review - < review-prompt.txt, or paste it after /review in the TUI. A custom prompt replaces the target flags, and with a custom prompt and no target flag the reviewer decides the scope from your wording, so name it explicitly (“Review my uncommitted changes…”). The review runs in a fresh context, not the one that wrote the change. Fix every P0 and P1 before committing; decide on P2 and P3 yourself.

  5. Validate machine output mechanically. For --output-schema runs, check the file with jq in the script (for example, jq -e '.endpoints | length > 0' endpoints.json) and fail the step when it does not hold.

You sign off on behaviour: the tests and the review findings. To run the same review on every pull request for the whole team, use the layered setup in Code review with Codex.

How do you point Codex at the right directories?

Section titled “How do you point Codex at the right directories?”
Terminal window
# Use another directory as the working root without cd
codex -C ~/src/shop-api "Explain how orders are persisted"
# Make a second directory writable next to the workspace
codex -C apps/web --add-dir ../api "Rename the orderId field in the web client and the API together"
# Run exec outside a Git repository
codex exec --skip-git-repo-check "Write a Python script that deduplicates rows in data.csv by email"

codex exec refuses to run outside a Git repository without --skip-git-repo-check. The check exists because Git is your undo button; use the flag only for throwaway directories.

For shell completions, generate the script for your shell and load it, for example eval "$(codex completion zsh)" in ~/.zshrc after compinit. When something about the installation looks wrong, codex doctor checks the installation, config, authentication and runtime health.

For cloud tasks, codex cloud (marked experimental in 0.157.1) submits, lists and applies tasks from the terminal: codex cloud exec --env <ENV_ID> "…", codex cloud list, codex cloud diff <TASK_ID> and codex cloud apply <TASK_ID>. Environment setup and best-of-N are covered in Codex cloud environments.

What breaks when you drive Codex from the CLI?

Section titled “What breaks when you drive Codex from the CLI?”
  • codex resume --last opens the wrong session. --last only sees interactive sessions started in the current directory. Add --all for other directories and --include-non-interactive for sessions that codex exec started. Better: /rename the thread and resume it by name.
  • Two forks overwrite each other’s files. A fork copies the transcript, not the working tree. Start each fork in its own worktree with --worktree, or run them one after the other.
  • codex exec resume rejects --sandbox. In 0.157.1, codex exec resume has no --sandbox flag (checked with codex exec resume --help). Pass the setting as config instead: codex exec resume --last -c sandbox_mode="workspace-write" "…".
  • codex exec -a never fails with “unexpected argument”. codex exec has no -a of its own in 0.157.1, and needs none: it already runs with approval never (on-request under --approve-for-me), and a codex -a never exec … prefix does not change that. Drop the flag, check the approval: line in the run header, and limit the run with the sandbox or a permission profile.
  • A copied command uses --full-auto or -a on-failure. Neither works in 0.157.1: --full-auto is gone from codex and codex exec, and -a accepts only on-request and never. Use --sandbox workspace-write, or --approve-for-me to route approval requests through automatic review.
  • A slash command does nothing. /compact, /new, /review and several others are unavailable while a turn is running. Press Esc, then run the command.
  • -i a.png "prompt" treats your prompt as a file. In 0.157.1 -i keeps taking arguments until the next flag, so a prompt after it becomes a file path, even with -i a.png,b.png (checked with codex exec 0.157.1). Put the prompt first, use --image=a.png,b.png, or end the list with --.
  • Never reach for --dangerously-bypass-approvals-and-sandbox to get past an approval. It disables the sandbox as well; it is meant only for runs that are already inside an external, disposable sandbox.

For recovery from sandbox denials, context overflow and wrong-direction edits in general, see Codex error recovery.