command-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Command Creator

命令创建器

Create Claude Code custom slash commands with proper structure and best practices.
按照规范结构和最佳实践创建Claude Code自定义斜杠命令。

Understanding Commands

理解命令

Claude Code commands are Markdown files with YAML frontmatter that define reusable workflows invoked via
/command-name
. They live in specific locations depending on scope:
  • Project-level:
    .claude/commands/
    in the project root (shared via git)
  • User-level:
    ~/.claude/commands/
    (personal, available everywhere)
  • Categorized: Nest under subdirectories for namespacing (e.g.,
    gh/review-pr.md
    becomes
    /gh:review-pr
    )
Claude Code命令是带有YAML frontmatter的Markdown文件,定义了可通过
/command-name
调用的可复用工作流。它们的存放位置取决于作用域:
  • 项目级:项目根目录下的
    .claude/commands/
    (通过git共享)
  • 用户级
    ~/.claude/commands/
    (个人专属,全局可用)
  • 分类存放:可嵌套在子目录中以实现命名空间(例如
    gh/review-pr.md
    会成为
    /gh:review-pr

Process

流程

1. Clarify Intent

1. 明确意图

Before writing anything, understand:
  • What should the command do? (single clear purpose)
  • Who uses it — just this user, or the whole team? (determines project vs user-level)
  • Does it need arguments? What kind?
  • What tools does it need access to?
  • Is there a category it belongs to? (e.g.,
    gh
    for GitHub,
    cc
    for Claude Code meta-commands)
在开始编写前,需明确:
  • 该命令应实现什么功能?(单一清晰的目标)
  • 使用者是谁——仅当前用户,还是整个团队?(决定是项目级还是用户级)
  • 是否需要参数?需要哪种类型的参数?
  • 需要访问哪些工具?
  • 它属于哪个分类?(例如
    gh
    对应GitHub,
    cc
    对应Claude Code元命令)

2. Write the Command

2. 编写命令

Every command file follows this structure:
markdown
---
description: Brief description shown in command list
argument-hint: [expected-arguments]
allowed-tools: Tool1, Tool2, Bash(prefix:*)
---
每个命令文件都遵循以下结构:
markdown
---
description: 命令列表中显示的简短描述
argument-hint: [预期参数]
allowed-tools: Tool1, Tool2, Bash(prefix:*)
---

Command Name

命令名称

What this command does and when to use it.
该命令的功能及使用场景。

Process:

流程:

Step-by-step instructions for the agent to follow.
代理需遵循的分步说明。

Your Task:

你的任务:

Act on "$ARGUMENTS" following these guidelines.
undefined
按照以下指南处理"$ARGUMENTS"。
undefined

Frontmatter fields

前置元数据字段

FieldRequiredPurpose
description
YesShort description shown when listing commands
argument-hint
NoHint for expected arguments (shown in autocomplete)
allowed-tools
NoRestrict which tools the command can use
字段是否必填用途
description
列出命令时显示的简短描述
argument-hint
预期参数提示(自动补全时显示)
allowed-tools
限制命令可使用的工具

Key conventions

关键约定

  • $ARGUMENTS
    is replaced with whatever the user types after the command name. Always reference it in the "Your Task" section so the command acts on user input.
  • allowed-tools
    uses patterns: exact names (
    Read
    ,
    Write
    ), or prefix globs for Bash (
    Bash(git:*)
    ,
    Bash(npm:*)
    ).
  • Keep commands focused and single-purpose — one command, one job.
  • Write instructions in the imperative form ("Analyze the code", not "You should analyze the code").
  • Include concrete examples of usage and expected behavior.
  • $ARGUMENTS
    会被用户在命令名称后输入的内容替换。务必在“你的任务”部分引用它,以便命令对用户输入做出响应。
  • allowed-tools
    使用匹配模式:精确名称(
    Read
    Write
    ),或Bash的前缀通配符(
    Bash(git:*)
    Bash(npm:*)
    )。
  • 命令应聚焦单一用途——一个命令完成一项工作。
  • 说明使用祈使语气(如“分析代码”,而非“你应该分析代码”)。
  • 包含具体的使用示例及预期行为。

3. Choose the Right Location

3. 选择合适的存放位置

ScopePathWhen to use
Project (shared)
.claude/commands/
Team workflows, project-specific tasks
Project (categorized)
.claude/commands/<category>/
Grouped commands (e.g.,
gh/
,
db/
)
User (personal)
~/.claude/commands/
Personal productivity, cross-project tools
作用域路径使用场景
项目级(共享)
.claude/commands/
团队工作流、项目特定任务
项目级(分类)
.claude/commands/<category>/
分组命令(如
gh/
db/
用户级(个人)
~/.claude/commands/
个人生产力工具、跨项目工具

4. Validate

4. 验证

After creating the command file:
  • Verify the YAML frontmatter parses correctly (no syntax errors)
  • Confirm the file is in the right directory
  • Check that
    $ARGUMENTS
    is referenced if the command accepts input
  • Ensure
    allowed-tools
    includes everything the command needs
创建命令文件后:
  • 验证YAML frontmatter解析正确(无语法错误)
  • 确认文件位于正确目录
  • 检查如果命令接受输入,是否引用了
    $ARGUMENTS
  • 确保
    allowed-tools
    包含命令所需的所有工具

Example: A Simple Command

示例:简单命令

markdown
---
description: Review a pull request with detailed analysis
argument-hint: [PR-number-or-URL]
allowed-tools: Bash(gh:*), Read, Grep, Glob
---
markdown
---
description: 通过详细分析评审拉取请求
argument-hint: [PR编号或URL]
allowed-tools: Bash(gh:*), Read, Grep, Glob
---

Review PR

评审PR

Perform a thorough code review of a GitHub pull request.
对GitHub拉取请求进行全面的代码评审。

Process:

流程:

  1. Fetch PR details and diff using
    gh pr view
    and
    gh pr diff
  2. Read changed files for full context
  3. Analyze changes for:
    • Correctness and potential bugs
    • Code style consistency
    • Missing tests or edge cases
    • Security concerns
  4. Provide a structured review summary
  1. 使用
    gh pr view
    gh pr diff
    获取PR详情和差异
  2. 读取变更文件以获取完整上下文
  3. 从以下方面分析变更:
    • 正确性及潜在bug
    • 代码风格一致性
    • 缺失的测试或边缘情况
    • 安全隐患
  4. 提供结构化的评审总结

Your Task:

你的任务:

Review PR "$ARGUMENTS" following these guidelines. If no PR number is given, use
gh pr list
to show recent PRs and ask which one to review.
undefined
按照以下指南评审PR "$ARGUMENTS"。如果未提供PR编号,使用
gh pr list
显示最近的PR并询问要评审哪一个。
undefined

Best Practices

最佳实践

  • Descriptive names: The filename becomes the command name — make it clear (
    fix-issue.md
    not
    fi.md
    )
  • Graceful argument handling: Always handle the case where
    $ARGUMENTS
    is empty
  • Minimal tool permissions: Only list tools the command actually needs in
    allowed-tools
  • Follow existing patterns: Look at other commands in the same directory for conventions
  • Test before shipping: Try the command with different inputs to verify it works
  • 描述性名称:文件名即为命令名称——确保清晰易懂(
    fix-issue.md
    而非
    fi.md
  • 优雅的参数处理:始终处理
    $ARGUMENTS
    为空的情况
  • 最小化工具权限:仅在
    allowed-tools
    中列出命令实际需要的工具
  • 遵循现有模式:查看同一目录下的其他命令以遵循约定
  • 发布前测试:使用不同输入尝试命令以验证其功能

Your Task

你的任务

Create a new command based on "$ARGUMENTS":
  1. If the purpose is unclear, ask clarifying questions
  2. Determine the appropriate location and category
  3. Create the command file with proper structure
  4. Explain what was created and how to use it
基于"$ARGUMENTS"创建新命令:
  1. 如果用途不明确,提出澄清问题
  2. 确定合适的存放位置和分类
  3. 创建符合规范结构的命令文件
  4. 说明创建的内容及使用方法