Claude Code Slash Commands: Automate Your Prompts

A Claude Code slash command is a reusable prompt saved as a Markdown file in the .claude/commands/ directory, where the filename becomes the command name you invoke with a slash. The body of the file is the prompt Claude runs, and it can accept arguments, run shell commands, and reference files, turning a prompt you retype into a single saved keystroke.
Project commands live in .claude/commands/ inside the repository and ship with the code, so the whole team shares them. Personal commands live under your home directory and follow you across every project. Subdirectories become namespaces, so a file under a git folder is invoked as a namespaced command, which keeps a large library organized.
The trigger is the difference. A slash command is invoked explicitly by you when you type the slash, which suits deliberate on-demand routines. A skill is invoked by the model, which reads skill descriptions and decides on its own when one is relevant. Use a slash command for a button you press and a skill for a capability the agent applies automatically.
Yes. A line beginning with an exclamation mark runs a shell command and injects its output into the prompt, so a command can include the live git diff. An arguments placeholder captures what you type after the command name, and positional placeholders capture individual values, so you can pass a ticket number or file path into the command.
Use the allowed-tools field in the command's YAML frontmatter to scope it to exactly the tools it needs. A review command allowed only to read and grep, but not to write files or run arbitrary shell commands, is safe to run without supervision, and the tighter scope also keeps Claude focused on the task instead of wandering into unrelated edits.

Key Takeaway
Claude Code slash commands are reusable prompt templates saved as Markdown files in .claude/commands/, where each filename becomes a command you invoke with a slash. They capture a prompt you type often, accept arguments, and can run shell commands, so a repeatable workflow becomes one keystroke instead of a paragraph you retype.
Every developer builds up a set of prompts they retype constantly: review this diff against our checklist, write a conventional commit for the staged changes, scaffold a new API route the way we do it here. Retyping them wastes time and, worse, they drift, because the version you type on Friday is not the one from Monday. Slash commands fix that by turning a prompt into a saved, versioned file.
This guide covers what slash commands are, how to write one with arguments and tool permissions, how they differ from skills, and where they fit against the rest of Claude Code's customization surface. If you have ever pasted the same instructions twice, this is the feature that pays you back.
A custom slash command is a Markdown file whose contents are a prompt. Drop a review.md file into .claude/commands/ and you can invoke it as slash-review; the filename is the command name. Project commands live in the repo and ship with the code, while personal commands live under your home directory and follow you across projects.
The body is just the prompt Claude runs when you invoke the command, but a few pieces of syntax make it dynamic:
Optional YAML frontmatter configures the command. The most useful fields are description, which shows up when you browse commands; argument-hint, which documents the expected arguments; allowed-tools, which limits what the command may do; and model, which can pin a cheaper or stronger model for that specific task.
A review command that takes a ticket number and is allowed to read the diff looks like this:
---
description: Review the current diff against our checklist
argument-hint: [ticket-number]
allowed-tools: Bash(git diff:*), Read, Grep
---
Review the staged diff for ticket $ARGUMENTS.
Here is the current diff:
!git diff --staged
Check error handling, tests, and naming. Report each
issue as file:line plus a one-line fix, then end with a
clear pass or fail verdict.Use allowed-tools to scope a command to exactly what it needs. A review command that can read and grep but cannot write files or run arbitrary shell commands is safe to run on autopilot, and the tighter scope also stops Claude from wandering off the task into unrelated edits.
Slash commands and skills look similar, since both are Markdown with frontmatter, but they trigger in opposite ways, and choosing the wrong one is a common mistake.
Claude Code ships with built-in commands you already rely on: slash-clear to reset context, slash-compact to summarize it, slash-init to bootstrap a CLAUDE.md, and slash-agents to manage subagents. Your custom commands live alongside them without collision, and you can organize your own into folders.
Subdirectories under .claude/commands/ become namespaces, so a file at .claude/commands/git/commit.md is invoked as a namespaced command. This keeps a growing library legible once you have more than a handful, grouping related routines the way you would group modules in code.
A command that runs shell commands through the exclamation-mark syntax executes them whenever the command is invoked, so treat those lines with the same caution as a hook. Keep destructive operations out of shared slash commands, and prefer read-only commands like git diff or git status over anything that mutates state.
Slash commands earn their keep when the team shares them, so treat the .claude/commands/ folder as part of the codebase, not as personal scratch.
Slash commands are the simplest customization Claude Code offers and often the highest return: no code, just a saved prompt that stops drifting and starts being shareable. Look at the instructions you typed today, pick the one you will type again tomorrow, and save it as a command. You will have built a small, versioned automation library before you notice.