Template Directory
Start with seven reusable commands that map to common development workflows. Save them as markdown files under .claude/commands/ or convert them to .claude/skills/<name>/SKILL.md as the workflow grows.
- code-review.md: inspect the current diff and return prioritized findings.
- prd.md: turn a feature idea into a compact product requirements draft.
- refactor.md: propose and apply a scoped simplification plan.
- test.md: find, run, and fix targeted tests.
- security.md: review auth, injection, secrets, and data exposure risks.
- changelog.md: summarize user-visible changes since the last release.
- commit-message.md: draft a conventional commit message from the current diff.
Code Review Template
Use this for /code-review-local when you want a lightweight project command rather than the bundled /code-review skill.
--- description: Review the current git diff for correctness issues allowed-tools: Read, Grep, Glob, Bash(git diff *) --- Review the current changes for bugs, regressions, missing tests, security concerns, and unnecessary complexity. Context: - Changed files: !`git diff --name-only HEAD` - Diff: !`git diff HEAD` Return findings first, ordered by severity. Include file paths and exact lines when possible.
PRD Template
Use this for /prd when product ideas need to become implementation-ready requirements.
--- description: Draft a concise PRD from a feature idea argument-hint: [feature or problem] allowed-tools: Read, Grep, Glob --- Create a PRD for: $ARGUMENTS Include: 1. Problem and target user 2. Goals and non-goals 3. User stories 4. UX states and edge cases 5. Technical notes from the repo 6. Acceptance criteria 7. Open questions
Refactor And Test Templates
Use focused templates for refactor and test workflows so Claude Code does not drift into unrelated cleanup.
# .claude/commands/refactor.md --- description: Plan and apply a scoped refactor argument-hint: [file or area] allowed-tools: Read, Grep, Glob, Edit, Bash(npm test *) --- Refactor $ARGUMENTS without changing behavior. First explain the smallest safe plan, then edit, then run the most relevant test. # .claude/commands/test.md --- description: Run and repair targeted tests argument-hint: [test pattern or area] allowed-tools: Read, Grep, Glob, Edit, Bash(npm test *) --- Find tests related to $ARGUMENTS, run the narrowest useful command, fix failures caused by the current changes, and summarize what remains.
Security, Changelog, And Commit Templates
These templates are copy-ready and intentionally conservative about tools.
# .claude/commands/security.md --- description: Review changes for security risks allowed-tools: Read, Grep, Glob, Bash(git diff *) --- Review the diff for auth bypass, injection, exposed secrets, unsafe deserialization, SSRF, path traversal, and data leakage. # .claude/commands/changelog.md --- description: Draft changelog notes from the current diff allowed-tools: Bash(git log *), Bash(git diff *) --- Draft concise changelog bullets grouped by Added, Changed, Fixed, and Migration Notes. # .claude/commands/commit-message.md --- description: Draft a conventional commit message allowed-tools: Bash(git diff --cached *), Bash(git status *) --- Write one conventional commit subject and a short body based on the staged diff.
Official Claude Code References
The official SDK slash commands page documents markdown command files, frontmatter, arguments, bash execution, file references, and namespacing. The skills guide explains why skills are now the recommended format for richer custom commands.
Common Errors
Keep command files boring and explicit. The more a command mutates state, the more carefully its tool permissions and review steps should be documented.
- Using the same filename for different workflows and confusing the slash command name.
- Adding broad Bash permission when a narrow git or test command is enough.
- Depending on unstaged changes when the command reads only staged diff.
- Forgetting to run /reload-skills or restart the session after adding files.
FAQ
Where do Claude Code slash commands live?
Legacy custom command files live in .claude/commands/ for a project or ~/.claude/commands/ for personal commands. Skills are now the recommended richer format.
Can a slash command accept arguments?
Yes. Command templates can use argument hints and placeholders such as $ARGUMENTS or positional values depending on the format.
Should slash command templates be committed?
Commit project commands when they are useful for the team and do not expose secrets, local-only paths, or risky permissions.