Claude Tips mascot
Claude Tips & Tricks
Claude Code intermediate

Create Custom Slash Commands as Prompt Templates

Define reusable prompt templates in .claude/commands/. Each markdown file becomes a slash command you can invoke with /command-name.

You can create your own slash commands in Claude Code by adding markdown files to the .claude/commands/ directory in your project. Each file becomes a reusable prompt template.

Setup:

mkdir -p .claude/commands

Example: code review command

# .claude/commands/review.md
Review the current git diff for:
- Security vulnerabilities
- Performance issues
- Error handling gaps
- Missing edge cases

Format your review as a markdown checklist with severity levels.

Now type /review in Claude Code to run it.

Example: test generation command

# .claude/commands/test.md
Look at the file I have open and generate comprehensive unit tests for it.
Use the existing test framework in the project.
Cover: happy path, edge cases, error cases, and boundary conditions.

Using variables:

Commands support a $ARGUMENTS placeholder for dynamic input:

# .claude/commands/explain.md
Explain the following concept as if teaching a junior developer: $ARGUMENTS

Usage: /explain dependency injection

Team sharing: Commit the .claude/commands/ directory to your repo so the whole team gets the same commands.

Skill files: For more advanced use cases, use .claude/skills/<name>/SKILL.md instead. These can be auto-invoked by Claude when the task matches the skill description, without you explicitly calling a slash command.

Paste into Claude Code
Create a .claude/commands/ directory with these custom slash commands: review.md (code review the current diff), test.md (write tests for recent changes), and refactor.md (suggest refactoring for selected code).