New tutorials dropping soon — subscribe to the newsletter for updates.

Custom Slash Commands

Stay lazy, code smarter

New tutorials and tips straight to your inbox

Custom Slash Commands

February 15, 20251:30

Create your own slash commands to automate repetitive tasks in Claude Code.

What Are Slash Commands?

Slash commands are reusable prompts you can trigger with /command-name in Claude Code. Instead of typing the same instructions every time, you save them once and invoke them with a shortcut.

Where They Live

Slash commands are markdown files in a .claude/commands/ directory:

your-project/
├── .claude/
│   └── commands/
│       ├── review.md
│       ├── test.md
│       └── deploy-check.md
├── src/
└── package.json

Creating Your First Command

Create .claude/commands/review.md:

Review the changes in my current git diff. For each file:

1. Check for bugs or logic errors
2. Flag any security concerns
3. Note any missing error handling
4. Suggest improvements (but keep it brief)

Focus on substance, not style. Don't comment on formatting.

Now in Claude Code, type /review and it runs this prompt.

Useful Commands to Create

Code Review

# .claude/commands/review.md
Look at the current git diff and review the changes.
Flag bugs, security issues, and missing edge cases.
Skip style nitpicks.

Test Writer

# .claude/commands/test.md
Write tests for the file I specify. Use the existing test
patterns in this project. Cover happy path, error cases,
and edge cases. Run the tests after writing them.

Commit Helper

# .claude/commands/commit.md
Look at the staged changes (git diff --cached).
Write a concise commit message following conventional commits format.
Create the commit.

Quick Refactor

# .claude/commands/refactor.md
Refactor the file I specify for readability:
- Extract magic numbers into named constants
- Simplify complex conditionals
- Add types where they're missing
Don't change behavior. Run tests after.

Using Arguments

Your slash commands can reference the file context. When you type /test src/lib/auth.ts, Claude receives both the command prompt and the file path.

Team Commands vs Personal Commands

  • Project commands (.claude/commands/) — Checked into git, shared with team
  • Personal commands (~/.claude/commands/) — Your home directory, personal shortcuts

Tips

  1. Keep commands focused — One command, one task
  2. Include constraints — "Don't change behavior" or "Follow existing patterns"
  3. Add verification steps — "Run tests after" or "Show me the diff before committing"
  4. Iterate on them — If a command gives inconsistent results, make the prompt more specific

Stay lazy.

Get bite-sized AI coding tips delivered to your inbox every week. No spam, unsubscribe anytime.