command-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommand 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:
- Creating custom slash commands for an agent
- Defining reusable prompts that should be invoked explicitly
- Building commands that need dynamic arguments
- Organizing frequently-used agent prompts
在以下场景使用command-creator:
- 为Agent创建自定义斜杠命令
- 定义需要显式调用的可复用提示词
- 构建需要动态参数的命令
- 整理常用的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 (project) or
.claude/commands/(personal)~/.claude/commands/ - Are invoked with syntax
/command-name - 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 系统提示词
| Element | Purpose | Example | Invocation |
|---|---|---|---|
| Commands | Quick, reusable prompts | | Explicit: |
| Skills | Complex workflows with multiple files | | Automatic based on context |
| System Prompt | Agent personality and core behavior | Agent role, coordination logic | Always 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
| 元素 | 用途 | 示例 | 调用方式 |
|---|---|---|---|
| 命令 | 快捷、可复用的提示词 | | 显式调用: |
| 技能 | 涉及多文件的复杂工作流 | | 根据上下文自动触发 |
| 系统提示词 | 定义Agent的个性和核心行为 | Agent角色、协作逻辑 | 始终生效 |
优先使用命令的场景:
- 你有频繁使用的提示词
- 需要对执行时机进行显式控制
- 提示词可容纳在单个Markdown文件中
- 需要传递动态参数
优先使用技能的场景:
- 工作流需要多步骤执行
- 需要脚本、引用或资源文件
- 希望根据上下文自动触发
- 多个Agent共享该能力
优先使用系统提示词的场景:
- 定义Agent的核心角色
- 指定Agent的专属行为
- 与其他Agent的协作逻辑
Command Structure
命令结构
Basic Command File
基础命令文件
File:
.claude/commands/optimize.mdmarkdown
Analyze this code for performance issues and suggest optimizations:Invocation:
/optimize文件路径:
.claude/commands/optimize.mdmarkdown
Analyze this code for performance issues and suggest optimizations:调用方式:
/optimizeCommand with Frontmatter
包含前置元数据的命令
File:
.claude/commands/git-commit.mdmarkdown
---
tools:
argument-hint: [message]
description: Create a git commit
model: haiku
---
Create a git commit with message: $ARGUMENTSInvocation:
/git-commit "fix: resolve login bug"文件路径:
.claude/commands/git-commit.mdmarkdown
---
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
前置元数据字段说明
| Field | Purpose | Default | Example |
|---|---|---|---|
| Tools command can use | Inherits from conversation | |
| Expected arguments | None | |
| Brief description | First line | |
| Specific model | Inherits from conversation | |
| Prevent SlashCommand tool | false | |
| 字段 | 用途 | 默认值 | 示例 |
|---|---|---|---|
| 命令可使用的工具 | 继承自对话配置 | |
| 参数格式提示 | 无 | |
| 命令简要描述 | 文件第一行内容 | |
| 指定使用的模型 | 继承自对话配置 | |
| 禁止SlashCommand工具调用 | false | |
Command Features
命令特性
1. Arguments
1. 参数处理
All Arguments with $ARGUMENTS
$ARGUMENTS使用$ARGUMENTS
获取所有参数
$ARGUMENTSCaptures 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 descriptionUsage:
bash
/fix-issue 123 high-priority$ARGUMENTS"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使用$1
, $2
, $3
获取位置参数
$1$2$3Access 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与团队共享
- 适用于项目专属工作流
- 在中显示"(project)"标识
/help
用户级命令(存储在):
~/.claude/commands/- 适用于所有项目的个人工作流
- 不与团队共享
- 在中显示"(user)"标识
/help
Step 2: Design Command Interface
步骤2:设计命令接口
Name: Use lowercase, hyphens for spaces
- Good: ,
git-commit,review-prfix-issue - Bad: ,
GitCommit,review_prfixIssue
Arguments: Decide on argument pattern
- Simple: Use for all args
$ARGUMENTS - Structured: Use ,
$1,$2for specific args$3
Prompt: Write clear instructions
- Explain what the command should do
- Provide context (use for bash,
!for files)@ - Specify expected output format
命名规则:使用小写字母,用连字符分隔单词
- 推荐:,
git-commit,review-prfix-issue - 不推荐:,
GitCommit,review_prfixIssue
参数设计:确定参数模式
- 简单场景:使用获取所有参数
$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.
EOFFor 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
EOFStep 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
undefineddisable-model-invocation: false
你的命令提示词,可使用$ARGUMENTS变量
undefinedStep 5: Test Command
步骤5:测试命令
bash
> /helpbash
> /helpVerify command appears in list
验证命令是否出现在列表中
/command-name arg1 arg2
/command-name arg1 arg2
Test execution with arguments
携带参数测试命令执行
undefinedundefinedStep 6: Reference in Agent Config
步骤6:在Agent配置中引用命令
File:
docs/agents/tracking-agent/config.yamlyaml
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.mdImportant: Reference by name without extension.
.md文件路径:
docs/agents/tracking-agent/config.yamlyaml
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重要提示:引用时只需使用命令名称,无需添加扩展名。
.mdCommand Examples
命令示例
Example 1: Simple Command
示例1:简单命令
File:
.claude/commands/optimize.mdmarkdown
Analyze the performance of this code and suggest three specific optimizations:Usage:
/optimize文件路径:
.claude/commands/optimize.mdmarkdown
Analyze the performance of this code and suggest three specific optimizations:使用方式:
/optimizeExample 2: Command with Arguments
示例2:带参数的命令
File:
.claude/commands/fix-issue.mdmarkdown
---
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.mdmarkdown
---
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 123Example 3: Git Commit Command
示例3:Git提交命令
File:
.claude/commands/git-commit.mdmarkdown
---
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.mdmarkdown
---
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:
- Analyze changes: Review the git diff
- Choose files: Select relevant files to stage
- Write message: Create commit message following format:
- Type:
feat|fix|docs|refactor|test|chore - Format:
<type>: <description> - Example:
feat: add user authentication
- Type:
- Create commit: Execute git commands to stage and commit
Important: Follow this repository's commit message style (see recent commits).
**Usage**: `/git-commit`基于上述git上下文信息,完成以下操作:
- 分析变更:查看git diff记录
- 选择文件:选择需要暂存的相关文件
- 编写提交信息:按照以下格式创建提交信息:
- 类型:
feat|fix|docs|refactor|test|chore - 格式:
<type>: <description> - 示例:
feat: add user authentication
- 类型:
- 完成提交:执行git命令完成暂存和提交
重要提示:请遵循本仓库的提交信息风格(可参考最近的提交记录)。
**使用方式**:`/git-commit`Example 4: Positional Arguments
示例4:位置参数命令
File:
.claude/commands/review-pr.mdmarkdown
---
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.mdmarkdown
---
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 aliceExample 5: File Reference Command
示例5:文件引用命令
File:
.claude/commands/explain-file.mdmarkdown
---
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.mdmarkdown
---
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.jsAgent Config Integration
Agent配置集成
Declaring Commands
声明命令
File:
docs/agents/qa-agent/config.yamlyaml
name: qa-agent
description: Quality assurance and validation agent文件路径:
docs/agents/qa-agent/config.yamlyaml
name: qa-agent
description: Quality assurance and validation agentSkills 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
undefinedcommands:
- review-pr # 快速PR评审
- security-scan # 安全检查
- test-coverage # 覆盖率分析
ref_docs:
- test-audit-protocol.md
- traycer-coordination-guide.md
undefinedCommands in Agent Workflow
Agent工作流中的命令
Agent can use commands:
- Manually: User invokes
/review-pr 456 - Programmatically: Via tool (if enabled)
SlashCommand
SlashCommand tool requirements:
- Command must have frontmatter
description - Not disabled via
disable-model-invocation: true - Character budget not exceeded (15,000 chars default)
Agent使用命令的方式:
- 手动调用:用户执行
/review-pr 456 - 程序化调用:通过工具调用(需启用)
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>.mdExample:
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.mdAgent Assignment
Agent分配
When called standalone (user asks to create a command):
- Ask user which agents should use this command
- Suggest agents based on command's purpose:
- Git operations → tracking-agent
- Code validation → qa-agent
- Implementation → action-agent
- Workflow coordination → workflow-upgrade-assistant
- List suggested agents for user confirmation
When called by agent-builder:
- Agent context provided automatically
- No need to ask about agent assignment
当独立调用命令创建功能时(用户请求创建命令):
- 询问用户哪些Agent需要使用该命令
- 根据命令用途推荐合适的Agent:
- Git操作 → tracking-agent
- 代码验证 → qa-agent
- 功能实现 → action-agent
- 工作流协作 → workflow-upgrade-assistant
- 列出推荐的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.yamlAdd command name (without .md extension) to section:
commands: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:.mdyaml
commands:
- existing-command-1
- existing-command-2
- your-new-command # 在此处添加(无需.md扩展名)Complete Workflow
完整工作流
- Create command file:
.claude/commands/<command-name>.md - Add frontmatter (description, argument-hint, allowed-tools)
- Write command prompt with $ARGUMENTS or $1, $2, $3
- Determine which agents use this command (ask user or use agent-builder context)
- Update each agent's config.yaml to reference the command
- Test command with
/command-name args
- 创建命令文件:
.claude/commands/<command-name>.md - 添加前置元数据(description、argument-hint、allowed-tools)
- 编写命令提示词,使用$ARGUMENTS或$1, $2, $3变量
- 确定使用该命令的Agent(询问用户或使用agent-builder上下文)
- 更新每个Agent的config.yaml以引用该命令
- 使用测试命令
/command-name args
Best Practices
最佳实践
1. Keep Commands Simple
1. 保持命令简洁
Good: Single-purpose, clear prompt
markdown
Review this code for security vulnerabilitiesBad: 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 issues2. Use Descriptive Names
2. 使用描述性命名
Good: , ,
Bad: , ,
review-prgit-commitfix-issuergcfix推荐:, ,
不推荐:, ,
review-prgit-commitfix-issuergcfix3. 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 commit4. 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.mdBad: 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[基于上下文的指令]
undefinedPattern 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 concernsUsage:
/review src/auth.js引用特定文件:
markdown
Review @$ARGUMENTS检查以下内容:
1. 代码质量
2. 安全问题
3. 性能隐患使用方式:
/review src/auth.jsPattern 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:
- Agent Builder analyzes requirements
- Identifies frequently-used prompts → Candidates for commands
- Calls Command Creator to define command specifications
- Creates command files in
.claude/commands/ - References commands in
config.yaml
Command Creator provides:
- Command file structure
- Frontmatter recommendations
- Argument patterns
- Integration with agent workflow
使用Agent Builder技能创建Agent时:
- Agent Builder分析需求
- 识别频繁使用的提示词 → 作为命令候选
- 调用命令创建器定义命令规范
- 在.claude/commands/目录下创建命令文件
- 在config.yaml中引用命令
命令创建器提供以下支持:
- 命令文件结构
- 前置元数据建议
- 参数模式
- 与Agent工作流的集成方案
Quick Reference
快速参考
Creating commands:
- Choose scope (project vs personal)
- Design command interface (name, arguments)
- Write prompt in Markdown
- Add frontmatter (description, argument-hint, allowed-tools)
- Test with
/command-name args - Reference in agent config.yaml
Command naming:
- Use: ,
git-commit,review-prfix-issue - Avoid: ,
GitCommit,review_prfixIssue
File location:
- Project:
.claude/commands/command-name.md - Personal:
~/.claude/commands/command-name.md
Config reference:
yaml
commands:
- command-name # No .md extension创建命令步骤:
- 选择作用域(项目级 vs 用户级)
- 设计命令接口(名称、参数)
- 在Markdown中编写提示词
- 添加前置元数据(description、argument-hint、allowed-tools)
- 使用测试
/command-name args - 在Agent的config.yaml中引用
命令命名规则:
- 推荐: ,
git-commit,review-prfix-issue - 避免: ,
GitCommit,review_prfixIssue
文件存储位置:
- 项目级:
.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的完整命令规范
- 参数设计模式
- 前置元数据最佳实践
- 集成示例