A custom slash command in Claude Code is a saved prompt stored as a Markdown file. Type /review, hit Enter, and Claude runs the exact review checklist you wrote — the same wording, the same order, every single time. Once you have three or four of these set up, the repetitive typing that eats into a coding session mostly disappears, and your whole team can run the same checks the same way.
If you have ever typed the same long instruction into Claude Code for the third time in a day — “review this pull request against our checklist, check for security issues, and flag anything that breaks the style guide” — you already know the problem custom slash commands solve. This guide shows you how to create custom slash commands in Claude Code from scratch: where the files live, how to write a prompt that behaves reliably, how to pass arguments like file names, and how to lock a command down so it only uses the tools you trust.
You need nothing beyond Claude Code itself and a text editor. The whole job takes about ten minutes for your first command, and roughly two minutes each after that.
What Custom Slash Commands in Claude Code Actually Are
Every slash command is a plain .md file. The file name becomes the command name, and the file contents become the instructions Claude follows when you invoke it. A file called review.md gives you /review. A file called fix-tests.md gives you /fix-tests. There is no registration step and no settings screen — saving the file is the whole setup.
Commands come in two scopes, and the scope decides who can use them. Project commands live in the .claude/commands folder inside your repository, so they travel with the code and anyone who clones the repo gets them. Personal commands live in the commands folder inside your user-level .claude directory, so they follow you across every project on your machine but never leak into a shared repo.
That split matters more than it first appears. A code-review checklist that encodes your team’s standards belongs in the project folder, where it can be reviewed in a pull request like any other code. A shortcut that formats your commit messages the way you like them belongs in your personal folder. When a command exists in both places with the same name, the project version wins — which is exactly why you should keep shared commands in the project only and avoid duplicating names across folders.
Commands can also do more than hold static text. A command file can pull in the output of a shell command, reference files in your project, and accept arguments you type after the command name. Used well, a command stops being a saved sentence and becomes a small workflow script: one line from you, and Claude runs the git status check, reads the changed files, and writes the summary.
What You Need Before You Start
Preparation is the difference between a smooth ten-minute job and a frustrating afternoon. Gather everything below before you start, and keep your terminal open beside your editor so you can test each command the moment you save it.
- Claude Code installed and working — run
claudein your terminal and confirm you can start a session in your project. - A text editor you are comfortable with — VS Code, Sublime Text, or even nano in the terminal. Any editor that saves plain Markdown will do.
- A project to practise in — a real repository works best, because your first commands will be genuinely useful there.
- One repeated prompt in mind — the instruction you have typed more than twice. That is your first command candidate.
- A backup habit — project commands are files in your repo, so commit them. Personal commands are worth backing up too, since rebuilding them from memory is a chore.
No extra tooling is required. Namespaces are possible by placing commands in subfolders — .claude/commands/frontend/review.md becomes /frontend:review — which keeps a large team library tidy instead of dumping fifty files into one folder. If you are still finding your feet with the tool itself, our guide to using Claude Code for free covers the setup and the daily workflow before you start automating it.

Step-by-Step: Create Your First Custom Slash Command
Follow these steps in order the first time you try this. Each one builds on the last, and skipping ahead is the most common reason people have to start over. Once the process feels familiar, you can safely combine or reorder steps to suit your own workflow.
- Pick a prompt you repeat. Look for instructions you have typed more than twice, such as reviewing changes against a checklist or writing release notes. The best first commands are narrow: one job, one clear done state. A command that tries to do everything does nothing reliably.
- Create the commands folder. In your project root, make a
.claude/commandsdirectory. For a personal command, use thecommandsfolder inside your user-level.claudedirectory instead. The folder is hidden by the leading dot, so usels -aif you cannot see it in your file browser. - Add a Markdown file named after the command. A file called
review.mdcreates/review. Keep names short, lowercase, and hyphenated:fix-tests.mdis far easier to type thanfix_failing_tests_v2.md. The file name is the whole interface, so choose it like a command you will type fifty times a week. - Write the prompt as instructions, in order. Describe exactly what Claude should do, step by step. Write it as if handing the task to a colleague who knows the codebase but not your habits: name the files to read, the checks to run, and the format you want the answer in. Vague prompts produce vague output, so be specific about the order of operations and the shape of the result.
- Add a frontmatter description. At the top of the file, a short YAML frontmatter block with a
descriptionfield tells teammates — and future you — what the command does at a glance. It also shows up when Claude lists available commands, which makes a shared library far easier to browse. - Add arguments if the command needs input. Use the
$ARGUMENTSplaceholder inside the prompt, then pass the value when you run the command — for example,/review src/auth/login.ts. Refer to that value inside the prompt wherever the file name or ticket number belongs. Without the placeholder, file-specific commands force you to edit the prompt every time you run them. - Restrict the tools the command may use. Frontmatter can list the tools a command is allowed to call, such as read-only file tools for a review command. This keeps powerful commands safer, because a review command has no business editing files or running shell commands. Set
allowed-toolsdeliberately, especially for commands you run without reviewing the output first. - Run it with a realistic example, then refine. Type the slash command with a real file or a real task, not a toy example. Read the output against your checklist. When something is missing or out of order, edit the file — small wording changes usually fix behaviour. Treat the first run as a learning pass: the second version of a command is almost always noticeably better than the first.
Project Commands vs Personal Commands
The choice comes down to audience. Project commands are shared, version-controlled, and reviewed in pull requests, which makes them the right home for anything that encodes team standards: review checklists, release routines, migration steps. Personal commands are private shortcuts for your own habits: a command that summarises your working tree in your preferred format, or one that drafts commit messages in your voice. Keep the two separate and you avoid the classic confusion of two commands with the same name doing different things on different machines.
Passing Arguments the Right Way
Arguments turn a fixed prompt into a flexible tool. A review command that accepts a file path can review any file; one that accepts a ticket number can pull the right context every time. Inside the file, $ARGUMENTS expands to everything you typed after the command name. If you need individual values, numbered placeholders let you address them separately. Design the prompt so the argument lands exactly where the changing part belongs — at the top, where Claude reads it first — rather than buried in the middle of a paragraph.
Locking a Command Down With Allowed Tools
Frontmatter is where a command stops being a text file and starts behaving like a small program. Beyond the description, you can set allowed-tools to a short list — Read and Glob for a reviewer, for instance — and Claude will not reach for anything else while running that command. You can also set a model if a particular command works better with a specific one. Keep these blocks short: a command with a page of frontmatter is usually a command trying to do too much.
Real Command Examples Worth Stealing
Abstract advice only goes so far, so here are four commands that earn their keep in real projects. Adapt the wording to your codebase rather than copying them word for word — the details are what make them work.
A code review command. The prompt asks Claude to read the changed files, check them against the team’s style guide, flag security issues such as unsanitised input and exposed secrets, and finish with a short list of required changes followed by optional nits. It ends with an explicit instruction: do not edit anything, report only. Pair it with read-only allowed tools and it becomes a safe, repeatable second pair of eyes on every pull request.
A test-fix command. It takes a failing test file as an argument, runs the test suite for that file, reads the failure output, and fixes the smallest thing that makes the test pass without changing unrelated behaviour. The prompt stresses minimal diffs, because the temptation with test fixes is to rewrite half the module.
A commit-message command. It runs git status and git diff, summarises the change in plain language, and drafts a commit message in your team’s format — usually a short imperative summary line followed by a brief body. If your project keeps a CLAUDE.md file with team conventions, this command can read it first so the message style matches automatically. Our guide on how to write a CLAUDE.md file shows how to set that up.
A release-notes command. It reads the commits since the last tag, groups them into features, fixes, and chores, and drafts notes in the format your changelog already uses. Run it the day before a release and the notes are mostly done before you sit down to write them.
Start with three commands you will use daily — review, test-fix, and summarise changes are the usual trio — and let the library grow from real repetition rather than from a brainstorming session. Commands born from a genuine repeated prompt get used; commands invented in advance gather dust. For more ideas on what to automate, see our roundup of the best Claude skills for coding.

