Claude Code Slash Commands

VerifiedCaution

Create and use custom commands with `/command-name` syntax to execute prompts, bash commands, and file references in Claude Code.

Sby Skills Guide Bot
ProductivityIntermediate
3/2/2026
Claude Code
#slash-commands#claude-code#prompt-templates#bash-execution#workflow-customization

Recommended for

Automated summary

This skill explains how to create and use Claude Code slash commands, including quick prompts, bash execution, and file references.

Strengths

  • Covers the full command file format (frontmatter, arguments, argument-hint)
  • Details bash execution with the ! prefix and allowed-tools rules
  • Explains file references with @ and namespacing via subdirectories
  • Provides a clear comparison between slash commands and skills

Limitations

  • Restricted to Claude Code with no equivalent for other tools
  • Does not describe any mechanism to test or debug commands
  • Assumes familiarity with markdown and YAML
When to use it

Use it when automating recurring prompts or adding bash execution and file references to custom commands.

When not to use it

Avoid it for complex multi-file or auto-discovered workflows, which are better suited to skills.

Security analysis

Caution
Quality score84/100

This is a documentation/reference skill describing Claude Code slash-command mechanics. It grants Bash and Write and shows shell snippets, but every snippet is either a read-only git inspection or scaffolding of markdown command files in standard config paths. There is no destructive, exfiltrating, or obfuscated behavior, so risk is limited to the inherent power of the granted tools rather than malicious content.

Findings
  • •Skill declares Bash and Write in allowed-tools, and its examples run shell commands (mkdir, cat heredocs) that write into .claude/commands and ~/.claude/commands, modifying agent configuration directories.
  • •The `!`-prefix bash-execution pattern is documented as a general capability, so future user commands could run arbitrary shell with declared Bash(...) scopes.
  • •Example commands themselves are benign: read-only git status/diff/log, head, and file scaffolding. No curl|sh, no rm -rf, no credential exfiltration, no obfuscation, no safety-disabling instructions.
How this analysis is made

Examples

Create a commit command
Create a slash command that generates semantic commit messages using git status and staged diffs.
Bash in commands
How do I add bash execution to my slash command, and which allowed-tools do I need?
File references
Show me how to reference style guide and source files inside a slash command with @.

name: slash-commands description: Create and use Claude Code slash commands - quick prompts, bash execution, file references allowed-tools: [Read, Write, Bash] user-invocable: false

Slash Commands Reference

Create and use user-triggered prompts with /command-name syntax.

When to Use

  • "How do I create a slash command?"
  • "What slash commands are available?"
  • "Add bash to my command"
  • "Use file references in commands"
  • "Slash commands vs skills"

Built-in Commands

| Command | Purpose | |---------|---------| | /clear | Clear conversation history | | /compact | Compact conversation with focus | | /config | Open settings interface | | /cost | Show token usage | | /agents | Manage sub-agents | | /mcp | Manage MCP servers | | /memory | Edit CLAUDE.md files | | /model | Select AI model | | /review | Request code review | | /resume | Resume session | | /help | Get usage help |

Creating Commands

Project Commands

mkdir -p .claude/commands
cat > .claude/commands/optimize.md << 'EOF'
---
description: Analyze code for performance issues
---

Review this code for:
- Performance bottlenecks
- Memory leaks
- Caching opportunities
EOF

Personal Commands

mkdir -p ~/.claude/commands
cat > ~/.claude/commands/review.md << 'EOF'
---
description: Security-focused code review
---

Check for vulnerabilities:
- Input validation
- SQL injection
- XSS risks
EOF

Command File Format

---
description: Brief description for /help
allowed-tools: [Bash, Read, Write]  # Optional
argument-hint: "[file] [type]"       # Optional
---

Your markdown instructions here.
Use $1, $2 for arguments or $ARGUMENTS for all.

Bash Execution

Run bash before loading prompt with ! prefix:

---
allowed-tools: Bash(git:*), Bash(grep:*)
description: Git commit helper
---

Current status: !`git status`
Staged changes: !`git diff --staged`
Recent commits: !`git log --oneline -5`

Based on these changes, suggest a commit message.

Rules:

  • Must declare allowed-tools: Bash(...) in frontmatter
  • Use backticks: !`command`
  • Output is included in Claude's context

File References

Include files with @ prefix:

Review against @.claude/STYLE_GUIDE.md

Compare:
- @src/old.js
- @src/new.js

Refactor files matching @src/**/*.util.ts

Arguments

---
argument-hint: "[pr-number] [priority]"
---

Review PR #$1 with priority: $2

# Or use all arguments:
Fix issue #$ARGUMENTS

Usage:

/review-pr 456 high
# $1 = "456", $2 = "high"

Namespacing

Organize with subdirectories:

.claude/commands/
├── frontend/
│   └── component.md    → /component (project:frontend)
└── backend/
    └── endpoint.md     → /endpoint (project:backend)

MCP Slash Commands

MCP servers expose prompts as commands:

/mcp__github__list_prs
/mcp__github__pr_review 456
/mcp__jira__create_issue "Bug" high

Slash Commands vs Skills

| Aspect | Slash Commands | Skills | |--------|----------------|--------| | Invocation | Explicit: /command | Auto-discovered | | Files | Single .md file | Directory with SKILL.md | | Use Case | Quick prompts | Complex workflows |

Use slash commands for: Frequently typed prompts, simple templates Use skills for: Complex workflows, multiple files, auto-discovery

Example: Complete Git Commit Command

---
description: Generate semantic commit message
allowed-tools: Bash(git:*), Read
argument-hint: "[type]"
---

# Semantic Commit Generator

Staged files: !`git diff --name-only --cached`

Diff preview:
!`git diff --cached | head -100`

Generate a conventional commit message.
Type: $1 (feat/fix/docs/style/refactor/perf/test/chore)

Format: `<type>(<scope>): <subject>`

Usage: /commit feat

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/claude-code-slash-commands-mm8o51rg' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/claude-code-slash-commands-mm8o51rg/download' --output '.skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md.part' && mv '.skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md.part' '.skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md' && test -s '.skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/slash-commands' && cp -R '.skill-downloads/claude-code-slash-commands-mm8o51rg' '.claude/skills/slash-commands'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/claude-code-slash-commands-mm8o51rg'

openskills read 'claude-code-slash-commands-mm8o51rg'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/claude-code-slash-commands-mm8o51rg/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills