claude-code-commands

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claude 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
.claude/skills/<name>/SKILL.md
for new work;
.claude/commands/<name>.md
remains supported for legacy single-file commands.
本技能为创建Claude Code斜杠命令提供权威参考。在构建新命令或改进现有命令模式时可使用本文档。
2026年说明:自定义斜杠命令已合并到技能中。新开发建议使用
.claude/skills/<name>/SKILL.md
格式;
.claude/commands/<name>.md
仍支持旧版单文件命令。

When to Use This Skill

何时使用本技能

Use this skill when you need to:
  • Create a new slash command for repeated workflows
  • Add
    $ARGUMENTS
    handling to commands
  • Invoke agents from commands
  • Include file context or bash output in commands
  • Organize commands for team sharing
当你需要以下操作时使用本技能:
  • 为重复工作流创建新的斜杠命令
  • 为命令添加
    $ARGUMENTS
    处理功能
  • 从命令中调用Agent
  • 在命令中包含文件上下文或bash输出
  • 整理命令以便团队共享

Quick Reference

快速参考

ComponentPurposeExample
FilenameCommand name
review.md
->
/review
ContentPrompt templateInstructions for Claude
$ARGUMENTS
User input
/review auth.js
->
$ARGUMENTS = "auth.js"
$1
,
$2
Positional args
/compare a.js b.js
->
$1 = "a.js"
${CLAUDE_SESSION_ID}
Session tracking
logs/${CLAUDE_SESSION_ID}.log
@file
Include file
@CLAUDE.md
includes file contents
!command
Bash output (preprocessing)
!git status
includes command output
组件用途示例
文件名命令名称
review.md
->
/review
内容提示模板给Claude的指令
$ARGUMENTS
用户输入
/review auth.js
->
$ARGUMENTS = "auth.js"
$1
,
$2
位置参数
/compare a.js b.js
->
$1 = "a.js"
${CLAUDE_SESSION_ID}
会话跟踪
logs/${CLAUDE_SESSION_ID}.log
@file
包含文件
@CLAUDE.md
会包含文件内容
!command
Bash输出(预处理)
!git status
会包含命令输出

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.
LocationScopeCreatesUse For
.claude/skills/<name>/SKILL.md
Project
/name
Recommended: team-shared commands with supporting files
~/.claude/skills/<name>/SKILL.md
Personal
/name
Personal cross-project commands
.claude/commands/<name>.md
Project
/name
Legacy single-file commands (still supported)
~/.claude/commands/<name>.md
Personal
/name
Legacy personal commands
packages/*/.claude/skills/<name>/SKILL.md
Nested
/name
Monorepo subdirectories
Nested discovery: Claude automatically discovers
.claude/skills/
and
.claude/commands/
in subdirectories when working inside those paths.
Claude Code同时支持旧版命令文件和基于技能的命令。推荐使用技能格式,因为它支持前置元数据控制和捆绑支持文件。
位置作用范围创建的命令使用场景
.claude/skills/<name>/SKILL.md
项目级
/name
推荐:团队共享的带支持文件的命令
~/.claude/skills/<name>/SKILL.md
个人级
/name
个人跨项目命令
.claude/commands/<name>.md
项目级
/name
旧版单文件命令(仍支持)
~/.claude/commands/<name>.md
个人级
/name
旧版个人命令
packages/*/.claude/skills/<name>/SKILL.md
嵌套级
/name
单体仓库子目录
嵌套发现:当在子目录中工作时,Claude会自动发现
.claude/skills/
.claude/commands/
目录。

Command Structure

命令结构

