command-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Command Creator

命令创建工具

Create custom slash commands for Claude Code. Commands are Markdown files that define reusable prompts with support for arguments, bash execution, file references, and tool permissions.
为Claude Code创建自定义斜杠命令。命令是Markdown文件,用于定义可复用的提示,支持参数、bash执行、文件引用和工具权限。

Command Locations

命令位置

TypeLocationScope
Project
.claude/commands/
Shared with team via git
Personal
~/.claude/commands/
Available across all projects
Project commands take precedence over personal commands with the same name.
类型位置作用范围
项目级
.claude/commands/
通过git与团队共享
个人级
~/.claude/commands/
在所有项目中可用
项目级命令优先级高于同名的个人级命令。

Basic Structure

基本结构

markdown
---
description: Brief description shown in /help
---

Your prompt instructions here.
Filename becomes the command name:
review.md
/review
markdown
---
description: 在/help中显示的简要描述
---

此处填写你的提示说明。
文件名即为命令名称:
review.md
/review

Frontmatter Options

前置配置选项

FieldPurposeDefault
description
Brief description for /helpFirst line of prompt
allowed-tools
Tools the command can useInherits from conversation
argument-hint
Shows usage hint in autocompleteNone
model
Specific model to useInherits from conversation
disable-model-invocation
Prevent Skill tool from calling thisfalse
hooks
Command-scoped hooks (PreToolUse, PostToolUse, Stop)None
字段用途默认值
description
用于/help的简要描述提示内容的第一行
allowed-tools
命令可使用的工具继承自对话设置
argument-hint
在自动补全中显示使用提示
model
要使用的特定模型继承自对话设置
disable-model-invocation
阻止Skill工具调用此命令false
hooks
命令级钩子(PreToolUse、PostToolUse、Stop)

Arguments

参数

All arguments:
$ARGUMENTS

所有参数:
$ARGUMENTS

markdown
---
description: Fix an issue
---
Fix issue #$ARGUMENTS following our coding standards
Usage:
/fix-issue 123 high-priority
$ARGUMENTS
= "123 high-priority"
markdown
---
description: 修复问题
---
按照我们的编码标准修复问题#$ARGUMENTS
使用示例:
/fix-issue 123 high-priority
$ARGUMENTS
= "123 high-priority"

Positional:
$1
,
$2
, etc.

位置参数:
$1
,
$2

markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: Review pull request
---
Review PR #$1 with priority $2 and assign to $3.
Usage:
/review-pr 456 high alice
markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: 审核拉取请求
---
审核PR #$1,优先级为$2,指定给$3。
使用示例:
/review-pr 456 high alice

Bash Execution

Bash执行

Execute bash before the command runs using the exclamation mark prefix. Output is included in context.
markdown
---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: Create a git commit
---
使用感叹号前缀在命令运行前执行bash命令,输出会包含在上下文当中。
markdown
---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: 创建git提交
---

Context

上下文

  • Current git status: !`git status`
  • Current git diff: !`git diff HEAD`
  • Current branch: !`git branch --show-current`
  • Recent commits: !`git log --oneline -10`
  • 当前git状态: !`git status`
  • 当前git差异: !`git diff HEAD`
  • 当前分支: !`git branch --show-current`
  • 最近提交: !`git log --oneline -10`

Task

任务

Create a git commit based on the above changes.

**Required**: Include `allowed-tools` with the Bash tool when using bang execution (the exclamation mark prefix).
基于上述变更创建一个git提交。

**必填项**:当使用感叹号执行时,需在`allowed-tools`中包含Bash工具。

File References

文件引用

Include file contents using the
@
prefix:
markdown
Review the implementation in @src/utils/helpers.js
Compare @src/old-version.js with @src/new-version.js
使用
@
前缀引入文件内容:
markdown
审核@src/utils/helpers.js中的实现
对比@src/old-version.js与@src/new-version.js

Namespacing

命名空间

Subdirectories group related commands. The subdirectory appears in the description:
  • .claude/commands/frontend/component.md
    /component
    (project:frontend)
  • .claude/commands/backend/test.md
    /test
    (project:backend)
Commands in different subdirectories can share names.
子目录用于分组相关命令,子目录会显示在描述中:
  • .claude/commands/frontend/component.md
    /component
    (project:frontend)
  • .claude/commands/backend/test.md
    /test
    (project:backend)
不同子目录下的命令可以重名。

Example: Complete Command

示例:完整命令

markdown
---
allowed-tools: Bash(npm:*), Bash(git:*), Read, Edit, Write
argument-hint: [component-name]
description: Create a new React component with tests
model: claude-sonnet-4-20250514
---
markdown
---
allowed-tools: Bash(npm:*), Bash(git:*), Read, Edit, Write
argument-hint: [component-name]
description: 创建带测试的新React组件
model: claude-sonnet-4-20250514
---

Context

上下文

  • Existing components: !`ls src/components/`
  • Project structure: !`ls -la src/`
  • 现有组件: !`ls src/components/`
  • 项目结构: !`ls -la src/`

Task

任务

Create a new React component named $1:
  1. Create component file at @src/components/$1.tsx
  2. Create test file at @src/components/$1.test.tsx
  3. Export from @src/components/index.ts
  4. Follow patterns in existing components
undefined
创建名为$1的新React组件:
  1. 在@src/components/$1.tsx创建组件文件
  2. 在@src/components/$1.test.tsx创建测试文件
  3. 在@src/components/index.ts中导出
  4. 遵循现有组件的模式
undefined

Hooks in Commands

命令中的钩子

Define command-scoped hooks that run during execution:
markdown
---
description: Deploy with validation
hooks:
  PreToolUse:
    - matcher: "Bash"
      hooks:
        - type: command
          command: "./scripts/validate.sh"
          once: true
---

Deploy to staging environment.
The
once: true
option runs the hook only once per session.
定义在执行过程中运行的命令级钩子:
markdown
---
description: 带验证的部署
hooks:
  PreToolUse:
    - matcher: "Bash"
      hooks:
        - type: command
          command: "./scripts/validate.sh"
          once: true
---

部署到预发布环境。
once: true
选项表示钩子在每个会话中仅运行一次。

Best Practices

最佳实践

  1. Keep prompts concise - Claude is smart; don't over-explain
  2. Use bash execution for context - Gather relevant state before the task
  3. Specify allowed-tools - Limit to what the command needs
  4. Add argument-hint - Help users understand expected arguments
  5. Use file references - Point to relevant files with
    @
  6. Namespace related commands - Use subdirectories for organization
  1. 保持提示简洁 - Claude很智能,无需过度解释
  2. 使用bash执行获取上下文 - 在任务前收集相关状态
  3. 指定allowed-tools - 限制为命令所需的工具
  4. 添加argument-hint - 帮助用户理解预期参数
  5. 使用文件引用 - 用
    @
    指向相关文件
  6. 为相关命令设置命名空间 - 使用子目录进行组织