OpenAIbeginner

How to Use Slash Commands in OpenAI Codex CLI

Master slash commands in OpenAI Codex CLI to navigate sessions, manage context, and access special features. Learn all available commands and keyboard shortcuts for efficient AI-assisted coding.

6 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

Slash commands in OpenAI Codex CLI provide quick access to navigation, context management, and special features without leaving your terminal session. Mastering these commands lets you work faster and maintain better control over your AI-assisted coding workflow.

Understanding Slash Commands

Slash commands are special instructions that start with a forward slash (/). Unlike regular prompts that Codex interprets as coding requests, slash commands trigger specific built-in behaviors. You can use them at any point during an interactive session.

To use a slash command, simply type it at the prompt and press Enter:

codex> /help

These commands help you manage your Codex session and navigate the interface.

/help

Displays all available slash commands with brief descriptions. This is your reference when you forget a command name:

codex> /help

The output lists every command available in your current Codex version, including any custom commands you have configured.

/clear

Resets the conversation context entirely. Use this when you want to start fresh without exiting and restarting Codex:

codex> /clear

After clearing, Codex has no memory of previous exchanges. This is useful when switching between unrelated tasks.

/quit or /exit

Ends your Codex session and returns you to the regular terminal prompt:

codex> /quit

You can also use Ctrl+D to exit.

Context Management Commands

Managing context is essential for long coding sessions. These commands help you optimize token usage and maintain relevant history.

/compact

Summarizes your conversation history to reduce token usage while preserving important context:

codex> /compact

When Codex compacts your history, it creates a condensed summary of key decisions, code changes, and context. Use this when:

  • You are approaching context limits and responses slow down
  • Your session has been running for a while with many exchanges
  • You want to preserve context but reduce token costs

/history

Displays your conversation history within the current session:

codex> /history

This shows the exchanges between you and Codex, which is helpful for reviewing what has been discussed or understanding how context has accumulated.

/undo

Reverts the most recent change Codex made to your files:

codex> /undo

This is a safety net when Codex makes an edit you did not intend. It works with the built-in version tracking that Codex maintains during sessions.

Mode and Model Commands

These commands let you adjust how Codex operates during a session.

/mode

Changes the approval mode, which controls how much autonomy Codex has when executing commands and making changes:

codex> /mode

Codex presents a menu of available modes:

  • suggest - Codex only suggests changes, you must approve each one
  • auto-edit - Codex can edit files automatically but asks before running commands
  • full-auto - Codex operates with full autonomy (use with caution)

/model

Switches to a different AI model mid-session without restarting:

codex> /model

A selection menu appears with available models like gpt-5.2-codex and gpt-5.1-codex-mini. This is useful when you want to use a cheaper model for simple tasks or a more powerful one for complex reasoning.

/status

Shows your current configuration including active model, approval mode, and token usage:

codex> /status

Special Feature Commands

Codex includes several commands that activate dedicated workflows.

/review

Launches a dedicated code review agent that analyzes your staged changes:

codex> /review

The review agent examines your git staging area and provides feedback on code quality, potential bugs, and improvement suggestions. This is particularly useful before committing changes.

/resume

Continues a previous session from where you left off:

codex> /resume

Codex maintains transcript history that allows you to pick up exactly where you stopped, including full context from the previous session.

/diff

Shows the differences between the current file state and before your session began:

codex> /diff

This helps you track what has changed during your Codex session without leaving the tool.

Keyboard Shortcuts

Alongside slash commands, Codex supports several keyboard shortcuts for common actions:

ShortcutAction
Ctrl+CCancel current operation
Ctrl+DExit Codex session
Ctrl+LClear screen (keeps context)
Up/DownNavigate command history
TabAutocomplete file paths

These shortcuts work throughout your session and complement slash commands for efficient navigation.

Creating Custom Commands

You can define custom slash commands in your ~/.codex/config.toml file to automate repetitive workflows:

# ~/.codex/config.toml

[[custom_commands]]
name = "test"
prompt = "Run the test suite and summarize any failures"

[[custom_commands]]
name = "docs"
prompt = "Update the documentation for the function I'm currently editing"

[[custom_commands]]
name = "security"
prompt = "Review this code for security vulnerabilities, focusing on input validation and authentication"

After adding custom commands, they become available as slash commands:

codex> /test
codex> /docs
codex> /security

Custom commands can include any prompt text, making them powerful shortcuts for tasks you perform frequently.

Tips for Efficient Command Usage

  1. Start sessions with /status to verify your model and mode settings are correct for the task
  2. Use /compact proactively rather than waiting for context limit errors
  3. Create custom commands for your most common workflows to save typing
  4. Use /mode suggest when working on critical code where you want full control
  5. Run /review before commits to catch issues before they enter your codebase
  6. Combine /clear with mode changes when switching between very different tasks

Next Steps

Frequently Asked Questions

Find answers to common questions

Key commands include /help (show all commands), /clear (reset context), /compact (summarize context), /mode (change approval mode), /model (switch AI model), /review (dedicated code review), and /history (view conversation history).

Need Professional IT & Security Help?

Our team of experts is ready to help protect and optimize your technology infrastructure.