How do I add my own /command to Claude Code?
Drop a markdown file in .claude/commands/ and Claude picks it up immediately. Project-scoped or user-scoped, your call.
A slash command is a markdown file. That’s the whole feature.
1. Pick a scope
- Project:
.claude/commands/<name>.md— committed with the repo, shared with the team. - User:
~/.claude/commands/<name>.md— only on your machine, available everywhere.
If a command exists in both, the project version wins.
2. Write the file
.claude/commands/review-pr.md:
---
description: Review the current branch's diff for SQL safety and missing tests
---
You are reviewing the diff against `main`. Focus on:
1. SQL queries — are parameters bound? Any string concatenation into SQL?
2. New code paths without tests.
3. Side effects inside conditionals (logging, mutation, network).
Report findings as a numbered list. Do not modify any files.
The diff:
!`git diff main...HEAD`
Two things to notice:
- The
descriptionshows up in the command palette. - The backtick-bang syntax
!`...`runs a shell command and inlines its output. That’s how you give commands access to live state.
3. Use it
In a session, type /review-pr. The full markdown body becomes the prompt, with the git diff substituted in.
4. Add arguments
If you want /review-pr api to scope the review, use $ARGUMENTS:
Review only the files under `$ARGUMENTS` for SQL safety...
When to write one
The bar is low: any prompt you’ve typed twice is worth a slash command. Three times and you’re being silly not to.
Sources
- Skills (formerly slash commands) — Custom commands have been merged into skills; .claude/commands/ files still work
slash-commands customization