Claude Code

Claude Code Slash Commands 模板目录

把重复 Claude Code 提示词整理成可复用 slash commands 的模板目录。

最后更新: 2026年6月15日

模板目录

先准备七个对应常见开发流程的命令。可以保存到 .claude/commands/,也可以在流程变复杂后迁移到 .claude/skills/<name>/SKILL.md。

  • code-review.md:检查当前 diff 并返回按优先级排序的问题。
  • prd.md:把功能想法变成紧凑 PRD。
  • refactor.md:提出并执行范围明确的简化计划。
  • test.md:查找、运行并修复定向测试。
  • security.md:检查认证、注入、密钥和数据暴露风险。
  • changelog.md:总结上次发布以来的用户可见变化。
  • commit-message.md:根据当前 diff 草拟 conventional commit message。

Code Review 模板

当你想要一个轻量项目命令,而不是内置 /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 模板

当产品想法需要变成可实现需求时使用。

---
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 与 Test 模板

给重构和测试分别使用聚焦模板,避免 Claude Code 漂到无关清理。

# .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 与 Commit 模板

这些模板可直接复制,并刻意保持工具权限保守。

# .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.

Claude Code 官方引用

官方 SDK slash commands 页面说明 markdown 命令文件、frontmatter、参数、bash 执行、文件引用和命名空间。skills 文档解释为什么更复杂的 custom commands 推荐迁移到 skills。

常见错误

命令文件越无聊、越明确越好。命令修改状态越多,就越需要精确工具权限和审查步骤。

  • 不同工作流使用同一文件名,导致 slash command 名称混乱。
  • 使用宽泛 Bash 权限,而不是窄范围 git 或 test 命令。
  • 命令只读取 staged diff,却依赖 unstaged changes。
  • 新增文件后忘记运行 /reload-skills 或重启会话。

常见问题

Claude Code slash commands 放在哪里?

旧版 custom command 放在项目 .claude/commands/ 或个人 ~/.claude/commands/;更丰富的格式建议用 skills。

Slash command 能接受参数吗?

可以。命令模板可使用 argument hint、$ARGUMENTS 或位置参数。

Slash command 模板应该提交吗?

如果它对团队有用且不包含密钥、本地路径或危险权限,可以提交。