command-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Command Creator

命令创建器

This skill guides the creation of Claude Code slash commands for agents in the Traycer enforcement framework. Claude Code commands are custom slash commands defined as Markdown files containing prompts.
本技能指导你在Traycer执行框架中为Agent创建Claude Code斜杠命令。Claude Code命令是包含提示词的自定义斜杠命令,以Markdown文件形式定义。

When to Use

使用场景

Use command-creator when:
  1. Creating custom slash commands for an agent
  2. Defining reusable prompts that should be invoked explicitly
  3. Building commands that need dynamic arguments
  4. Organizing frequently-used agent prompts
在以下场景使用command-creator:
  1. 为Agent创建自定义斜杠命令
  2. 定义需要显式调用的可复用提示词
  3. 构建需要动态参数的命令
  4. 整理常用的Agent提示词

Understanding Claude Code Commands

理解Claude Code命令

What Are Commands?

什么是命令?

Claude Code commands are custom slash commands that:
  • Are Markdown (.md) files containing prompts
  • Live in
    .claude/commands/
    (project) or
    ~/.claude/commands/
    (personal)
  • Are invoked with
    /command-name
    syntax
  • Support dynamic arguments via placeholders
  • Can execute bash commands before running
  • Can reference files using
    @
    prefix
Commands are NOT:
  • Bash/CLI scripts
  • Python/JavaScript code
  • Complex workflows (those are Skills)
  • Automatically triggered (they require explicit invocation)
Claude Code命令是自定义斜杠命令,具备以下特性:
  • 是包含提示词的Markdown(.md)文件
  • 存储在项目目录的
    .claude/commands/
    或个人目录的
    ~/.claude/commands/
  • 使用
    /command-name
    语法调用
  • 通过占位符支持动态参数
  • 执行前可运行bash命令
  • 使用
    @
    前缀引用文件
命令不是
  • Bash/CLI脚本
  • Python/JavaScript代码
  • 复杂工作流(此类场景使用Skills)
  • 自动触发的任务(需要显式调用)

Commands vs Skills vs System Prompt

命令 vs 技能 vs 系统提示词

ElementPurposeExampleInvocation
CommandsQuick, reusable prompts
/git-commit
,
/review-pr
Explicit:
/command-name
SkillsComplex workflows with multiple files
security-validation
,
test-standards
Automatic based on context
System PromptAgent personality and core behaviorAgent role, coordination logicAlways active
Use commands when:
  • You have a frequently-used prompt
  • Need explicit control over when it runs
  • Prompt fits in a single Markdown file
  • Want to pass dynamic arguments
Use skills when:
  • Workflow requires multiple steps
  • Need scripts, references, or assets
  • Want automatic discovery based on context
  • Multiple agents share the capability
Use system prompt when:
  • Defining agent's core role
  • Specifying agent-specific behavior
  • Coordination with other agents
元素用途示例调用方式
命令快捷、可复用的提示词
/git-commit
,
/review-pr
显式调用:
/command-name
技能涉及多文件的复杂工作流
security-validation
,
test-standards
根据上下文自动触发
系统提示词定义Agent的个性和核心行为Agent角色、协作逻辑始终生效
优先使用命令的场景
  • 你有频繁使用的提示词
  • 需要对执行时机进行显式控制
  • 提示词可容纳在单个Markdown文件中
  • 需要传递动态参数
优先使用技能的场景
  • 工作流需要多步骤执行
  • 需要脚本、引用或资源文件
  • 希望根据上下文自动触发
  • 多个Agent共享该能力
优先使用系统提示词的场景
  • 定义Agent的核心角色
  • 指定Agent的专属行为
  • 与其他Agent的协作逻辑

Command Structure

命令结构

Basic Command File

基础命令文件

File:
.claude/commands/optimize.md
markdown
Analyze this code for performance issues and suggest optimizations:
Invocation:
/optimize
文件路径
.claude/commands/optimize.md
markdown
Analyze this code for performance issues and suggest optimizations:
调用方式
/optimize

Command with Frontmatter

包含前置元数据的命令

File:
.claude/commands/git-commit.md
markdown
---
tools:
argument-hint: [message]
description: Create a git commit
model: haiku
---

Create a git commit with message: $ARGUMENTS
Invocation:
/git-commit "fix: resolve login bug"
文件路径
.claude/commands/git-commit.md
markdown
---
tools:
argument-hint: [message]
description: Create a git commit
model: haiku
---

Create a git commit with message: $ARGUMENTS
调用方式
/git-commit "fix: resolve login bug"

Frontmatter Fields

前置元数据字段说明

FieldPurposeDefaultExample
allowed-tools
Tools command can useInherits from conversation
Bash(git add:*)
argument-hint
Expected argumentsNone
[pr-number] [priority]
description
Brief descriptionFirst line
Create a git commit
model
Specific modelInherits from conversation
haiku
disable-model-invocation
Prevent SlashCommand toolfalse
true
字段用途默认值示例
allowed-tools
命令可使用的工具继承自对话配置
Bash(git add:*)
argument-hint
参数格式提示
[pr-number] [priority]
description
命令简要描述文件第一行内容
Create a git commit
model
指定使用的模型继承自对话配置
haiku
disable-model-invocation
禁止SlashCommand工具调用false
true

Command Features

命令特性

1. Arguments

1. 参数处理

All Arguments with
$ARGUMENTS

使用
$ARGUMENTS
获取所有参数

Captures all arguments as a single string:
markdown
---
description: Fix a GitHub issue
---

Fix issue #$ARGUMENTS following our coding standards:
1. Understand the issue
2. Locate relevant code
3. Implement solution
4. Add tests
5. Prepare PR description
Usage:
bash
/fix-issue 123 high-priority
$ARGUMENTS
becomes:
"123 high-priority"
将所有参数捕获为单个字符串:
markdown
---
description: Fix a GitHub issue
---

Fix issue #$ARGUMENTS following our coding standards:
1. Understand the issue
2. Locate relevant code
3. Implement solution
4. Add tests
5. Prepare PR description
使用示例:
bash
/fix-issue 123 high-priority
$ARGUMENTS
的值为:
"123 high-priority"

Positional Arguments with
$1
,
$2
,
$3

使用
$1
,
$2
,
$3
获取位置参数

Access specific arguments individually:
markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: Review pull request
---

Review PR #$1 with priority $2 and assign to $3.
Focus on security, performance, and code style.
Usage:
bash
/review-pr 456 high alice
  • $1
    =
    "456"
  • $2
    =
    "high"
  • $3
    =
    "alice"
单独访问特定位置的参数:
markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: Review pull request
---

Review PR #$1 with priority $2 and assign to $3.
Focus on security, performance, and code style.
使用示例:
bash
/review-pr 456 high alice
  • $1
    =
    "456"
  • $2
    =
    "high"
  • $3
    =
    "alice"

2. Bash Command Execution

2. Bash命令执行

Execute bash commands before prompt runs using
!
prefix:
markdown
---
tools: Bash(git status:*), Bash(git diff:*), Bash(git log:*)
description: Create a git commit based on current changes
---
使用
!
前缀在提示词执行前运行bash命令:
markdown
---
tools: Bash(git status:*), Bash(git diff:*), Bash(git log:*)
description: Create a git commit based on current changes
---

Context

上下文信息

  • Current git status: !
    git status
  • Staged and unstaged changes: !
    git diff HEAD
  • Current branch: !
    git branch --show-current
  • Recent commits: !
    git log --oneline -10
  • 当前git状态: !
    git status
  • 暂存与未暂存变更: !
    git diff HEAD
  • 当前分支: !
    git branch --show-current
  • 最近提交记录: !
    git log --oneline -10

Your task

任务要求

Based on the above changes, create a single git commit with an appropriate message.

**Important**: Must include `allowed-tools` with `Bash` tool for bash execution.
基于上述变更记录,创建一个合适的git提交信息并完成提交。

**重要提示**:必须在`allowed-tools`中包含`Bash`工具才能执行bash命令。

3. File References

3. 文件引用

Include file contents using
@
prefix:
markdown
---
description: Review specific file implementation
---

