Get the FREE Ultimate OpenClaw Setup Guide →

claude-code-slash-commands

Scanned
npx machina-cli add skill JamesPrial/claude-plugins/claude-code-slash-commands --openclaw
Files (1)
SKILL.md
4.9 KB

Claude Code Slash Commands

Create custom slash commands for Claude Code as Markdown files with optional YAML frontmatter.

Quick Reference

LocationScopeDescription Label
.claude/commands/Project (shared via git)(project)
~/.claude/commands/Personal (all projects)(user)

Command Structure

---
allowed-tools: Tool1, Tool2(pattern:*)
argument-hint: [arg1] [arg2]
description: Brief description shown in /help
model: claude-sonnet-4-20250514
disable-model-invocation: false
---

Your prompt instructions here.
Use $ARGUMENTS for all args, or $1, $2, etc. for positional.
Reference files with @path/to/file.
Execute bash inline with !`command`.

Creating Commands

Workflow

  1. Determine scope (project vs personal)
  2. Choose command name (filename without .md)
  3. Write frontmatter (optional but recommended)
  4. Write prompt body with argument placeholders
  5. Save to appropriate location

Frontmatter Options

FieldPurposeDefault
allowed-toolsTools the command can useInherits from conversation
argument-hintShows in autocomplete (e.g., [file] [options])None
descriptionBrief description for /helpFirst line of prompt
modelSpecific model to useInherits from conversation
disable-model-invocationPrevent SlashCommand tool from calling thisfalse

Arguments

All arguments - $ARGUMENTS captures everything:

Fix issue #$ARGUMENTS following our standards
# /fix-issue 123 high-priority → "123 high-priority"

Positional - $1, $2, etc. for specific args:

Review PR #$1 with priority $2 and assign to $3
# /review-pr 456 high alice → $1="456", $2="high", $3="alice"

Bash Execution

Use ! prefix to execute bash and include output in context:

---
allowed-tools: Bash(git:*)
description: Create commit from staged changes
---

## Context
- Status: !`git status --short`
- Diff: !`git diff --cached`
- Branch: !`git branch --show-current`

## Task
Create a commit message for these changes.

Important: Must include allowed-tools with Bash permissions when using ! commands.

File References

Use @ prefix to include file contents:

Review @src/utils/helpers.js for security issues
Compare @old.js with @new.js

Namespacing

Subdirectories organize commands (shown in description, not command name):

  • .claude/commands/frontend/component.md/component (project:frontend)
  • ~/.claude/commands/backend/api.md/api (user:backend)

Examples

Simple Command

# .claude/commands/review.md
Review this code for bugs, security issues, and style violations.

With Arguments

---
argument-hint: [issue-number]
description: Fix GitHub issue
---
# .claude/commands/fix-issue.md
Fix issue #$ARGUMENTS following our coding standards and create a PR.

Git Commit Helper

---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
argument-hint: [message]
description: Stage and commit changes
---
# .claude/commands/commit.md

## Current State
- Status: !`git status`
- Staged diff: !`git diff --cached`
- Branch: !`git branch --show-current`

## Instructions
Create a commit. If $ARGUMENTS provided, use as message. Otherwise generate from diff.

Code Generation

---
argument-hint: [component-name]
description: Generate React component
allowed-tools: Write
---
# .claude/commands/component.md

Create a React component named $1 with:
- TypeScript
- Tailwind styling
- Unit tests
- Storybook story

Reference our patterns: @src/components/Button.tsx

Multi-file Analysis

---
description: Compare implementations
argument-hint: [file1] [file2]
---
# .claude/commands/compare.md

Compare @$1 with @$2 and identify:
1. Architectural differences
2. Performance implications
3. Suggested improvements

Tips

  • Keep descriptions concise (shown in /help)
  • Use argument-hint for discoverability
  • Prefer $1, $2 when args have distinct roles
  • Use $ARGUMENTS for free-form input
  • Test commands with various argument patterns
  • Use extended thinking keywords for complex analysis

See Also

For complex multi-step workflows with scripts, templates, and reference docs, consider using Agent Skills instead. See references/skills-vs-commands.md.

Source

git clone https://github.com/JamesPrial/claude-plugins/blob/main/slash-command-guide/skills/claude-code-slash-commands/SKILL.mdView on GitHub

Overview

This skill helps you craft slash commands for Claude Code as Markdown files with optional YAML frontmatter. It covers frontmatter fields like allowed-tools, argument-hint, description, and model, plus how to use $ARGUMENTS, $1, and file references. Use it to organize project- or user-scoped commands.

How This Skill Works

Write a Markdown file under .claude/commands/ or ~/.claude/commands/, starting with a YAML frontmatter block that defines allowed-tools, argument-hint, description, model, and disable-model-invocation. The body uses $ARGUMENTS for all args or positional placeholders ($1, $2, etc.), references files with @path, and can include Bash execution with !`command` after declaring the allowed-tools Bash permission. This structure enables Claude Code to load and execute the command.

When to Use It

  • You want to create a new slash command (.md) for Claude Code to automate a task.
  • You need to document and share a command with project or personal scope.
  • You want to define argument hints to guide autocomplete and user input.
  • You are incorporating Bash-based steps and require allowed-tools for those commands.
  • You want to organize commands by scope using the .claude/commands or ~/.claude/commands paths.

Quick Start

  1. Step 1: Determine scope (project vs personal) and choose a command name.
  2. Step 2: Write frontmatter (allowed-tools, argument-hint, description, model, etc.) and craft the prompt body with $ARGUMENTS or $1, $2, etc., plus any @path references.
  3. Step 3: Save to the correct location (.claude/commands or ~/.claude/commands) and test with /help or a sample prompt.

Best Practices

  • Always include allowed-tools in frontmatter, especially when using ! for Bash execution.
  • Use argument-hint to improve autocomplete and clarity of required inputs.
  • Describe the command in description and set a concrete model if needed.
  • Place files under the correct directory: .claude/commands for project and ~/.claude/commands for user.
  • Use $ARGUMENTS for all inputs and test prompts to ensure correct substitution.

Example Use Cases

  • Simple Command: .claude/commands/review.md with a body that describes reviewing code for bugs and security issues.
  • With Arguments: a file like .claude/commands/fix-issue.md using frontmatter and a body containing # /fix-issue $ARGUMENTS.
  • Git Commit Helper: a command.md with Bash tools in frontmatter and a body that uses !`git status` and related commands.
  • Code Generation: a command.md showing argument-hint: [component-name] and a body that generates code scaffolding.
  • File References & Bash: a command that uses @src/utils/helpers.js and Bash commands to inspect content.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers