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:
- Start a session and work on Feature A for 30 minutes.
- The conversation grows long. Run /compact to compress history.
- Finish Feature A and move to Bug Fix B.
- Run /clear to wipe the slate so Feature A context does not confuse Bug Fix B.
- Work on Bug Fix B with a clean context.
- Run /exit when done for the day.
Slash Commands vs Regular Prompts
| Action | Use a Slash Command | Use a Regular Prompt |
|---|---|---|
| Clear conversation history | /clear | No equivalent |
| Add a file to context | /add-file filename | "Read the file filename.py" |
| Compress long conversation | /compact | No equivalent |
| Edit a file | Not possible with slash commands | "Edit the function in filename.py" |
| Explain code | Not 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
| Command | What It Does | When to Use It |
|---|---|---|
| /help | Lists all commands | Any time you need a reminder |
| /clear | Erases conversation history | Starting a new unrelated task |
| /compact | Compresses conversation | Long sessions getting slow |
| /add-file | Loads a file into context | Pre-loading a key file before work starts |
| /model | Shows or changes the AI model | Checking or switching models |
| /exit | Closes Claude Code | Ending 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.