Review the implementation in @src/utils/helpers.js and suggest improvements.
Multiple files:
markdown
Compare @src/old-version.js with @src/new-version.js and highlight differences.
使用
@
前缀引入文件内容:
markdown
---
description: Review specific file implementation
---

Review the implementation in @src/utils/helpers.js and suggest improvements.
多文件引用:
markdown
Compare @src/old-version.js with @src/new-version.js and highlight differences.

4. Namespacing

4. 命名空间管理

Organize commands in subdirectories:
Project structure:
text
.claude/commands/
├── git-commit.md          # /git-commit (project)
├── frontend/
│   └── component.md       # /component (project:frontend)
└── qa/
    └── review.md          # /review (project:qa)
Personal structure:
text
~/.claude/commands/
├── security-review.md     # /security-review (user)
└── templates/
    └── pr-template.md     # /pr-template (user:templates)
Conflict handling:
  • User vs project commands with same name: NOT SUPPORTED
  • Commands in different subdirectories: ALLOWED
通过子目录组织命令:
项目目录结构:
text
.claude/commands/
├── git-commit.md          # /git-commit (项目级)
├── frontend/
│   └── component.md       # /component (项目级:frontend)
└── qa/
    └── review.md          # /review (项目级:qa)
个人目录结构:
text
~/.claude/commands/
├── security-review.md     # /security-review (用户级)
└── templates/
    └── pr-template.md     # /pr-template (用户级:templates)
冲突处理:
  • 同名的用户级与项目级命令:不支持
  • 不同子目录下的同名命令:允许

Creating Commands

创建命令的步骤

Step 1: Determine Command Scope

步骤1:确定命令作用域

Project commands (
.claude/commands/
):
  • Shared with team via git
  • Project-specific workflows
  • Show "(project)" in
    /help
Personal commands (
~/.claude/commands/
):
  • Personal workflows across all projects
  • Not shared with team
  • Show "(user)" in
    /help
项目级命令(存储在
.claude/commands/
):
  • 通过git与团队共享
  • 适用于项目专属工作流
  • /help
    中显示"(project)"标识
用户级命令(存储在
~/.claude/commands/
):
  • 适用于所有项目的个人工作流
  • 不与团队共享
  • /help
    中显示"(user)"标识

Step 2: Design Command Interface

步骤2:设计命令接口

Name: Use lowercase, hyphens for spaces
  • Good:
    git-commit
    ,
    review-pr
    ,
    fix-issue
  • Bad:
    GitCommit
    ,
    review_pr
    ,
    fixIssue
Arguments: Decide on argument pattern
  • Simple: Use
    $ARGUMENTS
    for all args
  • Structured: Use
    $1
    ,
    $2
    ,
    $3
    for specific args
Prompt: Write clear instructions
  • Explain what the command should do
  • Provide context (use
    !
    for bash,
    @
    for files)
  • Specify expected output format
命名规则:使用小写字母,用连字符分隔单词
  • 推荐:
    git-commit
    ,
    review-pr
    ,
    fix-issue
  • 不推荐:
    GitCommit
    ,
    review_pr
    ,
    fixIssue
参数设计:确定参数模式
  • 简单场景:使用
    $ARGUMENTS
    获取所有参数
  • 结构化场景:使用
    $1
    ,
    $2
    ,
    $3
    获取特定位置参数
提示词编写:编写清晰的指令
  • 说明命令的功能
  • 提供上下文信息(使用
    !
    调用bash命令,使用
    @
    引用文件)
  • 指定预期的输出格式

Step 3: Create Command File

步骤3:创建命令文件

For project command:
bash
mkdir -p .claude/commands
cat > .claude/commands/review-pr.md << 'EOF'
---
argument-hint: [pr-number]
description: Review pull request for code quality
---

Review pull request #$ARGUMENTS:

1. Check for security vulnerabilities
2. Verify test coverage
3. Assess code quality and style
4. Suggest improvements

Provide summary in Markdown format.
EOF
For personal command:
bash
mkdir -p ~/.claude/commands
cat > ~/.claude/commands/security-scan.md << 'EOF'
---
description: Scan code for security issues
---

