DEV Community

myougaTheAxo
myougaTheAxo

Posted on • Originally published at zenn.dev

Claude Code Custom Slash Commands: Automate Your Repetitive Workflows

Claude Code Custom Slash Commands: Automate Your Repetitive Workflows

What Are Custom Slash Commands?

Claude Code lets you create your own commands like /commit, /review-pr, etc.

Put repetitive work into a single command so you never have to write the same instructions again.

How It Works

Just place Markdown files in .claude/commands/:

.claude/
  commands/
    review.md       → /review
    deploy-check.md → /deploy-check
    db-migrate.md   → /db-migrate
Enter fullscreen mode Exit fullscreen mode

Example 1: Code Review Command

.claude/commands/review.md:

# Code Review

Review current changes (`git diff HEAD`):

1. **Bug risks**: Crash or data corruption potential
2. **Security**: OWASP Top 10 perspective
3. **Performance**: N+1 queries, unnecessary loops
4. **Readability**: Variable names, function length, complexity
5. **Tests**: Coverage gaps

Include file:line numbers for each issue.
Severity: 🔴 must fix / 🟡 recommended / 🟢 suggestion
Enter fullscreen mode Exit fullscreen mode
claude /review
Enter fullscreen mode Exit fullscreen mode

Example 2: Pre-Deploy Checklist

.claude/commands/deploy-check.md:

# Pre-Deploy Checklist

Before production deployment:

## Automated
- [ ] `npm test` — all tests pass
- [ ] `npm run lint` — zero lint errors
- [ ] `npm run build` — build succeeds

## Manual
- [ ] `.env.production` has all required variables
- [ ] DB migrations have run
- [ ] Rollback plan is ready

If any issue found, stop and report. If all OK, output "Deploy Ready".
Enter fullscreen mode Exit fullscreen mode

Example 3: DB Migration Generator

.claude/commands/db-migrate.md:

# DB Migration Generator

Generate migration for: $ARGUMENTS

1. Check existing migrations in `migrations/`
2. Create new migration with timestamp in filename
3. Write both UP (apply) and DOWN (rollback)
4. Document impact on existing data
5. Output the migration run command

ORM: Prisma (see prisma/schema.prisma)
Enter fullscreen mode Exit fullscreen mode
claude /db-migrate "add last_login_at to users table"
Enter fullscreen mode Exit fullscreen mode

Team Sharing Strategy

.claude/
  commands/          ← Team shared (git tracked)
    review.md
    deploy-check.md

~/.claude/
  commands/          ← Personal (not git tracked)
    my-debug.md
Enter fullscreen mode Exit fullscreen mode

Using Arguments

# Run Tests

Run tests for `$ARGUMENTS` module and analyze any failures.
Enter fullscreen mode Exit fullscreen mode
claude /test UserService
claude /test PaymentController
Enter fullscreen mode Exit fullscreen mode

Summary

Command Effect
/review Standardize PR quality checks
/deploy-check Automate deployment verification
/db-migrate Consistent migration generation
/pr Unified PR creation flow

Make a habit of turning repetitive instructions into commands—it raises the productivity floor for your entire team.


This article is an excerpt from the Claude Code Complete Guide (7 chapters), available on note.com.
myouga (@myougatheaxo) - VTuber axolotl. Sharing practical AI development tips.

Top comments (0)