How to Create Your First Custom Slash Command in Claude Code

You’ve been typing the same long prompt into Claude Code for the third time today. You know there’s a way to turn it into a shortcut. You just don’t know exactly how.

This tutorial walks you through creating a real, working custom slash command from scratch — from creating the file to calling it in your session. By the end, you’ll have a command that actually runs.

📋 TL;DR
– Custom slash commands are .md files stored in .claude/commands/
– The filename becomes the command name — review.md becomes /review
– The file contains plain English instructions that Claude follows when you call the command
– You can create project-level commands (one project) or global commands (all projects)
– No coding required — if you can write clear instructions, you can build a command

This is part of our complete Claude Code Slash Commands & Skills — Full Guide. If you haven’t read What Are Slash Commands in Claude Code? yet, start there.


What You’re About to Build

You’re going to create a /review command. When you type /review in a Claude Code session, Claude will:

  1. Review the code you’re working on
  2. Check for bugs and unclear variable names
  3. Suggest one readability improvement
  4. Keep the response under 200 words

This is a real, useful command. Not a toy example. By the end of this tutorial you’ll be running it.


What You Need Before You Start

  • Claude Code installed and working (see Your First 10 Minutes with Claude Code if you need help with setup)
  • A terminal or file manager — you’re creating a folder and a text file
  • Five minutes

That’s it. No additional tools, no libraries, no configuration files to edit.


Step 1: Create the .claude/commands/ Folder

Custom slash commands live inside a .claude/commands/ folder. If you’ve never set up Claude Code in your project, this folder doesn’t exist yet.

To create it, run this in your project root:


# Creates the .claude/commands/ directory inside your current project
mkdir -p .claude/commands

The -p flag creates any parent directories that are missing, so if .claude/ doesn’t exist either, this creates both at once.

💡 Pro Tip: If you’ve already run /init in Claude Code, the .claude/ folder may already exist. Run ls -la .claude/ to check. If commands/ is missing inside it, create it with mkdir .claude/commands.

After running the command, your project structure looks like this:


your-project/
├── .claude/
│   └── commands/        ← your slash commands go here
├── src/
├── package.json
└── (rest of your project)

Terminal showing the mkdir command being run and the resulting .claude/commands/ folder structure in the project directory


Step 2: Create Your Command File

Now create the file that will become your /review command. The filename is the command name — so review.md becomes /review.

Create the file:


# Creates the review.md file inside your commands folder
touch .claude/commands/review.md

Now open it in your editor and add the instructions. Here’s a real, complete command file you can copy:


# This is the /review slash command — Claude follows these instructions when called

Review the code I'm currently working on. Follow this checklist exactly:

1. **Bugs and logic errors** — flag any obvious bugs or code that won't behave as intended
2. **Unclear naming** — point out any variable, function, or class names that don't clearly describe what they do
3. **One readability improvement** — suggest exactly one change that would make the code easier to read

Format your response like this:
- 🐛 Bugs: [list any bugs, or "None found"]
- 🏷️ Naming: [list naming issues, or "All clear"]
- ✨ Readability: [your one suggestion]

Keep the entire response under 200 words. Be direct. Skip the preamble.

A code editor with the review.md file open, showing the full command contents above


Step 3: Verify the File Is in the Right Place

Before you call the command, double-check the folder structure is correct.


# Lists the contents of your commands folder to confirm the file exists
ls -la .claude/commands/

You should see:


total 8
drwxr-xr-x  3 you  staff   96 Aug 10 09:00 .
drwxr-xr-x  4 you  staff  128 Aug 10 09:00 ..
-rw-r--r--  1 you  staff  412 Aug 10 09:00 review.md

If review.md appears in the list, you’re ready to call it.

⚠️ Warning: The file must be inside .claude/commands/ — not .claude/ directly, and not anywhere else in your project. Claude Code only looks in the commands/ subfolder for slash commands.


Step 4: Call Your New Command

Open (or restart) your Claude Code session inside the project folder. Then type:


# How to call your new custom slash command
/review

Claude Code reads review.md, follows every instruction in it, and applies the review to whatever code you’re currently working on.

Claude Code terminal showing /review being typed and the formatted response appearing with the bug, naming, and readability sections

If the command doesn’t appear or doesn’t work, check the troubleshooting section below.


Step 5: Test With Real Code

To see the command in action, paste a snippet of code with an intentional issue into the conversation before calling /review. Here’s an example:


# Example code to test your /review command against
def x(a, b):
    result = a + b
    if result = 10:
        print("ten")
    return result

Now call /review. Claude should catch the syntax error on the if line (= instead of ==), flag the unclear function name x, and suggest a readability improvement.

If it does all three — your command is working perfectly.


Understanding What the File Can Contain

Your command file is plain Markdown. Claude reads and follows everything in it as instructions. Here’s what works well inside a command file:

Numbered steps — Claude follows ordered lists reliably:


# Command that follows a numbered sequence
1. First, check for syntax errors
2. Then look for performance issues
3. Finally, suggest one improvement

Formatting instructions — you can dictate how Claude structures its response:


# Command with structured output format
Format your response as a bulleted list with emoji icons.

Persona or tone instructions — you can shape how Claude sounds:


# Command that sets the response style
Be concise. No introductory sentences. Get straight to the findings.

Context about your project — you can bake in project-specific knowledge:


# Command with project-specific context baked in
This project uses Python 3.11 and follows PEP 8. 
Flag any violations of PEP 8 naming conventions.

Creating a Second Command

Once you understand the pattern, creating more commands is fast. Here’s a /commit command that writes a git commit message:


# Creates the commit.md file for a /commit slash command
touch .claude/commands/commit.md

# This is the /commit slash command — writes a conventional commit message

Write a git commit message for the changes I've made. Follow the Conventional Commits format:

<type>(<scope>): <short description>

[optional body explaining WHY, not WHAT]

Types to use: feat, fix, docs, style, refactor, test, chore

Rules:
- Keep the first line under 72 characters
- Use the imperative mood ("add feature" not "added feature")
- Do not end the first line with a period
- Only include a body if the change needs explanation

Output just the commit message. Nothing else.

Now you have two commands: /review and /commit. Both callable anytime, in one line each.


Common Mistakes and How to Fix Them

The command doesn’t appear when I type /

Check that the file is in .claude/commands/ — not .claude/ directly. Also confirm the file extension is .md, not .txt or no extension.

Claude isn’t following my instructions

Your instructions may be ambiguous. Be more specific. Instead of “check the code quality,” write “flag any variable names shorter than 3 characters.” Concrete beats vague every time.

The command works but gives generic responses

Add more context to your command file. Tell Claude what language you’re using, what framework, what coding standards your team follows. The more specific the file, the more specific the output.

I changed the file but the command isn’t updating

Claude Code reads the file fresh each time you call the command. If you edited the file and the output didn’t change, the file might not have saved. Check your editor.

The command name has a space in it

Filenames with spaces create commands with spaces, which don’t work cleanly. Use hyphens or underscores: code-review.md becomes /code-review.


Key Takeaways

  • A custom slash command is a .md file in .claude/commands/ — the filename is the command name
  • The file contains plain English instructions that Claude follows when you call the command
  • You can have as many commands as you want — each one is its own file
  • Commands are project-specific by default; you can also create global commands (covered in Where to Store Slash Commands (Project vs Global))
  • Writing better instructions = getting better results from your commands

Next Steps

Return to Claude Code Slash Commands & Skills — Full Guide for the full picture.