Scan this code for security vulnerabilities:
- Hardcoded secrets
- Insecure dependencies
- Authentication issues
- Input validation problems
EOF
创建项目级命令:
bash
mkdir -p .claude/commands
cat > .claude/commands/review-pr.md << 'EOF'
---
argument-hint: [pr-number]
description: Review pull request for code quality
---

Review pull request #$ARGUMENTS:

1. Check for security vulnerabilities
2. Verify test coverage
3. Assess code quality and style
4. Suggest improvements

Provide summary in Markdown format.
EOF
创建用户级命令:
bash
mkdir -p ~/.claude/commands
cat > ~/.claude/commands/security-scan.md << 'EOF'
---
description: Scan code for security issues
---

Scan this code for security vulnerabilities:
- Hardcoded secrets
- Insecure dependencies
- Authentication issues
- Input validation problems
EOF

Step 4: Add Frontmatter

步骤4:添加前置元数据

Enhance command with metadata:
markdown
---
通过元数据增强命令功能:
markdown
---

Brief description shown in /help

在/help中显示的简要描述

description: Create a git commit
description: Create a git commit

Hint shown during autocomplete

自动补全时显示的参数提示

argument-hint: [message]
argument-hint: [message]

Tools the command can use

命令可使用的工具

tools: Bash(git add:), Bash(git status:), Bash(git commit:*)
tools: Bash(git add:), Bash(git status:), Bash(git commit:*)

Specific model (optional)

指定使用的模型(可选)

model: haiku
model: haiku

Prevent SlashCommand tool from invoking (optional)

禁止SlashCommand工具调用(可选)

disable-model-invocation: false

Your command prompt here with $ARGUMENTS
undefined

disable-model-invocation: false

你的命令提示词,可使用$ARGUMENTS变量
undefined

Step 5: Test Command

步骤5:测试命令

bash
> /help
bash
> /help

Verify command appears in list

验证命令是否出现在列表中

/command-name arg1 arg2
/command-name arg1 arg2

Test execution with arguments

携带参数测试命令执行

undefined
undefined

Step 6: Reference in Agent Config

步骤6:在Agent配置中引用命令

File:
docs/agents/tracking-agent/config.yaml
yaml
name: tracking-agent

commands:
  - git-commit       # References .claude/commands/git-commit.md
  - linear-update    # References .claude/commands/linear-update.md
  - review-pr        # References .claude/commands/review-pr.md
Important: Reference by name without
.md
extension.
文件路径
docs/agents/tracking-agent/config.yaml
yaml
name: tracking-agent

commands:
  - git-commit       # 引用.claude/commands/git-commit.md
  - linear-update    # 引用.claude/commands/linear-update.md
  - review-pr        # 引用.claude/commands/review-pr.md
重要提示:引用时只需使用命令名称,无需添加
.md
扩展名。

Command Examples

命令示例

Example 1: Simple Command

示例1:简单命令

File:
.claude/commands/optimize.md
markdown
Analyze the performance of this code and suggest three specific optimizations:
Usage:
/optimize
文件路径
.claude/commands/optimize.md
markdown
Analyze the performance of this code and suggest three specific optimizations:
使用方式
/optimize

Example 2: Command with Arguments

示例2:带参数的命令

File:
.claude/commands/fix-issue.md
markdown
---
argument-hint: [issue-number]
description: Fix a GitHub issue following project standards
---

Fix issue #$ARGUMENTS following these steps:

1. **Understand**: Read issue description and requirements
2. **Locate**: Find relevant code in codebase
3. **Implement**: Create solution addressing root cause
4. **Test**: Add appropriate tests
5. **Document**: Prepare concise PR description

Follow project coding standards and conventions.
Usage:
/fix-issue 123
文件路径
.claude/commands/fix-issue.md
markdown
---
argument-hint: [issue-number]
description: Fix a GitHub issue following project standards
---

Fix issue #$ARGUMENTS following these steps:

