Commands System
Relevant source files
The following files were used as context for generating this wiki page:
- cli-tool/docs_to_claude/COMMANDS_GUIDE.md
- cli-tool/components/skills/development/command-development/SKILL.md
- cli-tool/components/skills/development/command-creator/references/best-practices.md
- cli-tool/components/skills/development/command-creator/SKILL.md
- cli-tool/components/agents/development-tools/command-expert.md
- cli-tool/components/skills/development/command-development/README.md
The Commands System in Claude Code Templates provides a framework for creating and executing custom "slash commands"—reusable, automated prompts invoked via a simple slash syntax (e.g., /optimize). These commands enable rapid execution of complex workflows, dynamic argument passing, and context enrichment through automated bash command output and file references.
Sources: cli-tool/docs_to_claude/COMMANDS_GUIDE.md:3-13, cli-tool/components/skills/development/command-development/SKILL.md:12-18
Commands are designed as instructions specifically for AI agent consumption rather than human reading. They are stored as Markdown files with optional YAML frontmatter and are scoped to either a specific project or the global user environment.
Sources: cli-tool/components/skills/development/command-development/SKILL.md:25-30, cli-tool/docs_to_claude/COMMANDS_GUIDE.md:21-27
Architecture and Command Locations
The system utilizes a hierarchical priority model for command discovery. When a command is invoked, the system searches specific directories to resolve the file. If a name conflict occurs, project-level commands take precedence over personal ones.
| Type | Location | Scope | Priority |
|---|---|---|---|
| Project Commands | .claude/commands/ | Current project only (shared) | Higher |
| Personal Commands | ~/.claude/commands/ | All projects (private) | Lower |
| Plugin Commands | [plugin-name]/commands/ | Plugin-specific | N/A |
Sources: cli-tool/docs_to_claude/COMMANDS_GUIDE.md:21-27, cli-tool/components/skills/development/command-development/SKILL.md:41-55
Command Discovery Flow
The following diagram illustrates how the system resolves a command when a user inputs a slash command.
Command Structure and Configuration
Commands are defined in Markdown files (.md). The system parses these files into three primary segments: metadata (frontmatter), the instructional prompt, and dynamic execution blocks (bash/file references).
YAML Frontmatter Configuration
The frontmatter allows developers to restrict tools, hint at arguments, and define metadata for the /help output.
| Field | Description | Type |
|---|---|---|
description | Brief explanation shown in /help. | String |
argument-hint | Autocomplete guidance for arguments (e.g., [pr-number]). | String |
allowed-tools | Restricts which tools the command can use (e.g., Read, Edit, Bash). | Array/String |
model | Specific Claude model to use (e.g., claude-3-5-sonnet-20241022). | String |
disable-model-invocation | If true, prevents Claude from triggering the command automatically. | Boolean |
Sources: cli-tool/docs_to_claude/COMMANDS_GUIDE.md:83-131, cli-tool/components/skills/development/command-development/SKILL.md:88-135
Dynamic Arguments and Context
The system supports variable substitution to make commands reusable across different files or issues.
$ARGUMENTS: Captures the entire string provided after the command.- Positional Arguments (
$1,$2): Accesses individual words passed in the command call. - File References (
@filename): Instructs Claude to read the specified file content into the prompt context. - Bash Integration (
!bash_command``): Executes a shell command and embeds the output directly into the prompt before it is sent to the model.
Sources: cli-tool/docs_to_claude/COMMANDS_GUIDE.md:135-182, cli-tool/components/skills/development/command-development/SKILL.md:162-185
Command Execution Lifecycle
The execution of a command involves a pre-processing phase where dynamic context is gathered before the final prompt is presented to the AI agent.
Best Practices for Command Development
To ensure commands are "agent-executable" and autonomous, developers must follow specific writing styles and structural patterns.
Writing Style Guidelines
- Imperative Form: Use verb-first instructions (e.g., "Run git status" instead of "You should run...").
- Specificity: Define exact line ranges or tool flags.
- Success Criteria: Explicitly state when the agent should stop (e.g., "Stop when make all-ci exits with code 0").
- Anti-Patterns: Call out prohibited actions using "NEVER" or "DO NOT".
Sources: cli-tool/components/skills/development/command-creator/references/best-practices.md:10-55, cli-tool/components/skills/development/command-development/SKILL.md:235-255
Implementation Patterns
| Pattern | Description |
|---|---|
| Workflow Automation | Analyze state, perform actions, and report results (e.g., PR submission). |
| Iterative Fixing | Run a check, parse errors, apply fixes, and repeat until successful. |
| Agent Delegation | Provide context and launch a specialized subagent via the Task tool. |
Sources: cli-tool/components/skills/development/command-creator/SKILL.md:46-51, cli-tool/components/skills/development/command-creator/references/best-practices.md:135-160
The SlashCommand Tool
The SlashCommand tool allows Claude to programmatically invoke custom commands during a conversation. This is governed by a character budget (defaulting to 15,000 characters) to prevent token overflow. Developers can control this behavior using the disable-model-invocation flag in the YAML frontmatter.
Sources: cli-tool/docs_to_claude/COMMANDS_GUIDE.md:374-428
Summary
The Commands System is a modular infrastructure that transforms static prompts into dynamic, context-aware automation tools. By leveraging YAML metadata, bash integration, and strict imperative instruction styles, it enables AI agents to perform complex, multi-step engineering tasks autonomously while maintaining project-specific constraints and tool safety.