Chapter 1 · Slash Commands

Slash Commands in Claude Code

How to drive Claude from the keyboard — the four command types, the four mechanics that make them powerful, and how to build your own.

01 · Foundation

A slash command is just a Markdown file Claude reads

What it is

A shortcut you type as /name during a session. Behind it sits a plain Markdown file with a little frontmatter. No special language, no code to learn — just instructions in English that Claude follows when you invoke it.

Why it matters

Anything you do more than twice becomes a one-word command. Your best prompts move out of your head and into the repo — versioned, repeatable, and shareable with the whole team.

02 · The Landscape

Commands come in four types — you'll mostly write the second

ABuilt-in

Ship with Claude Code — /help, /clear, /model, /compact. 60+ of them, nothing to install.

BSkills — your own

Custom commands you write as a SKILL.md file — /commit, /optimize. This is where your real leverage lives.

CPlugin commands

Bundled inside an installed plugin — /pr-review:review. A whole set distributed together.

DMCP prompts

Exposed by a connected MCP server — /mcp__github__list_prs. Live data from external tools.

03 · Built-in Commands

You already have 60+ built-in commands — type / to see them

/clearWipe the conversation, keep your CLAUDE.md context
/compactSummarize and continue when the context window fills up
/contextVisualize what's eating your context window
/modelSwitch model and effort level mid-session
/rewindUndo code and/or conversation back to a checkpoint
/initGenerate a CLAUDE.md memory file for the project
You never have to memorize them — type / and start filtering by letter.
04 · The Shift

Custom commands have merged into skills

The old way — still works

.claude/commands/optimize.md

A single Markdown file. Nothing breaks; existing commands keep running exactly as before.

The new way — recommended

.claude/skills/optimize/SKILL.md

A folder that can bundle scripts and templates, auto-trigger when relevant, and run in its own isolated context.

Both give you /optimize. If a skill and a command share a name, the skill wins — so build new work as a skill.
05 · Anatomy

Every custom command is frontmatter plus instructions

---
name: fix-issue
description: Fix a GitHub issue by number. Use when given an issue ref.
argument-hint: [issue-number]
allowed-tools: Bash(git *), Read
---

# What Claude should do
1. Read the issue details
2. Implement the fix for issue #$ARGUMENTS
3. Run the tests and report the result
The block between --- is config. The description doubles as the trigger Claude reads to auto-run it. Everything below is just the prompt.
06 · The Mechanics

Four mechanics turn a static prompt into a real command

1$ARGUMENTS

Pass input. /fix-issue 123 lands "123" in $ARGUMENTS. Use $0, $1 for separate args.

2!`command`

Run a shell command first and inject its output, so Claude sees real state — your actual git diff, not a guess.

3@file

Pull a file's contents straight into the prompt — @src/app.js. Compare two with @old.js @new.js.

4allowed-tools

Scope what runs without asking — Bash(git *). Fewer permission prompts, tighter safety.

07 · Lifecycle

How a command runs, from keystroke to result

The same five beats behind every skill — locate, inject live context, substitute your input, then act.

1
Invoke
Type /commit
you start it
2
Locate
Find SKILL.md
.claude/skills/
3
Inject
Run !`cmd`
live context
4
Substitute
Fill $ARGUMENTS
your input
5
Execute
Claude acts
writes the commit
08 · Worked Example

/commit shows every mechanic working together

---
allowed-tools: Bash(git add:*), Bash(git commit:*), Bash(git diff:*)
argument-hint: [message]
description: Create a git commit with context
---

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

## Task
Write one conventional commit. If $ARGUMENTS is set, use it.
The !`git diff` runs before the prompt, so Claude reads your real changes and writes the commit message itself. That's the whole unlock.
09 · Safety Pattern

/push-all proves a command can be safe

It stages, commits, and pushes — but never blindly. Before it touches the remote it:

  • Scans for secrets — .env, *.key, *.pem, and real-vs-placeholder API keys
  • Flags large files (>10MB) and build artifacts like node_modules/ and dist/
  • Prints a change summary and waits for an explicit "yes" before pushing
Side-effecting commands should pause for a human. Set disable-model-invocation: true so only you can fire them — never Claude on its own.
10 · The Toolkit

This chapter ships eight ready-to-use commands

/optimizeFind performance bottlenecks, memory leaks, and caching wins
/prLint, test, and prepare a pull request with a summary
/commitWrite a conventional commit from your live git diff
/push-allSafe stage-commit-push with a secret and artifact scan
/generate-api-docsBuild API documentation straight from source code
/doc-refactorRestructure project documentation for clarity
/setup-ci-cdWire up pre-commit hooks and GitHub Actions
/unit-test-expandTarget untested branches and edge cases
11 · Installation

Installing a command takes one copy

Drop the file in the right folder and type the command — that's it.

# As a skill (recommended)
mkdir -p .claude/skills/commit
cp commit.md .claude/skills/commit/SKILL.md

# As a legacy command, shared with the whole team
cp *.md .claude/commands/
Project .claude/ ships with the repo for the team; ~/.claude/ keeps it personal. Then just type /commit.
12 · Best Practices

Good commands follow six simple habits

Do

  • Name them for actions — /commit, not /helper
  • Write a description with trigger conditions
  • Keep each command to a single task
  • Use !`...` so Claude knows real state
  • Set disable-model-invocation for side effects

Don't

  • Build commands for one-time tasks
  • Hardcode secrets, keys, or tokens
  • Pack complex branching logic into one file
  • Skip the description field
  • Assume Claude already knows current state
13 · Recap

Start with /commit, then write your own

A slash command is a Markdown file Claude reads. Four types — built-in, skills, plugin, MCP — and you'll mostly write skills. Four mechanics give them power: $ARGUMENTS for input, !`command` for live context, @file for file contents, and allowed-tools for safe scope. Skills are the future; your old .claude/commands/ files still work.

Pick the task you do most this week, and turn it into a command. That's how the leverage compounds.
Sid Dani · June 2026