Skill-based (recommended):
text
.claude/skills/
|-- review/SKILL.md           # /review
|-- test/SKILL.md             # /test
`-- deploy/SKILL.md           # /deploy
Legacy 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                 # /deploy

Command 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

步骤

  1. [First action Claude should take]
  2. [Second action]
  3. [Third action]
  1. [Claude应执行的第一个操作]
  2. [第二个操作]
  3. [第三个操作]

Output Format

输出格式

[Specify expected output structure]
undefined
[指定预期的输出结构]
undefined

Frontmatter Fields (Skills)

技能前置元数据字段

FieldPurpose
name
Slash command name (kebab-case)
description
When to use this skill/command
argument-hint
Hint shown during autocomplete for expected arguments
allowed-tools
Tools this skill can run without extra prompts
disable-model-invocation
If
true
, Claude will not auto-invoke
user-invocable
If
false
, hidden from the
/
menu
model
Override the model for this skill
context
Use
fork
for isolated execution
agent
Subagent used to execute this skill
hooks
Optional lifecycle hooks for the skill
Legacy
.claude/commands/*.md
works for single-file commands; prefer skills if you need frontmatter controls or bundled resources.
字段用途
name
斜杠命令名称(短横线命名法)
description
何时使用该技能/命令
argument-hint
自动补全时显示的预期参数提示
allowed-tools
该技能无需额外提示即可运行的工具
disable-model-invocation
如果为
true
,Claude不会自动调用该技能
user-invocable
如果为
false
,会在
/
菜单中隐藏
model
覆盖该技能使用的模型
context
使用
fork
实现隔离执行
agent
用于执行该技能的子Agent
hooks
技能的可选生命周期钩子
旧版
.claude/commands/*.md
适用于单文件命令;如果需要前置元数据控制或捆绑资源,推荐使用技能格式。

allowed-tools Syntax

allowed-tools 语法

yaml
allowed-tools: Read, Grep, Bash(git:*)
PatternMeaning
Tool
Allow any invocation of that tool
Tool(prefix:*)
Allow with specific prefix only
Bash(git:*)
Only git commands
Bash(npm test:*)
Only npm test commands
yaml
allowed-tools: Read, Grep, Bash(git:*)
模式含义
Tool
允许调用该工具的任何操作
Tool(prefix:*)
仅允许带有特定前缀的操作
Bash(git:*)
仅允许git命令
Bash(npm test:*)
仅允许npm test命令

$ARGUMENTS Usage

$ARGUMENTS 使用方法

Single Argument

单个参数

markdown
undefined
markdown
undefined

Code 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
undefined
markdown
undefined

Compare 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
undefined
markdown
undefined

Run 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
$1
,
$2
, etc. for specific arguments (like shell scripts):
markdown
undefined
使用
$1
,
$2
等表示特定参数(类似shell脚本):
markdown
undefined

Compare 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
undefined

Review 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
undefined

Smart 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
undefined
markdown
undefined

Security Audit

安全审计

Perform a comprehensive security audit.
Target: $ARGUMENTS
Use the security-auditor agent to:
  1. Scan for OWASP Top 10 vulnerabilities
  2. Check authentication patterns
  3. Review data validation
  4. Analyze dependencies
Provide a severity-rated findings report.
undefined
执行全面的安全审计。
目标:$ARGUMENTS
使用security-auditor Agent完成以下操作:
  1. 扫描OWASP Top 10漏洞
  2. 检查认证模式
  3. 评审数据验证
  4. 分析依赖项
提供带严重程度评级的发现报告。
undefined

Multi-Agent Orchestration

多Agent编排

markdown
undefined
markdown
undefined

Fullstack Feature

全栈功能开发

Build a complete fullstack feature.
Feature: $ARGUMENTS
Workflow:
  1. Use prd-architect to clarify requirements
  2. Use system-architect to design approach
  3. Use backend-engineer for API implementation
  4. Use frontend-engineer for UI implementation
  5. Use test-architect for test coverage
Coordinate between agents and ensure integration.
undefined
构建完整的全栈功能。
功能:$ARGUMENTS
工作流:
  1. 使用prd-architect明确需求
  2. 使用system-architect设计实现方案
  3. 使用backend-engineer实现API
  4. 使用frontend-engineer实现UI
  5. 使用test-architect完成测试覆盖
协调各Agent工作并确保集成性。
undefined

Validation Command

验证命令

markdown
undefined
markdown
undefined

Pre-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

开发命令

CommandPurpose
/review
Code review
/test
Run/write tests
/debug
Debug issues
/refactor
Improve code
命令用途
/review
代码评审
/test
运行/编写测试
/debug
调试问题
/refactor
代码重构

Architecture Commands

架构命令

CommandPurpose
/design
System design
/architecture-review
Review architecture
/tech-spec
Write tech spec
命令用途
/design
系统设计
/architecture-review
架构评审
/tech-spec
编写技术规格

Security Commands

安全命令

CommandPurpose
/security-scan
Security audit
/secrets-check
Find exposed secrets
/dependency-audit
Check dependencies
命令用途
/security-scan
安全审计
/secrets-check
查找暴露的密钥
/dependency-audit
依赖项检查

Operations Commands

运维命令

CommandPurpose
/deploy
Deployment workflow
/rollback
Rollback changes
/incident
Incident response

命令用途
/deploy
部署工作流
/rollback
回滚变更
/incident
事件响应

Naming Conventions

命名规范

PatternExampleUse For
{action}
/review
Simple actions
{action}-{target}
/security-scan
Specific targets
{domain}-{action}
/pm-strategy
Domain-prefixed
{tool}-{action}
/git-commit
Tool-specific

模式示例适用场景
{action}
/review
简单操作
{action}-{target}
/security-scan
特定目标
{domain}-{action}
/pm-strategy
领域前缀
{tool}-{action}
/git-commit
工具特定

Command vs Agent vs Skill

命令 vs Agent vs 技能

FeatureCommandAgentSkill
TriggerUser types
/command
Claude decidesClaude loads
PurposeQuick shortcutsComplex workKnowledge
StatefulnessStatelessMaintains contextReference only
LengthShort promptFull instructionsDetailed docs
Flow: User -> Command -> Agent -> Skill

特性命令Agent技能
触发方式用户输入
/command
Claude自动决定Claude自动加载
用途快速快捷方式复杂工作知识参考
状态性无状态保持上下文仅参考
长度短提示完整指令详细文档
流程:用户 -> 命令 -> Agent -> 技能

Invocation Control

调用控制

Control who can invoke commands using frontmatter:
FrontmatterUser InvokesClaude InvokesUse Case
(default)Yes (
/name
)
Yes (auto)General commands
disable-model-invocation: true
Yes (
/name
)
No (never)Deploy, commit, dangerous ops
user-invocable: false
No (hidden)Yes (auto)Background knowledge only
使用前置元数据控制谁可以调用命令:
前置元数据用户可调用Claude可自动调用用例
(默认)是(
/name
是(自动)通用命令
disable-model-invocation: true
是(
/name
否(从不)部署、提交、危险操作
user-invocable: false
否(隐藏)是(自动)仅后台知识参考

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=20000
Check with
/context
command for warnings about excluded skills.

默认技能/命令描述预算:15,000字符
如果许多命令被排除在上下文之外:
bash
export SLASH_COMMAND_TOOL_CHAR_BUDGET=20000
使用
/context
命令查看关于被排除技能的警告。

Best Practices

最佳实践

DO

正确示例

markdown
undefined
markdown
undefined

Good Command

优秀命令

Clear, specific instructions.
Target: $ARGUMENTS
  1. First, analyze the target
  2. Then, perform action X
  3. Finally, output result Y
Expected output:
  • Summary of findings
  • Actionable recommendations
undefined
清晰、具体的指令。
目标:$ARGUMENTS
  1. 首先,分析目标
  2. 然后,执行操作X
  3. 最后,输出结果Y
预期输出:
  • 发现总结
  • 可执行的建议
undefined

DON'T

错误示例

markdown
undefined
markdown
undefined

Bad Command

糟糕命令

Do stuff with $ARGUMENTS.
Make it good.

---
用$ARGUMENTS做些事情。
做得好一点。

---

Advanced Patterns

高级模式

Conditional Logic

条件逻辑

markdown
undefined
markdown
undefined

Smart 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):
  • 使用
    gh pr view
    获取PR详情
  • 评审所有变更文件
如果目标是文件路径:
  • 评审该特定文件
如果目标是目录:
  • 评审目录下的所有文件
undefined

Template with Options

带选项的模板

markdown
undefined
markdown
undefined

Generate Tests

生成测试

Generate tests for: $ARGUMENTS
Options (parsed from arguments):
  • --unit
    - Unit tests only
  • --e2e
    - E2E tests only
  • --coverage
    - Include coverage report
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 - 钩子自动化