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
| Action | Key |
|---|---|
| Open slash-command popup | / |
| Navigate popup | Arrow keys |
| Execute highlighted command | Enter |
| Queue command for next turn (while agent runs) | Tab |
| Dismiss popup | Escape |
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).
| Command | Description |
|---|---|
/new | Start a new session (clears context) |
/clear | Clear the current session transcript from view (context preserved) |
/resume | Show a list of past sessions to resume |
/fork | Fork the current session into a new branch |
/compact | Summarise and compress the conversation history to save tokens |
/title | Set or rename the current session title |
/quit | Exit Codex CLI (alias: /exit) |
/stop | Stop the currently running agent turn |
Example: compact then continue
/compact
Output (inline in TUI):
Compacted 42 turns → 1 summary message (saved ≈ 14,000 tokens).
Example: fork to try an alternative
/fork
Output (inline in TUI):
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.
| Command | Description |
|---|---|
/model | Switch the model for the current session |
/fast | Toggle fast mode (lower-latency, smaller model) |
/personality | Adjust the agent's tone and verbosity style |
/plan | Ask the agent to produce a step-by-step plan before executing |
/effort | Set reasoning effort (minimal / low / medium / high / xhigh) |
Example: switch model mid-session
/model gpt-5-pro
Output (inline in TUI):
Switched to gpt-5-pro for the next turn.
Example: plan-first mode for a tricky task
/plan
Refactor src/auth/ to use JWT cookies instead of session tokens.
Output (inline in TUI):
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.
| Command | Description |
|---|---|
/permissions | View and edit current tool permissions |
/approvals | (Hidden from popup) Open the approvals configuration panel |
/sandbox-add-read-dir | Grant read access to an additional directory |
/sandbox-add-write-dir | Grant write access to an additional directory |
/sandbox-mode | Toggle the active sandbox mode for the session |
Example: temporarily widen the sandbox
/sandbox-add-write-dir /tmp/build-out
Output (inline in TUI):
Added /tmp/build-out to writable paths for this session.
Example: tighten approvals after a risky step
/approvals untrusted
Output (inline in TUI):
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.
| Command | Description |
|---|---|
/diff | Show a unified diff of all file changes made in this session |
/review | Ask the agent to review its own changes and suggest improvements |
/copy | Copy the last assistant message to the clipboard (keyboard: Ctrl+O) |
/revert | Revert 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
/save-diff /tmp/session.patch
Output (inline in TUI):
Saved 142 lines of diff to /tmp/session.patch
# 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
/diff
/review
Output (inline in TUI):
[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.
| Command | Description |
|---|---|
/mention | Open a file/symbol picker to @mention a file in your next message |
/init | Scaffold an AGENTS.md file in the current directory |
/status | Print session status — model, sandbox mode, approval policy, session ID |
/files | List files currently in the agent's context window |
/forget | Remove a file from the agent's context window |
/refresh | Re-read open files from disk (use after external edits) |
Example: status snapshot
/status
Output (inline in TUI):
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).
| Command | Description |
|---|---|
/agent | Manage sub-agents (experimental multi-agent orchestration) |
/ps | List running processes spawned by the agent |
/kill <pid> | Kill a process the agent started |
/task | Create a delegated task description for a sub-agent |
Example: list processes
/ps
Output (inline in TUI):
PID CMD STARTED
4421 npm run dev (server on :4321) 14:02
4475 node test-watch.js 14:08
Example: kill a runaway process
/kill 4475
Output (inline in TUI):
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.
| Command | Description |
|---|---|
/mcp | List 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
/mcp restart filesystem
Output (inline in TUI):
Stopping filesystem… ok
Starting filesystem… ok
4 tools available
Apps and plugins
| Command | Description |
|---|---|
/apps | Manage connected apps (OpenAI desktop integrations) |
/plugins | List 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.
| Command | Description |
|---|---|
/debug-config | Print the resolved configuration (merged user + project config.toml) |
/statusline | Toggle the status bar at the bottom of the TUI |
/experimental | Access experimental features not yet in the main command surface |
/logs | Tail the diagnostic log inline |
/tokens | Show the running token count for the current session |
Example: print effective config
/debug-config
Output (inline in TUI):
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
/tokens
Output (inline in TUI):
Input tokens this session : 18,432
Output tokens this session : 4,210
Cache hits / misses : 7 / 12
Account
| Command | Description |
|---|---|
/logout | Log out of your OpenAI / ChatGPT account |
/feedback | Open the feedback form |
Keyboard shortcuts (TUI)
The TUI is fully keyboard-driven. Memorise these five and you'll rarely reach for the mouse.
| Key | Action |
|---|---|
Ctrl+O | Copy last assistant message |
Ctrl+C | Cancel the in-flight turn (agent stops at next safe point) |
Ctrl+D | Exit Codex (same as /quit) |
Ctrl+L | Clear the visible transcript (context preserved) |
Ctrl+R | Reverse-search prompt history |
Tab | Queue a slash command for the next turn while agent runs |
Shift+Tab | Cycle focus between input and chat history |
Escape | Cancel current input / close popup |
Up / Down | Navigate history or popup |
Enter | Submit message or execute command |
Shift+Enter | Insert 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
<!-- ~/.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
/lint
Output (inline in TUI):
[agent runs ruff and mypy, reports results]
Arguments via $1, $2, $@
<!-- ~/.codex/commands/translate.md -->
Translate the following text into $1: $@
/translate French "Hello, world"
Output (inline in TUI):
"Bonjour le monde"
Project-scoped commands
<!-- 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
-
/cleardoes NOT free the context window. It only hides the transcript visually. Use/compactto actually reclaim tokens. -
/modelmid-session changes the model from the next turn onward. The current turn (if mid-flight) finishes with the old model. -
Tabto queue commands only works while the agent is running. Outside of an in-flight turn,Tabautocompletes. -
/revertonly undoes the last edit operation. It is not a full session-level rollback. Use/save-diff+ manualgit apply -Rfor multi-step undo. -
Custom slash commands run in the same approval policy as the session. A
/dangerouscommand isn't magically safer; if you haveapproval_policy = "never", your custom command will execute without prompting. -
/exitandCtrl+Dflush the history file. If the session was forked, the parent thread is not duplicated — only the active fork is saved. -
Slash commands cannot themselves call other slash commands. You can describe a workflow but you cannot chain
/lint+/testin one custom command. Use a single multi-step prompt instead.
Real-world recipes
Two-command code review workflow
/diff
/review
Output (inline in TUI):
[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.
/tokens
/compact
/tokens
Output (inline in TUI):
Input tokens: 28,431 → Compacting → Input tokens: 14,108
Save a session diff as a patch and switch branches
/save-diff /tmp/feat.patch
# 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
<!-- 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.
/cleanup
Output (inline in TUI):
Removed 4 unused imports, sorted imports in 12 files, formatted 28 files.