cheat sheet

Codex Slash Commands

Complete reference for every built-in Codex CLI slash command — session control, model switching, sandboxing, MCP management, and TUI utilities.

Codex Slash Commands

What it is

Codex CLI exposes 30+ slash commands inside the interactive TUI session. Type / to open the command popup and navigate with arrow keys or type to filter. Press Tab to queue a slash command for the next turn while the agent is still running. Most commands take effect immediately; a few open sub-menus or require additional input.


Opening the popup

ActionKey
Open slash-command popup/
Navigate popupArrow keys
Execute highlighted commandEnter
Queue command for next turn (while agent runs)Tab
Dismiss popupEscape

Session management

Session commands control the lifecycle of the current chat thread — starting fresh, resuming a previous run, forking off a branch, or compacting history to save tokens. They never trigger model calls themselves (except /compact, which uses the model to summarise).

CommandDescription
/newStart a new session (clears context)
/clearClear the current session transcript from view (context preserved)
/resumeShow a list of past sessions to resume
/forkFork the current session into a new branch
/compactSummarise and compress the conversation history to save tokens
/titleSet or rename the current session title
/quitExit Codex CLI (alias: /exit)
/stopStop the currently running agent turn

Example: compact then continue

text
/compact

Output (inline in TUI):

text
Compacted 42 turns → 1 summary message (saved ≈ 14,000 tokens).

Example: fork to try an alternative

text
/fork

Output (inline in TUI):

text
Forked session th_01abc → th_01xyz. Now on th_01xyz.

Model and behaviour

These commands let you change how the agent thinks within an active session — swap the model, dial reasoning effort up or down, request a plan-first workflow. Changes apply to the next turn; turns already in flight are unaffected.

CommandDescription
/modelSwitch the model for the current session
/fastToggle fast mode (lower-latency, smaller model)
/personalityAdjust the agent's tone and verbosity style
/planAsk the agent to produce a step-by-step plan before executing
/effortSet reasoning effort (minimal / low / medium / high / xhigh)

Example: switch model mid-session

text
/model gpt-5-pro

Output (inline in TUI):

text
Switched to gpt-5-pro for the next turn.

Example: plan-first mode for a tricky task

text
/plan
Refactor src/auth/ to use JWT cookies instead of session tokens.

Output (inline in TUI):

text
Plan:
1. Add jwt dependency to pyproject.toml.
2. Introduce src/auth/jwt.py with encode/decode helpers.
3. Replace session lookups in src/auth/middleware.py.
4. Update tests/test_auth.py.
Proceed? [y/n/e]

Permissions and sandboxing

The TUI offers fast inline controls for the same approval and sandbox settings you can configure in config.toml. Changes are scoped to the current session and revert when you exit.

CommandDescription
/permissionsView and edit current tool permissions
/approvals(Hidden from popup) Open the approvals configuration panel
/sandbox-add-read-dirGrant read access to an additional directory
/sandbox-add-write-dirGrant write access to an additional directory
/sandbox-modeToggle the active sandbox mode for the session

Example: temporarily widen the sandbox

text
/sandbox-add-write-dir /tmp/build-out

Output (inline in TUI):

text
Added /tmp/build-out to writable paths for this session.

Example: tighten approvals after a risky step

text
/approvals untrusted

Output (inline in TUI):

text
Approval policy set to "untrusted" for this session.

Diff and review

Diff and review commands surface the agent's filesystem changes in a digestible form, then optionally fold them through a second pass of the agent for self-review. Pair /diff with /review after a long autonomous turn to catch regressions before committing.

CommandDescription
/diffShow a unified diff of all file changes made in this session
/reviewAsk the agent to review its own changes and suggest improvements
/copyCopy the last assistant message to the clipboard (keyboard: Ctrl+O)
/revertRevert the agent's last edit (one-level undo)
/save-diff <path>Save the current session diff to a .patch file

Example: save and apply a session's diff

text
/save-diff /tmp/session.patch

Output (inline in TUI):

text
Saved 142 lines of diff to /tmp/session.patch
bash
# Outside the TUI, apply the patch to a different branch
git checkout review-branch
git apply /tmp/session.patch

Output: (none — patch applied)

Example: self-review before committing

text
/diff
/review

Output (inline in TUI):

text
[diff displayed]
[agent review: "Looks correct, but consider extracting the JWT helpers to src/auth/jwt.py for testability."]

Context and files

These commands explicitly add or surface context — file pickers, current session status, and project-memory scaffolding. They are the workhorses for telling the agent "look at this file" without typing the full path.

CommandDescription
/mentionOpen a file/symbol picker to @mention a file in your next message
/initScaffold an AGENTS.md file in the current directory
/statusPrint session status — model, sandbox mode, approval policy, session ID
/filesList files currently in the agent's context window
/forgetRemove a file from the agent's context window
/refreshRe-read open files from disk (use after external edits)

Example: status snapshot

text
/status

Output (inline in TUI):

text
session_id     : th_01abc
model          : gpt-5-pro
profile        : sprint
sandbox        : workspace-write (+ allow_network)
approval       : on-request
cwd            : /home/alice/myproject
agents_md      : found (1,842 bytes)
mcp_servers    : filesystem, github

Agents and processes

/agent is Codex's entry point for delegated sub-agent work — spawn a child agent for an isolated task and either wait for its result or background it. See subagents for the full reference. /ps lists long-running processes started by the agent (background servers, watchers).

CommandDescription
/agentManage sub-agents (experimental multi-agent orchestration)
/psList running processes spawned by the agent
/kill <pid>Kill a process the agent started
/taskCreate a delegated task description for a sub-agent

Example: list processes

text
/ps

Output (inline in TUI):

