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.
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.
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.
You already have 60+ built-in commands — type / to see them
| /clear | Wipe the conversation, keep your CLAUDE.md context |
| /compact | Summarize and continue when the context window fills up |
| /context | Visualize what's eating your context window |
| /model | Switch model and effort level mid-session |
| /rewind | Undo code and/or conversation back to a checkpoint |
| /init | Generate a CLAUDE.md memory file for the project |
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.
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
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.
How a command runs, from keystroke to result
The same five beats behind every skill — locate, inject live context, substitute your input, then act.
/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.
/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
This chapter ships eight ready-to-use commands
| /optimize | Find performance bottlenecks, memory leaks, and caching wins |
| /pr | Lint, test, and prepare a pull request with a summary |
| /commit | Write a conventional commit from your live git diff |
| /push-all | Safe stage-commit-push with a secret and artifact scan |
| /generate-api-docs | Build API documentation straight from source code |
| /doc-refactor | Restructure project documentation for clarity |
| /setup-ci-cd | Wire up pre-commit hooks and GitHub Actions |
| /unit-test-expand | Target untested branches and edge cases |
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/
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
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.