claude-code-commands
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude Code Commands - Meta Reference
Claude Code 命令 - 元参考文档
This skill provides the definitive reference for creating Claude Code slash commands. Use this when building new commands or improving existing command patterns.
2026 note: Custom slash commands have been merged into skills. Prefer for new work; remains supported for legacy single-file commands.
.claude/skills/<name>/SKILL.md.claude/commands/<name>.md本技能为创建Claude Code斜杠命令提供权威参考。在构建新命令或改进现有命令模式时可使用本文档。
2026年说明:自定义斜杠命令已合并到技能中。新开发建议使用格式;仍支持旧版单文件命令。
.claude/skills/<name>/SKILL.md.claude/commands/<name>.mdWhen to Use This Skill
何时使用本技能
Use this skill when you need to:
- Create a new slash command for repeated workflows
- Add handling to commands
$ARGUMENTS - Invoke agents from commands
- Include file context or bash output in commands
- Organize commands for team sharing
当你需要以下操作时使用本技能:
- 为重复工作流创建新的斜杠命令
- 为命令添加处理功能
$ARGUMENTS - 从命令中调用Agent
- 在命令中包含文件上下文或bash输出
- 整理命令以便团队共享
Quick Reference
快速参考
| Component | Purpose | Example |
|---|---|---|
| Filename | Command name | |
| Content | Prompt template | Instructions for Claude |
| User input | |
| Positional args | |
| Session tracking | |
| Include file | |
| Bash output (preprocessing) | |
| 组件 | 用途 | 示例 |
|---|---|---|
| 文件名 | 命令名称 | |
| 内容 | 提示模板 | 给Claude的指令 |
| 用户输入 | |
| 位置参数 | |
| 会话跟踪 | |
| 包含文件 | |
| Bash输出(预处理) | |
Command Locations
命令位置
Claude Code supports both legacy command files and skill-based commands. Skills are the recommended format because they support frontmatter controls and bundled supporting files.
| Location | Scope | Creates | Use For |
|---|---|---|---|
| Project | | Recommended: team-shared commands with supporting files |
| Personal | | Personal cross-project commands |
| Project | | Legacy single-file commands (still supported) |
| Personal | | Legacy personal commands |
| Nested | | Monorepo subdirectories |
Nested discovery: Claude automatically discovers and in subdirectories when working inside those paths.
.claude/skills/.claude/commands/Claude Code同时支持旧版命令文件和基于技能的命令。推荐使用技能格式,因为它支持前置元数据控制和捆绑支持文件。
| 位置 | 作用范围 | 创建的命令 | 使用场景 |
|---|---|---|---|
| 项目级 | | 推荐:团队共享的带支持文件的命令 |
| 个人级 | | 个人跨项目命令 |
| 项目级 | | 旧版单文件命令(仍支持) |
| 个人级 | | 旧版个人命令 |
| 嵌套级 | | 单体仓库子目录 |
嵌套发现:当在子目录中工作时,Claude会自动发现和目录。
.claude/skills/.claude/commands/Command Structure
命令结构
Skill-based (recommended):
text
.claude/skills/
|-- review/SKILL.md # /review
|-- test/SKILL.md # /test
`-- deploy/SKILL.md # /deployLegacy commands:
text
.claude/commands/
|-- review.md # /review
|-- test.md # /test
`-- deploy.md # /deploy基于技能的格式(推荐):
text
.claude/skills/
|-- review/SKILL.md # /review
|-- test/SKILL.md # /test
`-- deploy/SKILL.md # /deploy旧版命令格式:
text
.claude/commands/
|-- review.md # /review
|-- test.md # /test
`-- deploy.md # /deployCommand Template (Skill-Based)
命令模板(基于技能)
markdown
---
name: command-name
description: Brief description for invocation and auto-loading
argument-hint: [path|#pr] [options]
allowed-tools: Read, Grep, Bash(git:*)
disable-model-invocation: false
---markdown
---
name: command-name
description: 调用和自动加载时显示的简短描述
argument-hint: [path|#pr] [options]
allowed-tools: Read, Grep, Bash(git:*)
disable-model-invocation: false
---Command Title
命令标题
[Clear instructions for what this command does]
User request: $ARGUMENTS
[该命令功能的清晰说明]
用户请求:$ARGUMENTS
Steps
步骤
- [First action Claude should take]
- [Second action]
- [Third action]
- [Claude应执行的第一个操作]
- [第二个操作]
- [第三个操作]
Output Format
输出格式
[Specify expected output structure]
undefined[指定预期的输出结构]
undefinedFrontmatter Fields (Skills)
技能前置元数据字段
| Field | Purpose |
|---|---|
| Slash command name (kebab-case) |
| When to use this skill/command |
| Hint shown during autocomplete for expected arguments |
| Tools this skill can run without extra prompts |
| If |
| If |
| Override the model for this skill |
| Use |
| Subagent used to execute this skill |
| Optional lifecycle hooks for the skill |
Legacy works for single-file commands; prefer skills if you need frontmatter controls or bundled resources.
.claude/commands/*.md| 字段 | 用途 |
|---|---|
| 斜杠命令名称(短横线命名法) |
| 何时使用该技能/命令 |
| 自动补全时显示的预期参数提示 |
| 该技能无需额外提示即可运行的工具 |
| 如果为 |
| 如果为 |
| 覆盖该技能使用的模型 |
| 使用 |
| 用于执行该技能的子Agent |
| 技能的可选生命周期钩子 |
旧版适用于单文件命令;如果需要前置元数据控制或捆绑资源,推荐使用技能格式。
.claude/commands/*.mdallowed-tools Syntax
allowed-tools 语法
yaml
allowed-tools: Read, Grep, Bash(git:*)| Pattern | Meaning |
|---|---|
| Allow any invocation of that tool |
| Allow with specific prefix only |
| Only git commands |
| Only npm test commands |
yaml
allowed-tools: Read, Grep, Bash(git:*)| 模式 | 含义 |
|---|---|
| 允许调用该工具的任何操作 |
| 仅允许带有特定前缀的操作 |
| 仅允许git命令 |
| 仅允许npm test命令 |
$ARGUMENTS Usage
$ARGUMENTS 使用方法
Single Argument
单个参数
markdown
undefinedmarkdown
undefinedCode Review
代码评审
Review the following file or code for quality, security, and best practices:
$ARGUMENTS
Focus on:
- Code quality issues
- Security vulnerabilities
- Performance concerns
- Best practice violations
**Usage**: `/review src/auth.js`评审以下文件或代码的质量、安全性和最佳实践:
$ARGUMENTS
重点关注:
- 代码质量问题
- 安全漏洞
- 性能隐患
- 最佳实践违规
**用法**:`/review src/auth.js`Multiple Arguments
多个参数
markdown
undefinedmarkdown
undefinedCompare Files
文件对比
Compare these two files and explain the differences:
$ARGUMENTS
Provide:
- Line-by-line diff
- Semantic changes
- Impact analysis
**Usage**: `/compare old.js new.js`对比这两个文件并解释差异:
$ARGUMENTS
提供:
- 逐行差异
- 语义变更
- 影响分析
**用法**:`/compare old.js new.js`Optional Arguments
可选参数
markdown
undefinedmarkdown
undefinedRun Tests
运行测试
Run tests for the specified scope.
Scope: $ARGUMENTS
If no scope specified, run all tests.
If scope is a file, run tests for that file.
If scope is a directory, run tests in that directory.
**Usage**: `/test` or `/test auth/` or `/test login.test.ts`为指定范围运行测试。
范围:$ARGUMENTS
如果未指定范围,运行所有测试。
如果范围是文件,运行该文件的测试。
如果范围是目录,运行该目录下的测试。
**用法**:`/test` 或 `/test auth/` 或 `/test login.test.ts`Positional Arguments
位置参数
Use , , etc. for specific arguments (like shell scripts):
$1$2markdown
undefined使用, 等表示特定参数(类似shell脚本):
$1$2markdown
undefinedCompare Files
文件对比
Compare $1 with $2.
Show:
- Line differences
- Semantic changes
- Which version is preferred
**Usage**: `/compare old.js new.js` -> `$1 = "old.js"`, `$2 = "new.js"`
---对比$1和$2。
显示:
- 行差异
- 语义变更
- 推荐版本
**用法**:`/compare old.js new.js` -> `$1 = "old.js"`, `$2 = "new.js"`
---File References (@ Prefix)
文件引用(@ 前缀)
Include file contents directly in the command with :
@markdown
undefined使用直接在命令中包含文件内容:
@markdown
undefinedReview with Context
带上下文的评审
Review this code following our standards.
Project standards:
@CLAUDE.md
Code to review:
$ARGUMENTS
**Usage**: `/review-context src/auth.js` includes CLAUDE.md contents automatically.
---按照我们的标准评审此代码。
项目标准:
@CLAUDE.md
待评审代码:
$ARGUMENTS
**用法**:`/review-context src/auth.js` 会自动包含CLAUDE.md的内容。
---Bash Execution (! Prefix)
Bash 执行(! 前缀)
Execute bash commands and include output with :
!markdown
undefined执行bash命令并包含其输出,使用:
!markdown
undefinedSmart Commit
智能提交
Current status:
!git status --short
Recent commits:
!git log --oneline -5
Staged changes:
!git diff --cached
Generate a commit message for the staged changes.
**Usage**: `/smart-commit` runs git commands and includes their output.
**Important**: The `!command` syntax is preprocessing - commands execute before the content is sent to Claude. Claude only sees the rendered output with actual data, not the command itself.当前状态:
!git status --short
最近提交:
!git log --oneline -5
暂存的变更:
!git diff --cached
为暂存的变更生成提交信息。
**用法**:`/smart-commit` 会运行git命令并包含其输出。
**重要提示**:`!command`语法是预处理 - 命令会在内容发送给Claude之前执行。Claude只会看到包含实际数据的渲染输出,而不是命令本身。Backtick Syntax
反引号语法
For inline execution, use backticks:
markdown
PR diff: !`gh pr diff`
Changed files: !`gh pr diff --name-only`对于内联执行,使用反引号:
markdown
PR差异:!`gh pr diff`
变更文件:!`gh pr diff --name-only`Command Patterns
命令模式
Agent Invocation
Agent 调用
markdown
undefinedmarkdown
undefinedSecurity Audit
安全审计
Perform a comprehensive security audit.
Target: $ARGUMENTS
Use the security-auditor agent to:
- Scan for OWASP Top 10 vulnerabilities
- Check authentication patterns
- Review data validation
- Analyze dependencies
Provide a severity-rated findings report.
undefined执行全面的安全审计。
目标:$ARGUMENTS
使用security-auditor Agent完成以下操作:
- 扫描OWASP Top 10漏洞
- 检查认证模式
- 评审数据验证
- 分析依赖项
提供带严重程度评级的发现报告。
undefinedMulti-Agent Orchestration
多Agent编排
markdown
undefinedmarkdown
undefinedFullstack Feature
全栈功能开发
Build a complete fullstack feature.
Feature: $ARGUMENTS
Workflow:
- Use prd-architect to clarify requirements
- Use system-architect to design approach
- Use backend-engineer for API implementation
- Use frontend-engineer for UI implementation
- Use test-architect for test coverage
Coordinate between agents and ensure integration.
undefined构建完整的全栈功能。
功能:$ARGUMENTS
工作流:
- 使用prd-architect明确需求
- 使用system-architect设计实现方案
- 使用backend-engineer实现API
- 使用frontend-engineer实现UI
- 使用test-architect完成测试覆盖
协调各Agent工作并确保集成性。
undefinedValidation Command
验证命令
markdown
undefinedmarkdown
undefinedPre-Commit Check
提交前检查
Validate changes before commit.
Files: $ARGUMENTS (or all staged files if not specified)
Checklist:
- All tests pass
- No linting errors
- No type errors
- No console.log statements
- No TODO comments
- No hardcoded secrets
Return READY or BLOCKED with details.
---提交前验证变更。
文件:$ARGUMENTS(如果未指定则检查所有暂存文件)
检查清单:
- 所有测试通过
- 无代码检查错误
- 无类型错误
- 无console.log语句
- 无TODO注释
- 无硬编码密钥
返回READY或BLOCKED状态及详细信息。
---Command Categories
命令分类
Development Commands
开发命令
| Command | Purpose |
|---|---|
| Code review |
| Run/write tests |
| Debug issues |
| Improve code |
| 命令 | 用途 |
|---|---|
| 代码评审 |
| 运行/编写测试 |
| 调试问题 |
| 代码重构 |
Architecture Commands
架构命令
| Command | Purpose |
|---|---|
| System design |
| Review architecture |
| Write tech spec |
| 命令 | 用途 |
|---|---|
| 系统设计 |
| 架构评审 |
| 编写技术规格 |
Security Commands
安全命令
| Command | Purpose |
|---|---|
| Security audit |
| Find exposed secrets |
| Check dependencies |
| 命令 | 用途 |
|---|---|
| 安全审计 |
| 查找暴露的密钥 |
| 依赖项检查 |
Operations Commands
运维命令
| Command | Purpose |
|---|---|
| Deployment workflow |
| Rollback changes |
| Incident response |
| 命令 | 用途 |
|---|---|
| 部署工作流 |
| 回滚变更 |
| 事件响应 |
Naming Conventions
命名规范
| Pattern | Example | Use For |
|---|---|---|
| | Simple actions |
| | Specific targets |
| | Domain-prefixed |
| | Tool-specific |
| 模式 | 示例 | 适用场景 |
|---|---|---|
| | 简单操作 |
| | 特定目标 |
| | 领域前缀 |
| | 工具特定 |
Command vs Agent vs Skill
命令 vs Agent vs 技能
| Feature | Command | Agent | Skill |
|---|---|---|---|
| Trigger | User types | Claude decides | Claude loads |
| Purpose | Quick shortcuts | Complex work | Knowledge |
| Statefulness | Stateless | Maintains context | Reference only |
| Length | Short prompt | Full instructions | Detailed docs |
Flow: User -> Command -> Agent -> Skill
| 特性 | 命令 | Agent | 技能 |
|---|---|---|---|
| 触发方式 | 用户输入 | Claude自动决定 | Claude自动加载 |
| 用途 | 快速快捷方式 | 复杂工作 | 知识参考 |
| 状态性 | 无状态 | 保持上下文 | 仅参考 |
| 长度 | 短提示 | 完整指令 | 详细文档 |
流程:用户 -> 命令 -> Agent -> 技能
Invocation Control
调用控制
Control who can invoke commands using frontmatter:
| Frontmatter | User Invokes | Claude Invokes | Use Case |
|---|---|---|---|
| (default) | Yes ( | Yes (auto) | General commands |
| Yes ( | No (never) | Deploy, commit, dangerous ops |
| No (hidden) | Yes (auto) | Background knowledge only |
使用前置元数据控制谁可以调用命令:
| 前置元数据 | 用户可调用 | Claude可自动调用 | 用例 |
|---|---|---|---|
| (默认) | 是( | 是(自动) | 通用命令 |
| 是( | 否(从不) | 部署、提交、危险操作 |
| 否(隐藏) | 是(自动) | 仅后台知识参考 |
Example: User-Only Command
示例:仅用户可调用的命令
yaml
---
description: Deploy to production
disable-model-invocation: true
allowed-tools: Bash(kubectl:*), Bash(docker:*)
---yaml
---
description: 部署到生产环境
disable-model-invocation: true
allowed-tools: Bash(kubectl:*), Bash(docker:*)
---Deploy
部署
Deploy $ARGUMENTS to production cluster.
Claude cannot auto-invoke this - user must explicitly type `/deploy`.
---将$ARGUMENTS部署到生产集群。
Claude无法自动调用此命令 - 用户必须显式输入`/deploy`。
---Context Budget
上下文预算
Default skill/command description budget: 15,000 characters.
If many commands are excluded from context:
bash
export SLASH_COMMAND_TOOL_CHAR_BUDGET=20000Check with command for warnings about excluded skills.
/context默认技能/命令描述预算:15,000字符。
如果许多命令被排除在上下文之外:
bash
export SLASH_COMMAND_TOOL_CHAR_BUDGET=20000使用命令查看关于被排除技能的警告。
/contextBest Practices
最佳实践
DO
正确示例
markdown
undefinedmarkdown
undefinedGood Command
优秀命令
Clear, specific instructions.
Target: $ARGUMENTS
- First, analyze the target
- Then, perform action X
- Finally, output result Y
Expected output:
- Summary of findings
- Actionable recommendations
undefined清晰、具体的指令。
目标:$ARGUMENTS
- 首先,分析目标
- 然后,执行操作X
- 最后,输出结果Y
预期输出:
- 发现总结
- 可执行的建议
undefinedDON'T
错误示例
markdown
undefinedmarkdown
undefinedBad Command
糟糕命令
Do stuff with $ARGUMENTS.
Make it good.
---用$ARGUMENTS做些事情。
做得好一点。
---Advanced Patterns
高级模式
Conditional Logic
条件逻辑
markdown
undefinedmarkdown
undefinedSmart Review
智能评审
Review target: $ARGUMENTS
If target is a PR number (e.g., #123):
- Fetch PR details with
gh pr view - Review all changed files
If target is a file path:
- Review that specific file
If target is a directory:
- Review all files in directory
undefined评审目标:$ARGUMENTS
如果目标是PR编号(例如:#123):
- 使用获取PR详情
gh pr view - 评审所有变更文件
如果目标是文件路径:
- 评审该特定文件
如果目标是目录:
- 评审目录下的所有文件
undefinedTemplate with Options
带选项的模板
markdown
undefinedmarkdown
undefinedGenerate Tests
生成测试
Generate tests for: $ARGUMENTS
Options (parsed from arguments):
- - Unit tests only
--unit - - E2E tests only
--e2e - - Include coverage report
--coverage
Default: Generate both unit and E2E tests.
---为以下内容生成测试:$ARGUMENTS
选项(从参数解析):
- - 仅单元测试
--unit - - 仅端到端测试
--e2e - - 包含覆盖率报告
--coverage
默认:同时生成单元和端到端测试。
---Navigation
导航
Resources
资源
- references/command-patterns.md - Common patterns
- references/command-examples.md - Full examples
- data/sources.json - Documentation links
- references/command-patterns.md - 常见模式
- references/command-examples.md - 完整示例
- data/sources.json - 文档链接
Related Skills
相关技能
- ../claude-code-agents/SKILL.md - Agent creation
- ../claude-code-skills/SKILL.md - Skill creation
- ../claude-code-hooks/SKILL.md - Hook automation
- ../claude-code-agents/SKILL.md - Agent创建
- ../claude-code-skills/SKILL.md - 技能创建
- ../claude-code-hooks/SKILL.md - 钩子自动化