Slash Commands in Claude Code

Slash commands are shortcuts built directly into Claude Code. Instead of typing a long instruction, you type a short command starting with a forward slash and Claude Code performs a predefined action immediately. They save time and give you precise control over how Claude Code behaves during your session.

How Slash Commands Work

Type a forward slash at the prompt line and a menu of available commands appears. You select or type the command you want. Slash commands work on the session itself — they do not directly edit your code files. They control Claude Code's behavior, memory, and settings.

You type: /
               |
               v
[ Menu of commands appears ]
               |
               v
You select or complete the command
               |
               v
[ Claude Code executes the action instantly ]

The Core Slash Commands

/help

Shows a list of all available slash commands with a short description of each. Use this any time you forget a command or want to discover new ones.

/help

/clear

Clears the current conversation from Claude Code's memory and starts a fresh session. Use this when you finish one task and move to a completely different one. Clearing prevents leftover context from the previous task from influencing the new one.

/clear

Think of it as starting a new page. The project files stay unchanged — only the conversation history disappears.

/compact

Summarizes the current conversation and compresses it. This frees up space in the context window without wiping the whole conversation. Use this when a long session is slowing Claude Code's responses or when you want to continue the same task with a lighter memory load.

/compact

/exit

Closes the Claude Code session entirely and returns you to your normal terminal prompt.

/exit

Diagram: Slash Command Purposes

Think of slash commands as the controls on a recording console — they do not change the music, they adjust how the recording session runs.

SLASH COMMANDS CONTROL THE SESSION

/clear     →  Wipe the whiteboard, start fresh
/compact   →  Fold the whiteboard, keep key notes
/help      →  Open the instruction manual
/exit      →  Leave the recording studio

File and Code Slash Commands

/add-file

Manually adds a specific file to Claude Code's active context. By default, Claude Code reads files when you mention them in a prompt. Use /add-file when you want a file loaded into context before the conversation starts, or when Claude Code is missing context about a file.

/add-file src/payment_gateway.py

After this command, Claude Code knows the contents of payment_gateway.py and can reference it without you mentioning it by name in every prompt.

Model and Behavior Commands

/model

Shows the current AI model Claude Code is using, or lets you switch to a different one if multiple models are available in your setup.

/model

/config

Opens or displays Claude Code's configuration settings. You can see and change settings like how Claude Code handles permissions, output format, and auto-accept behavior.

/config

Using Slash Commands During a Long Session

Slash commands are most valuable during long working sessions. Here is a realistic pattern:

  1. Start a session and work on Feature A for 30 minutes.
  2. The conversation grows long. Run /compact to compress history.
  3. Finish Feature A and move to Bug Fix B.
  4. Run /clear to wipe the slate so Feature A context does not confuse Bug Fix B.
  5. Work on Bug Fix B with a clean context.
  6. Run /exit when done for the day.

Slash Commands vs Regular Prompts

ActionUse a Slash CommandUse a Regular Prompt
Clear conversation history/clearNo equivalent
Add a file to context/add-file filename"Read the file filename.py"
Compress long conversation/compactNo equivalent
Edit a fileNot possible with slash commands"Edit the function in filename.py"
Explain codeNot possible with slash commands"Explain what this function does"

Slash commands handle session management. Everything involving actual code — reading, editing, creating, debugging — uses regular prompts.

Custom Slash Commands

Claude Code supports custom slash commands defined in a configuration file. Teams can create shared custom commands for tasks they repeat often, like running a specific kind of code review or generating a standard report.

Custom commands live in the CLAUDE.md file or in Claude Code's configuration. When defined, they appear in the slash command menu alongside built-in commands.

Example custom command:
/review-security  →  runs a security-focused code review on the current file

Custom commands are covered in more detail in the advanced prompting and team usage topics.

A Quick Slash Command Reference

CommandWhat It DoesWhen to Use It
/helpLists all commandsAny time you need a reminder
/clearErases conversation historyStarting a new unrelated task
/compactCompresses conversationLong sessions getting slow
/add-fileLoads a file into contextPre-loading a key file before work starts
/modelShows or changes the AI modelChecking or switching models
/exitCloses Claude CodeEnding the session

Key Points

  • Slash commands start with / and control the Claude Code session, not your code files.
  • /clear wipes conversation memory for a fresh start on a new task.
  • /compact compresses a long conversation to free up context without losing the thread.
  • /add-file loads a specific file into context before you start prompting.
  • Regular prompts handle all code-related tasks — slash commands handle session management.
  • Teams can define custom slash commands for repeated workflows.

Leave a Comment