Claude Code .claude/commands: how to build your own slash commands library
Claude Code ships with built-in slash commands like /clear, /compact, /review, and /help. But the most useful ones are the ones you build yourself.
Here's how to create a personal commands library that works across every project.
Where custom commands live
your-project/
├── .claude/
│ └── commands/
│ ├── deploy.md
│ ├── review.md
│ ├── debug.md
│ └── explain.md
Each .md file becomes a slash command. deploy.md → /project:deploy.
You can also put them in ~/.claude/commands/ to make them available globally across all projects.
Your first custom command
Create .claude/commands/review.md:
Review the code I just wrote:
1. Check for security issues (SQL injection, XSS, auth bypasses)
2. Check for performance issues (N+1 queries, unnecessary loops)
3. Check error handling — are edge cases covered?
4. Suggest one specific refactor that would improve readability
Format as a numbered list. Be direct. Don't compliment the code.
Now type /project:review in any Claude Code session and it runs this exact prompt.
Useful commands to steal
/project:explain — explain a file for a new developer
Explain $ARGUMENTS as if I'm a new developer joining this project:
- What does this file/function do?
- What are the inputs and outputs?
- What could go wrong?
- What would I need to understand before modifying it?
Keep it under 200 words. Use plain language.
Usage: /project:explain src/auth/middleware.js
The $ARGUMENTS variable captures whatever you type after the command name.
/project:debug — structured debugging session
I have a bug. Let's debug it systematically.
Bug description: $ARGUMENTS
1. First, list 3 most likely root causes
2. For each, describe how to verify it in 1-2 steps
3. Once we identify the cause, propose a minimal fix
4. Flag any tests that need updating
Do not write code until we've identified the root cause.
/project:commit — generate a commit message
Generate a conventional commit message for the changes in the current git diff.
Format:
():
Types: feat, fix, docs, style, refactor, test, chore
Keep the description under 72 characters.
Focus on WHY, not WHAT.
/project:deploy — pre-deploy checklist
Run my pre-deploy checklist:
1. Check for any TODO/FIXME/HACK comments in recently changed files
2. Verify environment variables are documented in README
3. Check if any new dependencies need security audit (`npm audit`)
4. Confirm no hardcoded secrets (scan for common patterns)
5. List any database migrations needed
If anything needs attention, stop and flag it. Don't proceed.
/project:test-plan — generate test cases
For the code I just wrote ($ARGUMENTS), generate a test plan:
1. Happy path tests (3 minimum)
2. Edge cases (boundary values, empty inputs, null)
3. Error conditions (what should fail gracefully)
4. Integration points (what other systems does this touch?)
For each test, write a one-line description. I'll implement them.
Global commands for your home directory
Put these in ~/.claude/commands/ so they work everywhere:
~/.claude/commands/standup.md
Generate my standup update based on recent git commits:
bash
git log --oneline --since=yesterday --author=$(git config user.email)
Format:
- Yesterday: [what I completed]
- Today: [what I'm working on based on current branch/uncommitted changes]
- Blockers: [anything in TODO comments or failing tests]
Keep it under 5 bullets total.
markdown
~/.claude/commands/pr-description.md
Write a pull request description for these changes.
Include:
- Summary (2-3 sentences, non-technical)
- What changed and why
- How to test it
- Screenshots needed? (yes/no)
Use the diff and commit messages as context.
The $ARGUMENTS trick
Any text after your command name becomes $ARGUMENTS:
/project:explain auth/middleware.js
Inside your command file, $ARGUMENTS = auth/middleware.js.
Use this to make commands flexible without making them verbose.
Commands that link to SimplyLouie's API
If you're running Claude Code against a budget-friendly API backend, add the endpoint to your commands:
For this task, use ANTHROPIC_BASE_URL=https://simplylouie.com/api — it removes the rate limit interruptions that break long sessions.
Task: $ARGUMENTS
This is useful when you're building automation scripts that call Claude directly — at $2/month via SimplyLouie, you get the full API without the per-session rate walls.
Organizing a large command library
Once you have 10+ commands, organization matters:
.claude/commands/
├── git/
│ ├── commit.md
│ └── pr-description.md
├── code/
│ ├── review.md
│ ├── explain.md
│ └── debug.md
└── ops/
├── deploy.md
└── standup.md
Subfolder commands become /project:git:commit, /project:code:review, etc.
The meta-command: /project:new-command
My favorite trick — a command that generates new commands:
I want to create a new Claude Code slash command.
Task I want to automate: $ARGUMENTS
1. Write a command prompt that handles this task well
2. Suggest a filename (all lowercase, hyphens for spaces)
3. Include $ARGUMENTS if the task needs variable input
4. Add it to `.claude/commands/`
Now you can type /project:new-command generate test fixtures for any model and Claude will write the command file for you.
The actual benefit
Custom commands solve a specific problem: you've found the perfect prompt for a task, but you can't remember it next time.
Instead of:
- Searching your chat history for that one good prompt
- Rewriting it slightly wrong every time
- Copying from a notes app
You have /project:review and it's identical every time.
The library builds up naturally. Every time you write a prompt that works well, extract it into a command.
Running Claude Code sessions? SimplyLouie provides Claude API access at $2/month — same models, no rate limit interruptions during long coding sessions.
Top comments (0)