Advanced Tricks: Shell Output, File References, and Namespaces
Once the basics feel natural, three features turn good commands into great ones. First, a command can embed the output of a shell command using the ! syntax — !git status drops the current working-tree state straight into the prompt, so a commit-message command never works from stale information. This is the trick that makes commands feel alive rather than canned.
Second, commands can reference files with @ mentions, pulling the contents of a specific file into the prompt at run time. A review command that reads @CONTRIBUTING.md applies the project’s own rules without you pasting them in. Combine that with arguments and you have a command that adapts to whatever file you point it at.
Third, subfolders create namespaces. A growing team library stays usable when commands are grouped — frontend:review, backend:migrate, docs:changelog — instead of one flat list of fifty names. The folder path becomes part of the command name, separated by a colon, which keeps related commands together and makes them easy to find.
One more habit worth building: treat commands like code. Review changes to shared commands in pull requests, especially when they affect the whole team. A small edit to a review prompt changes what every reviewer sees, so it deserves the same scrutiny as a change to a linter config. If you are weighing Claude Code against other AI editors, our Cursor vs Claude Code comparison covers where each one fits best.
Common Mistakes to Avoid
Almost every failed attempt at this traces back to one of a handful of predictable errors. Read this list before your first attempt, and again if something goes wrong, because the fix is usually here.
- Making a command too broad. A command that does everything does nothing reliably. Keep each command to one job with a clear done state, and split anything bigger into two commands you run in sequence.
- Forgetting the argument placeholder. Without
$ARGUMENTS, file-specific commands force you to edit the prompt every time. Design commands to accept the changing part as an argument from the start. - Leaving powerful tools unrestricted. A command that can edit files and run shell commands should be deliberate about it. Use the allowed-tools setting for any command you run without reviewing the output first.
- Duplicating commands across folders. Project and personal commands with the same name create confusion about which one actually ran. Keep shared ones in the project only.
- Writing prompts for yourself, not for Claude. A prompt that says “review this properly” relies on shared context Claude does not have. Spell out the checklist, the order, and the output format as if briefing a new colleague.
- Never testing with real input. A command tested only on a trivial example breaks on the first real file. Test with the messiest realistic case you have, not the cleanest.
If you have already made one of these mistakes, do not panic. In most cases you can return to the last good step, correct the problem, and continue without starting from zero. And if you want to connect Claude Code to other tools, our guide to using the GitHub MCP server with Claude Code shows how to wire up repository access the same way.

Frequently Asked Questions
Where do custom slash commands live?
Project commands live in the .claude/commands folder of the repository, and personal commands live in the commands folder inside your user-level .claude directory. Subfolders create namespaced commands, such as /frontend:review.
How do I pass input to a slash command?
Type the command followed by your text — for example, /review src/auth/login.ts — and use the $ARGUMENTS placeholder in the file where that text should appear in the prompt.
Can a slash command run shell commands?
Yes. Commands can include bash output using the ! syntax, which is useful for pulling in git status, recent test results, or the output of any other command at run time.
What is the difference between a command and a subagent?
A command is a saved prompt that runs in your main session, in your current context. A subagent is a separate assistant with its own context window and tool set, better suited to long, self-contained jobs you want to run in parallel.
Can I share my custom slash commands with my team?
Yes — that is the point of project commands. Put the files in .claude/commands, commit them, and the whole team gets them on the next pull. Review changes to them in pull requests, just like any other shared configuration.