text
PID    CMD                                STARTED
4421   npm run dev (server on :4321)      14:02
4475   node test-watch.js                 14:08

Example: kill a runaway process

text
/kill 4475

Output (inline in TUI):

text
Killed PID 4475.

MCP servers

/mcp is the live introspection command for Model Context Protocol servers — see what's running, what tools are exposed, and per-server tool-call counts. Sub-commands let you restart, disable, or re-enable a server inline without editing config.

CommandDescription
/mcpList connected MCP servers and their available tools
/mcp restart <name>Restart a single MCP server
/mcp disable <name>Disable a server for the session
/mcp enable <name>Re-enable a previously disabled server

See MCP Servers for configuration.

Example: restart a flaky server

text
/mcp restart filesystem

Output (inline in TUI):

text
Stopping filesystem… ok
Starting filesystem… ok
4 tools available

Apps and plugins

CommandDescription
/appsManage connected apps (OpenAI desktop integrations)
/pluginsList and toggle installed plugins

Debug and config

When something feels wrong (a hook didn't fire, a profile didn't activate, an MCP tool isn't available), these are the first commands to reach for. /debug-config is the single most-useful introspection command; it shows the fully-merged active configuration.

CommandDescription
/debug-configPrint the resolved configuration (merged user + project config.toml)
/statuslineToggle the status bar at the bottom of the TUI
/experimentalAccess experimental features not yet in the main command surface
/logsTail the diagnostic log inline
/tokensShow the running token count for the current session

Example: print effective config

text
/debug-config

Output (inline in TUI):

text
model           = "gpt-5-pro"
approval_policy = "on-request"
sandbox_mode    = "workspace-write"
profile         = "sprint"
project_trusted = true
agents_md_path  = "/home/alice/myproject/AGENTS.md"
mcp_servers     = ["filesystem", "github"]
hooks_loaded    = 2

Example: check token usage

text
/tokens

Output (inline in TUI):

text
Input  tokens this session : 18,432
Output tokens this session : 4,210
Cache  hits / misses        : 7 / 12

Account

CommandDescription
/logoutLog out of your OpenAI / ChatGPT account
/feedbackOpen the feedback form

Keyboard shortcuts (TUI)

The TUI is fully keyboard-driven. Memorise these five and you'll rarely reach for the mouse.

KeyAction
Ctrl+OCopy last assistant message
Ctrl+CCancel the in-flight turn (agent stops at next safe point)
Ctrl+DExit Codex (same as /quit)
Ctrl+LClear the visible transcript (context preserved)
Ctrl+RReverse-search prompt history
TabQueue a slash command for the next turn while agent runs
Shift+TabCycle focus between input and chat history
EscapeCancel current input / close popup
Up / DownNavigate history or popup
EnterSubmit message or execute command
Shift+EnterInsert a newline without submitting

Custom slash commands

Codex supports user-defined slash commands defined as Markdown files in ~/.codex/commands/ (global) or <project>/.codex/commands/ (project). Each file's name becomes the command (e.g., ~/.codex/commands/lint.md/lint), and the body is the prompt sent to the model.

Define /lint

markdown
<!-- ~/.codex/commands/lint.md -->
Run `ruff check --fix .` and `mypy src/`. Report what you fixed and what
still needs human attention.

Output: (none — defines a slash command)

Invoke it

text
/lint

Output (inline in TUI):

text
[agent runs ruff and mypy, reports results]

Arguments via $1, $2, $@

markdown
<!-- ~/.codex/commands/translate.md -->
Translate the following text into $1: $@
text
/translate French "Hello, world"

Output (inline in TUI):

text
"Bonjour le monde"

Project-scoped commands

markdown
<!-- myproject/.codex/commands/release.md -->
Bump the version in pyproject.toml, write a CHANGELOG entry for everything
since the last tag, and create an annotated git tag v$1.

Output: (none — defines a project-scoped slash command)


Common pitfalls

  1. /clear does NOT free the context window. It only hides the transcript visually. Use /compact to actually reclaim tokens.

  2. /model mid-session changes the model from the next turn onward. The current turn (if mid-flight) finishes with the old model.

  3. Tab to queue commands only works while the agent is running. Outside of an in-flight turn, Tab autocompletes.

  4. /revert only undoes the last edit operation. It is not a full session-level rollback. Use /save-diff + manual git apply -R for multi-step undo.

  5. Custom slash commands run in the same approval policy as the session. A /dangerous command isn't magically safer; if you have approval_policy = "never", your custom command will execute without prompting.

  6. /exit and Ctrl+D flush the history file. If the session was forked, the parent thread is not duplicated — only the active fork is saved.

  7. Slash commands cannot themselves call other slash commands. You can describe a workflow but you cannot chain /lint + /test in one custom command. Use a single multi-step prompt instead.


Real-world recipes

Two-command code review workflow

text
/diff
/review

Output (inline in TUI):

text
[diff displayed]
[agent suggests improvements]

Inspect token usage before a long task

Useful before a /compact to gauge whether it's worth the round-trip.

text
/tokens
/compact
/tokens

Output (inline in TUI):

text
Input tokens: 28,431  →  Compacting  →  Input tokens: 14,108

Save a session diff as a patch and switch branches

text
/save-diff /tmp/feat.patch
bash
# Outside the TUI
git stash
git checkout main
git apply /tmp/feat.patch

Output: (none — patch applied to main)

Custom /cleanup command for a project

markdown
<!-- myproject/.codex/commands/cleanup.md -->
1. Remove unused imports in src/.
2. Sort imports per isort profile=black.
3. Run ruff format on everything in src/.
4. Report a one-line summary.
text
/cleanup

Output (inline in TUI):

text
Removed 4 unused imports, sorted imports in 12 files, formatted 28 files.