Working Code
Let's create a custom command for your project. Create a markdown file in the .claude/commands/ directory:
> Create .claude/commands/review.md with this content:
>
> Review the current git diff changes.
> Check from these perspectives:
> 1. Potential bugs
> 2. Security vulnerabilities
> 3. Performance issues
> 4. Coding convention violations
>
> For each item, say "Pass" if no issues, or explain the problem in detail.
Now use it in a Claude Code session:
> /project:review
The custom command runs and performs the code review automatically.
Try It Yourself
Create a more practical command:
Test generation command — .claude/commands/test.md:
Write unit tests for all public functions in $ARGUMENTS.
Requirements:
- Test framework: whatever the project uses
- Include normal cases, error cases, and edge cases
- Add clear descriptions for each test
- Filename: original-filename.test.{extension}
Usage:
> /project:test src/utils/validator.ts
$ARGUMENTS gets replaced with src/utils/validator.ts.
"Why?" — Turning Repetitive Tasks into Patterns
During development, you end up repeating the same types of requests: "review the code," "write tests," "add types." Instead of typing detailed prompts every time, it's more efficient to create a well-crafted command once and reuse it.
Command Storage Locations
| Location | Usage | Purpose |
| --------------------- | ------------------ | ----------------------------------------- |
| .claude/commands/ | /project:command | Shared with the team (included in Git) |
| ~/.claude/commands/ | /user:command | Personal only (available in all projects) |
The $ARGUMENTS Variable
When you include $ARGUMENTS in a command file, the text after the slash command is substituted in:
/project:test src/utils/validator.ts
^^^^^^^^^^^^^^^^^^^^^^^^
This part goes into $ARGUMENTS
What Makes a Good Custom Command
- Specific instructions — use a checklist instead of "do it well"
- Reusable — use
$ARGUMENTSto dynamically specify the target - Defined output format — "organize as a table," "output as markdown"
Deep Dive
Example command collections for the whole team
Useful commands in practice:
/project:review— code review/project:test— test generation/project:docs— function/module documentation/project:migrate— DB migration generation/project:changelog— changelog writing
Put these files in .claude/commands/ and commit to Git so the entire team uses the same commands.
- Create
.claude/commands/docs.mdthat generates JSDoc/TSDoc for the$ARGUMENTSfile. - Create
~/.claude/commands/explain.mdas a personal command that explains code in plain English. - Run
/project:docs src/index.tsand check the result.
Q1. Where are team-shared custom commands stored?
- A)
~/.claude/commands/ - B)
.claude/commands/ - C)
/etc/claude/commands/ - D)
node_modules/.claude/