AgentSkillsCN

command-creator

为创建自定义 Claude Code 斜杠命令提供指南。适用于用户希望创建新命令(或更新现有命令),以提供可复用的提示片段、工作流或自动化功能时使用。当用户提出创建 /commands、斜杠命令、自定义命令,或希望将常用提示定义为可复用命令时触发。

SKILL.md
--- frontmatter
name: command-creator
description: Guide for creating custom Claude Code slash commands. Use when user wants to create a new command (or update an existing command) that provides a reusable prompt snippet, workflow, or automation. Triggers on requests to create /commands, slash commands, custom commands, or when user wants to define frequently-used prompts as reusable commands.

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.

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.

Basic Structure

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

Your prompt instructions here.

Filename becomes the command name: review.md/review

Frontmatter Options

FieldPurposeDefault
descriptionBrief description for /helpFirst line of prompt
allowed-toolsTools the command can useInherits from conversation
argument-hintShows usage hint in autocompleteNone
modelSpecific model to useInherits from conversation
disable-model-invocationPrevent Skill tool from calling thisfalse
hooksCommand-scoped hooks (PreToolUse, PostToolUse, Stop)None

Arguments

All arguments: $ARGUMENTS

markdown
---
description: Fix an issue
---
Fix issue #$ARGUMENTS following our coding standards

Usage: /fix-issue 123 high-priority$ARGUMENTS = "123 high-priority"

Positional: $1, $2, etc.

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

Bash Execution

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

## Context
- Current git status: !\`git status\`
- Current git diff: !\`git diff HEAD\`
- Current branch: !\`git branch --show-current\`
- Recent commits: !\`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).

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

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.

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

## Context
- Existing components: !\`ls src/components/\`
- Project structure: !\`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

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.

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