1. **理解需求**:阅读问题描述和要求
2. **定位代码**:在代码库中找到相关代码
3. **实现修复**:针对根本问题创建解决方案
4. **添加测试**:编写相应的测试用例
5. **准备文档**:撰写简洁的PR描述

遵循项目的编码标准和规范。
使用方式
/fix-issue 123

Example 3: Git Commit Command

示例3:Git提交命令

File:
.claude/commands/git-commit.md
markdown
---
tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*), Bash(git diff:*), Bash(git log:*)
description: Create a git commit based on current changes
---
文件路径
.claude/commands/git-commit.md
markdown
---
tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*), Bash(git diff:*), Bash(git log:*)
description: Create a git commit based on current changes
---

Context

上下文信息

  • Current git status: !
    git status
  • Staged and unstaged changes: !
    git diff HEAD
  • Current branch: !
    git branch --show-current
  • Recent 10 commits: !
    git log --oneline -10
  • 当前git状态: !
    git status
  • 暂存与未暂存变更: !
    git diff HEAD
  • 当前分支: !
    git branch --show-current
  • 最近10条提交记录: !
    git log --oneline -10

Your Task

任务要求

Based on the above git context, create a single git commit:
  1. Analyze changes: Review the git diff
  2. Choose files: Select relevant files to stage
  3. Write message: Create commit message following format:
    • Type:
      feat|fix|docs|refactor|test|chore
    • Format:
      <type>: <description>
    • Example:
      feat: add user authentication
  4. Create commit: Execute git commands to stage and commit
Important: Follow this repository's commit message style (see recent commits).

**Usage**: `/git-commit`
基于上述git上下文信息,完成以下操作:
  1. 分析变更:查看git diff记录
  2. 选择文件:选择需要暂存的相关文件
  3. 编写提交信息:按照以下格式创建提交信息:
    • 类型:
      feat|fix|docs|refactor|test|chore
    • 格式:
      <type>: <description>
    • 示例:
      feat: add user authentication
  4. 完成提交:执行git命令完成暂存和提交
重要提示:请遵循本仓库的提交信息风格(可参考最近的提交记录)。

**使用方式**:`/git-commit`

Example 4: Positional Arguments

示例4:位置参数命令

File:
.claude/commands/review-pr.md
markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: Review pull request with priority and assignment
---

Review pull request #$1:

**Priority**: $2
**Assign to**: $3

**Review checklist**:
1. Security vulnerabilities
2. Performance issues
3. Code style violations
4. Test coverage
5. Documentation completeness

Provide detailed review comments with severity levels.
Usage:
/review-pr 456 high alice
文件路径
.claude/commands/review-pr.md
markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: Review pull request with priority and assignment
---

Review pull request #$1:

**优先级**: $2
**负责人**: $3

**评审检查清单**:
1. 安全漏洞
2. 性能问题
3. 代码风格违规
4. 测试覆盖率
5. 文档完整性

提供带有严重级别的详细评审意见。
使用方式
/review-pr 456 high alice

Example 5: File Reference Command

示例5:文件引用命令

File:
.claude/commands/explain-file.md
markdown
---
argument-hint: <file-path>
description: Explain implementation of a specific file
---

Explain the implementation in @$ARGUMENTS:

1. **Purpose**: What does this file do?
2. **Structure**: How is the code organized?
3. **Key functions**: What are the main functions/classes?
4. **Dependencies**: What does it depend on?
5. **Usage**: How is it used elsewhere?

Provide clear, beginner-friendly explanation.
Usage:
/explain-file src/utils/helpers.js
文件路径
.claude/commands/explain-file.md
markdown
---
argument-hint: <file-path>
description: Explain implementation of a specific file
---

Explain the implementation in @$ARGUMENTS:

1. **用途**:该文件的功能是什么?
2. **结构**:代码是如何组织的?
3. **核心函数**:主要的函数/类有哪些?
4. **依赖关系**:它依赖哪些其他模块?
5. **使用场景**:其他模块如何调用它?

提供清晰、适合初学者的解释。
使用方式
/explain-file src/utils/helpers.js

Agent Config Integration

Agent配置集成

Declaring Commands

声明命令

