How to Create a New Slash Command
Relevant source files
The following files were used as context for generating this wiki page:Slash commands are custom instructions that can be invoked within the Claude Code environment using the /command-name syntax. They serve as shortcuts for complex, multi-step workflows, encapsulating a series of instructions, tool permissions, and arguments into a single, reusable command. This allows developers to automate repetitive tasks such as reviewing pull requests, onboarding to a new task, or interacting with integrated services like JIRA.
These commands are defined in simple Markdown files, making them easy to create and modify. Each command file contains a set of instructions that guide Claude on how to perform a specific task, what tools it is allowed to use, and how to handle user-provided arguments. This system provides a powerful way to extend Claude's capabilities and tailor it to the specific needs of a project.
Sources: README.md:464-467, README.md:88-92
File Structure and Location
All slash commands are stored as individual Markdown files within the .claude/commands/ directory at the root of the project. The name of the file (excluding the .md extension) determines the name of the slash command. For example, a file named pr-review.md creates the /pr-review command.
Sources: README.md:52, README.md:56-59
The following diagram illustrates the directory structure for commands.
Sources: README.md:49-59
Command File Format
A command file is a Markdown document composed of two main parts: a YAML frontmatter block for configuration and a Markdown body containing the instructions for Claude.
Sources: README.md:469-477
Frontmatter Configuration
The frontmatter is a YAML block at the very top of the file, enclosed by ---. It defines the command's metadata and permissions.
| Field | Required | Description |
|---|---|---|
description | Yes | A brief description of the command's purpose. This text is displayed in the list of available commands. |
allowed-tools | No | A comma-separated list of tools that the command is permitted to use. This can include built-in tools like Read and Grep, or more specific ones like Bash(git:*). |
Sources: README.md:469-472, .claude/commands/onboard.md:2-4, .claude/commands/pr-review.md:2-4
Instruction Body
The content following the frontmatter is the instruction set for Claude. This is written in Markdown and can include several special features.
Variables
The instruction body can use variables to access arguments passed to the command from the user.
$ARGUMENTS: A single string containing all arguments provided after the command name.$1,$2,$3, etc.: Individual positional arguments.
Sources: README.md:479-481, .claude/commands/onboard.md:6
Inline Bash Commands
You can embed shell commands directly into the Markdown body to dynamically insert their output. This is done by wrapping the command in `!``...```.
For example, to include the current Git branch in the instructions:
Current branch: !`git branch --show-current`
Sources: README.md:483-486
Example Command File
The following is the content of the /onboard command, which demonstrates the structure of a command file.
File: .claude/commands/onboard.md
---
description: Deeply understand a task, explore the codebase, and create a detailed implementation plan.
allowed-tools: Read, Grep, Glob, Find, Bash
---
# Onboarding to Task: $ARGUMENTS
You are an expert software engineer onboarding to a new task. Your goal is to fully understand the requirements, explore the existing codebase, and create a detailed, step-by-step implementation plan.
## Your Process:
1. **Clarify the Goal:**
- Restate the task described in `$ARGUMENTS` in your own words.
- Identify any ambiguities or questions you have about the requirements.
2. **Explore the Codebase:**
- Use `Grep`, `Find`, and `Glob` to locate relevant files, components, and functions related to the task.
- Read the contents of key files to understand the current implementation.
- Identify the main entry points and control flows.
3. **Formulate an Implementation Plan:**
- Break the task down into small, logical steps.
- For each step, specify the files you will need to create or modify.
- Describe the changes you plan to make (e.g., "Add a new state variable to `MyComponent.tsx`," "Create a new function `calculateValue` in `utils.ts`").
- Identify potential challenges or edge cases.
4. **Summarize and Confirm:**
- Present the final plan for my review.
- Ask for confirmation before proceeding with any code modifications.
Sources: .claude/commands/onboard.md:1-30
Command Execution Flow
When a user invokes a slash command, Claude follows a clear sequence of steps to execute the associated task.
The diagram below shows the execution flow when a user runs a command like /ticket PROJ-123.
Sources: README.md:88-92, README.md:464-481
Example Commands
The repository provides several pre-built commands that serve as excellent examples of what can be achieved.
| Command | File | Description |
|---|---|---|
/onboard | onboard.md | Guides Claude to understand a task, explore the codebase, and create an implementation plan. |
/pr-review | pr-review.md | Instructs Claude to perform a pull request review based on a diff. |
/pr-summary | pr-summary.md | Generates a structured pull request summary, including title, description, and changes. |
/ticket | ticket.md | Manages a full ticket workflow, from reading requirements in a system like JIRA to implementing the feature and updating the ticket status. |
Sources: README.md:468, .claude/commands/onboard.md:2, .claude/commands/pr-review.md:2, .claude/commands/pr-summary.md:2, .claude/commands/ticket.md:2
Conclusion
Creating a new slash command is a straightforward process that significantly enhances the automation capabilities of Claude Code. By creating a simple Markdown file in the .claude/commands/ directory, developers can define custom workflows with specific instructions, tool permissions, and argument handling. This modular approach allows teams to build a library of powerful, project-specific automations that streamline development, enforce conventions, and reduce manual effort.
Sources: README.md:464-467, README.md:56-59