What Are Custom Slash Commands in Claude Code?
Claude Code ships with built-in commands like /help and /compact, but you can also create your own custom commands tailored to your specific workflow. Custom slash commands let you package frequently used prompts into reusable one-liners that your entire team can share.
If you've ever found yourself typing the same review checklist, test generation prompt, or deployment checklist over and over, custom commands eliminate that repetition entirely.
How Custom Commands Work
Custom slash commands are simply Markdown files stored in specific directories. Claude Code automatically discovers them and makes them available as slash commands. There are two locations where you can place them.
Project-Level Commands
Create a .claude/commands/ folder at the root of your project and add Markdown files inside it.
my-project/
├── .claude/
│ └── commands/
│ ├── review.md → invoked as /review
│ ├── test-check.md → invoked as /test-check
│ └── deploy-prep.md → invoked as /deploy-prep
├── src/
└── package.json
Commit this folder to your Git repository, and every team member gets the same commands automatically.
Global Commands
Commands placed in ~/.claude/commands/ are available across all projects on your machine.
# Global command location
~/.claude/commands/
├── explain.md → invoked as /explain
└── summarize.md → invoked as /summarizeA good rule of thumb: put personal productivity commands in the global folder, and project-specific workflows in the project folder.
Creating Your First Custom Command
Let's build a code review command step by step.
Step 1: Create the Directory
# Run from your project root
mkdir -p .claude/commandsStep 2: Write the Command File
Create .claude/commands/review.md:
Review the following code for these criteria:
1. **Bugs**: null references, off-by-one errors, type mismatches
2. **Security**: SQL injection, XSS, authentication gaps
3. **Performance**: unnecessary loops, N+1 queries, memory leaks
4. **Readability**: naming conventions, function length, comment quality
5. **Testing**: test coverage, edge case handling
Format your findings as:
- 🔴 Critical: Must fix before merging
- 🟡 Warning: Recommended fixes
- 🟢 Suggestion: Nice-to-have improvements
Target: $ARGUMENTSThe $ARGUMENTS placeholder is automatically replaced with whatever you type after the command name.
Step 3: Use the Command
In Claude Code, simply type:
# Review a specific file
> /review src/auth/login.ts
# Review an entire directory
> /review src/api/That's it — no more copy-pasting the same review checklist every time.
Practical Command Examples
Here are some battle-tested commands that work well in real-world projects.
Test Generation Command
.claude/commands/gen-test.md:
Generate unit tests for the specified file.
Requirements:
- Match the testing framework already used in this project
- Cover happy-path scenarios for all major use cases
- Include error handling, boundary values, and null/undefined cases
- Mock external dependencies appropriately
- Use descriptive test names that explain what's being tested
Place test files under __tests__/ mirroring the source directory structure.
Target: $ARGUMENTSUsage:
> /gen-test src/services/userService.ts
# → generates src/services/__tests__/userService.test.tsCommit Message Generator
.claude/commands/commit-msg.md:
Analyze the currently staged changes and generate a commit message
following the Conventional Commits format.
Rules:
- Type: feat / fix / refactor / docs / test / chore
- Scope: the module or area being changed
- Subject: 50 characters max, imperative mood
- Body: briefly explain why the change was made and its impact
First run `git diff --staged` to inspect the changes,
then propose 3 message options.Refactoring Advisor
.claude/commands/refactor.md:
Analyze the specified code and suggest refactoring improvements.
Evaluation criteria:
- DRY: extract duplicated logic
- Single Responsibility: split oversized functions/classes
- Dependency Injection: improve testability
- Type Safety: eliminate `any`, add type guards
- Error Handling: adopt Result/Either patterns where appropriate
Show each suggestion with before → after code examples.
Include a priority rating (High / Medium / Low) for each change.
Target: $ARGUMENTSCommands vs. Skills
As of 2026, Claude Code offers two extension mechanisms: custom commands and skills. Here's how they compare.
| Feature | Custom Commands | Skills |
|---------|----------------|--------|
| Location | .claude/commands/ | .claude/skills/ |
| File format | Markdown | Markdown with SKILL.md |
| Invocation | /command-name | /skill-name or automatic |
| Auto-trigger | No | Yes (via frontmatter) |
| File management | No | Supported |
Custom commands are ideal for straightforward prompt reuse. Skills are better for complex automations that need auto-triggering or file management capabilities. Importantly, existing .claude/commands/ files continue to work — there's no rush to migrate.
Team Workflow Patterns
Custom commands really shine when shared across a team.
Sharing via Git
# Commit the commands folder
git add .claude/commands/
git commit -m "feat(dx): add team custom slash commands for Claude Code"
git push origin mainAfter a git pull, every team member has access to the same commands.
Recommended Team Command Structure
.claude/commands/
├── review.md # Code review
├── pr-description.md # Auto-generate PR descriptions
├── gen-test.md # Test generation
├── migration.md # Database migration scaffolding
├── api-doc.md # API documentation generation
└── onboarding.md # Codebase walkthrough for new hires
Onboarding Command Example
Help new team members get up to speed quickly with a dedicated onboarding command.
.claude/commands/onboarding.md:
Give a guided tour of this project for a new team member.
Include:
1. Directory structure overview and what each folder does
2. Core tech stack (reference package.json / requirements.txt)
3. How to start the development server
4. How to run tests
5. Environment variable setup (reference .env.example)
6. Key architectural patterns and design decisions
7. Coding conventions (reference linter/formatter configs)
If a CLAUDE.md file exists, incorporate its content as well.Wrapping Up
Custom slash commands in Claude Code are remarkably easy to set up — just create a Markdown file and you're done. For individual productivity, they eliminate repetitive prompting. For teams, committing .claude/commands/ to Git standardizes workflows across the entire engineering organization.
Start small: pick one prompt you find yourself typing repeatedly and turn it into a custom command. You'll notice the improvement immediately.
Once you've got the basics down, explore [building custom skills for Claude Code]((/articles/claude-code/claude-code-custom-skills-development) or [automating workflows with Claude Code Hooks]((/articles/claude-code/claude-code-hooks-workflow-automation) to take your productivity even further.