File:
docs/agents/qa-agent/config.yaml
yaml
name: qa-agent
description: Quality assurance and validation agent
文件路径
docs/agents/qa-agent/config.yaml
yaml
name: qa-agent
description: Quality assurance and validation agent

Skills for complex workflows

用于复杂工作流的技能

skills:
  • security-validation
  • test-standards
  • code-quality-standards
skills:
  • security-validation
  • test-standards
  • code-quality-standards

Commands for explicit invocations

用于显式调用的命令

commands:
  • review-pr # Quick PR review
  • security-scan # Security check
  • test-coverage # Coverage analysis
ref_docs:
  • test-audit-protocol.md
  • traycer-coordination-guide.md
undefined
commands:
  • review-pr # 快速PR评审
  • security-scan # 安全检查
  • test-coverage # 覆盖率分析
ref_docs:
  • test-audit-protocol.md
  • traycer-coordination-guide.md
undefined

Commands in Agent Workflow

Agent工作流中的命令

Agent can use commands:
  1. Manually: User invokes
    /review-pr 456
  2. Programmatically: Via
    SlashCommand
    tool (if enabled)
SlashCommand tool requirements:
  • Command must have
    description
    frontmatter
  • Not disabled via
    disable-model-invocation: true
  • Character budget not exceeded (15,000 chars default)
Agent使用命令的方式:
  1. 手动调用:用户执行
    /review-pr 456
  2. 程序化调用:通过
    SlashCommand
    工具调用(需启用)
SlashCommand工具要求:
  • 命令必须包含
    description
    前置元数据
  • 未通过
    disable-model-invocation: true
    禁用
  • 未超过字符限制(默认15000字符)

Framework Integration (Traycer Enforcement Framework)

框架集成(Traycer执行框架)

When creating commands for the Traycer enforcement framework:
为Traycer执行框架创建命令时,需遵循以下规则:

Command Location

命令存储位置

Commands live in:
.claude/commands/<command-name>.md
Example:
text
.claude/commands/
├── git-commit.md
├── review-pr.md
└── your-new-command.md
命令需存储在:
.claude/commands/<command-name>.md
示例目录结构:
text
.claude/commands/
├── git-commit.md
├── review-pr.md
└── your-new-command.md

Agent Assignment

Agent分配

When called standalone (user asks to create a command):
  1. Ask user which agents should use this command
  2. Suggest agents based on command's purpose:
    • Git operations → tracking-agent
    • Code validation → qa-agent
    • Implementation → action-agent
    • Workflow coordination → workflow-upgrade-assistant
  3. List suggested agents for user confirmation
When called by agent-builder:
  • Agent context provided automatically
  • No need to ask about agent assignment
当独立调用命令创建功能时(用户请求创建命令):
  1. 询问用户哪些Agent需要使用该命令
  2. 根据命令用途推荐合适的Agent:
    • Git操作 → tracking-agent
    • 代码验证 → qa-agent
    • 功能实现 → action-agent
    • 工作流协作 → workflow-upgrade-assistant
  3. 列出推荐的Agent供用户确认
当通过agent-builder调用时:
  • 自动提供Agent上下文信息
  • 无需询问Agent分配问题

Updating Agent Config

更新Agent配置

After creating the command, update each agent's config.yaml:
File:
docs/agents/<agent-name>/config.yaml
Add command name (without .md extension) to
commands:
section:
yaml
commands:
  - existing-command-1
  - existing-command-2
  - your-new-command    # Add here (no .md extension)
创建命令后,更新每个Agent的config.yaml文件:
文件路径
docs/agents/<agent-name>/config.yaml
commands:
部分添加命令名称(无需
.md
扩展名):
yaml
commands:
  - existing-command-1
  - existing-command-2
  - your-new-command    # 在此处添加(无需.md扩展名)

Complete Workflow

