Tools integration

Claude Code 自定义命令:参数和 Skills

创建 Claude Code 自定义命令,理解 .claude/commands、命令参数、skills、argument-hint 和可维护工作流的区别。

Claude Code 自定义命令

Claude Code 自定义命令适合把重复提示词变成可手动调用的 slash command,例如 review diff、生成 release notes、整理 issue、迁移检查和部署清单。当前更推荐把复杂复用流程迁移到 skills:简单命令继续用 .claude/commands/*.md,需要元数据、参数、辅助文件或自动发现时,用 skill。

快速答案

简单命令可以这样写:

# .claude/commands/review.md

Review the current git diff. Focus on correctness bugs, regressions, security risks, and missing tests.
Lead with concrete findings and file references.

使用时输入:

/review

如果工作流需要说明、参数提示、示例、脚本或辅助文件,改用 skill:

.claude/skills/release-check/SKILL.md

Commands 和 Skills 怎么选

需求推荐方式原因
一个短的可复用 prompt.claude/commands/name.md成本最低,容易维护。
带参数或示例的工作流.claude/skills/name/SKILL.mdSkill 支持 frontmatter 和辅助文件。
团队检查清单Skill更适合放步骤、示例和验证规则。
外部工具访问MCP、CLI 或 pluginCommand 只是指令,不会创造工具能力。
每次会话都要遵守的项目规则CLAUDE.md应该作为项目记忆加载,而不是手动调用。

传递参数

命令名后面的文本就是参数。命令文件要明确告诉 Claude 如何使用这段文本:

# .claude/commands/explain.md

Explain the target provided after `/explain`.
If the user gives a file path, inspect that file first.
If the user gives a concept, explain it with examples from this repository.

使用方式:

/explain src/core/auth/index.ts
/explain MCP server permissions

需要命名参数、参数提示或更清晰的自动补全时,用 skill:

---
description: Draft release notes for the target version.
argument-hint: '[version]'
arguments: version
---
Draft release notes for $version from the current git history.

实用命令示例

Review 当前 diff

# .claude/commands/review.md

Review the current git diff for correctness bugs, regressions, security issues, and missing tests.
Return findings first, with file paths and line numbers.
Do not summarize unless there are findings.

生成 Release Notes

# .claude/commands/release-notes.md

Read the commits since the latest tag and draft concise release notes.
Separate user-facing changes, fixes, and internal maintenance.
Call out migration or rollback risks.

整理 GitHub Issues

# .claude/commands/triage-issues.md

Use GitHub CLI to list open issues, group them by theme, and suggest the next three to handle.
Do not modify issues unless explicitly asked.

安全规则

  • 命令保持短小;长流程迁移到 skill。
  • 不要在命令里隐藏宽权限或危险操作。
  • 稳定项目事实放进 CLAUDE.md,不要在每个命令里重复。
  • release、部署、迁移类命令先在小 diff 上验证。
  • 如果旧 command 被新 skill 完全覆盖,及时删除旧 command。

相关页面

官方来源