完整工作流

  1. Create command file:
    .claude/commands/<command-name>.md
  2. Add frontmatter (description, argument-hint, allowed-tools)
  3. Write command prompt with $ARGUMENTS or $1, $2, $3
  4. Determine which agents use this command (ask user or use agent-builder context)
  5. Update each agent's config.yaml to reference the command
  6. Test command with
    /command-name args
  1. 创建命令文件:
    .claude/commands/<command-name>.md
  2. 添加前置元数据(description、argument-hint、allowed-tools)
  3. 编写命令提示词,使用$ARGUMENTS或$1, $2, $3变量
  4. 确定使用该命令的Agent(询问用户或使用agent-builder上下文)
  5. 更新每个Agent的config.yaml以引用该命令
  6. 使用
    /command-name args
    测试命令

Best Practices

最佳实践

1. Keep Commands Simple

1. 保持命令简洁

Good: Single-purpose, clear prompt
markdown
Review this code for security vulnerabilities
Bad: Multiple unrelated tasks
markdown
Review code for security, performance, style, tests, documentation, and deployment issues
推荐:单一用途,提示词清晰
markdown
Review this code for security vulnerabilities
不推荐:包含多个无关任务
markdown
Review code for security, performance, style, tests, documentation, and deployment issues

2. Use Descriptive Names

2. 使用描述性命名

Good:
review-pr
,
git-commit
,
fix-issue
Bad:
r
,
gc
,
fix
推荐
review-pr
,
git-commit
,
fix-issue
不推荐
r
,
gc
,
fix

3. Provide Context with Bash

3. 通过Bash提供上下文信息

Good: Include relevant git context
markdown
- Current branch: !`git branch --show-current`
- Recent commits: !`git log --oneline -5`
Bad: Assume context is known
markdown
Create a commit
推荐:包含相关git上下文
markdown
- 当前分支: !`git branch --show-current`
- 最近提交记录: !`git log --oneline -5`
不推荐:假设上下文已知
markdown
Create a commit

4. Document Expected Arguments

4. 文档化预期参数

Good: Clear argument hint
markdown
---
argument-hint: [pr-number] [priority] [assignee]
---
Bad: No hint, unclear usage
推荐:清晰的参数提示
markdown
---
argument-hint: [pr-number] [priority] [assignee]
---
不推荐:无参数提示,使用方式不明确

5. Use Frontmatter

5. 使用前置元数据

Good: Complete metadata
markdown
---
description: Review pull request
argument-hint: [pr-number]
tools: Bash(gh pr view:*)
---
Bad: No frontmatter (description defaults to first line)
推荐:完整的元数据
markdown
---
description: Review pull request
argument-hint: [pr-number]
tools: Bash(gh pr view:*)
---
不推荐:无前置元数据(描述默认使用文件第一行内容)

6. Namespace Organization

6. 命名空间组织

Good: Organized by function
text
.claude/commands/
├── git/
│   ├── commit.md
│   ├── branch.md
│   └── push.md
├── qa/
│   ├── review.md
│   └── test.md
Bad: Flat structure with many commands
推荐:按功能分类组织
text
.claude/commands/
├── git/
│   ├── commit.md
│   ├── branch.md
│   └── push.md
├── qa/
│   ├── review.md
│   └── test.md
不推荐:扁平结构包含大量命令

Common Patterns

常见模式

Pattern 1: Context-Rich Commands

模式1:上下文丰富的命令

Include bash output for context:
markdown
---
tools: Bash(git status:*), Bash(git diff:*)
---
包含bash输出作为上下文:
markdown
---
tools: Bash(git status:*), Bash(git diff:*)
---

Context

上下文信息

  • Git status: !
    git status --short
  • Changes: !
    git diff --stat
  • Git状态: !
    git status --short
  • 变更记录: !
    git diff --stat

Task

任务要求

[Your instructions based on context]
undefined
[基于上下文的指令]
undefined

Pattern 2: Structured Arguments

模式2:结构化参数

Use positional args for structured input:
markdown
---
argument-hint: [component] [action] [target]
---

$1: Component name
$2: Action to perform
$3: Target file/directory

Execute $2 on $1 targeting $3.
使用位置参数处理结构化输入:
markdown
---
argument-hint: [component] [action] [target]
---

$1: 组件名称
$2: 执行操作
$3: 目标文件/目录

对$1执行$2操作,目标为$3。

Pattern 3: File-Based Commands

模式3:基于文件的命令

Reference specific files:
markdown
Review @$ARGUMENTS for:
1. Code quality
2. Security issues
3. Performance concerns
Usage:
/review src/auth.js
引用特定文件:
markdown
Review @$ARGUMENTS检查以下内容:
1. 代码质量
2. 安全问题
3. 性能隐患
使用方式:
/review src/auth.js

Pattern 4: Multi-Step Workflows

模式4:多步骤工作流

Break complex tasks into steps:
markdown
Execute deployment workflow for $ARGUMENTS:

**Phase 1: Pre-deployment**
- [ ] Run tests
- [ ] Security scan
- [ ] Build artifacts

**Phase 2: Deployment**
- [ ] Deploy to staging
- [ ] Verify health checks
- [ ] Deploy to production

**Phase 3: Post-deployment**
- [ ] Monitor metrics
- [ ] Verify functionality
- [ ] Document deployment
将复杂任务拆分为多个步骤:
markdown
为$ARGUMENTS执行部署工作流:

**阶段1:部署前准备**
- [ ] 运行测试
- [ ] 安全扫描
- [ ] 构建产物

**阶段2:部署执行**
- [ ] 部署到预发布环境
- [ ] 验证健康检查
- [ ] 部署到生产环境

**阶段3:部署后验证**
- [ ] 监控指标
- [ ] 验证功能
- [ ] 记录部署信息

Integration with Agent Builder

与Agent Builder的集成

When using Agent Builder skill to create an agent:
  1. Agent Builder analyzes requirements
  2. Identifies frequently-used prompts → Candidates for commands
  3. Calls Command Creator to define command specifications
  4. Creates command files in
    .claude/commands/
  5. References commands in
    config.yaml
Command Creator provides:
  • Command file structure
  • Frontmatter recommendations
  • Argument patterns
  • Integration with agent workflow
使用Agent Builder技能创建Agent时:
  1. Agent Builder分析需求
  2. 识别频繁使用的提示词 → 作为命令候选
  3. 调用命令创建器定义命令规范
  4. 在.claude/commands/目录下创建命令文件
  5. 在config.yaml中引用命令
命令创建器提供以下支持:
  • 命令文件结构
  • 前置元数据建议
  • 参数模式
  • 与Agent工作流的集成方案

Quick Reference

快速参考

Creating commands:
  1. Choose scope (project vs personal)
  2. Design command interface (name, arguments)
  3. Write prompt in Markdown
  4. Add frontmatter (description, argument-hint, allowed-tools)
  5. Test with
    /command-name args
  6. Reference in agent config.yaml
Command naming:
  • Use:
    git-commit
    ,
    review-pr
    ,
    fix-issue
  • Avoid:
    GitCommit
    ,
    review_pr
    ,
    fixIssue
File location:
  • Project:
    .claude/commands/command-name.md
  • Personal:
    ~/.claude/commands/command-name.md
Config reference:
yaml
commands:
  - command-name  # No .md extension
创建命令步骤:
  1. 选择作用域(项目级 vs 用户级)
  2. 设计命令接口(名称、参数)
  3. 在Markdown中编写提示词
  4. 添加前置元数据(description、argument-hint、allowed-tools)
  5. 使用
    /command-name args
    测试
  6. 在Agent的config.yaml中引用
命令命名规则:
  • 推荐:
    git-commit
    ,
    review-pr
    ,
    fix-issue
  • 避免:
    GitCommit
    ,
    review_pr
    ,
    fixIssue
文件存储位置:
  • 项目级:
    .claude/commands/command-name.md
  • 用户级:
    ~/.claude/commands/command-name.md
配置引用方式:
yaml
commands:
  - command-name  # 无需.md扩展名

Resources

参考资源

For detailed patterns and examples, see
references/command-examples.md
:
  • Complete command specifications from existing agents
  • Argument design patterns
  • Frontmatter best practices
  • Integration examples
如需查看详细模式和示例,请参考
references/command-examples.md
:
  • 现有Agent的完整命令规范
  • 参数设计模式
  • 前置元数据最佳实践
  • 集成示例