Claude Code & Context Engineering

Custom Slash Commands: Turn Your Repeated Claude Code Workflows into One-Word Apps

19 December 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

Stop retyping the same Claude Code prompts. Build custom slash commands with arguments, live shell output and file references — five worked examples based on Anthropic's official docs.

Five copy-ready custom slash commands with frontmatter, arguments and shell injection

Contents
  1. Where command files live
  2. Anatomy of a command file
  3. The four moving parts
  4. Five commands worth copying
  5. Namespacing with subdirectories
  6. Commands vs skills vs subagents
  7. Four mistakes that make commands disappoint
  8. Verdict

You have a prompt you paste into Claude Code three times a week. It is twelve lines long. It has placeholders you edit by hand, and half the time you forget one of the steps, so the output needs a correction round.

That prompt wants to be a slash command. A custom command is a Markdown file you write once; after that, typing /commit or /review-pr 123 runs the whole workflow, with the blanks filled in for you.

This guide covers the mechanics from Anthropic’s official Claude Code documentation: where command files live, the frontmatter fields that matter, arguments, file references, and live shell output. It ends with five commands worth copying, including two patterns that circulate in the Claude Code community on Reddit.

The short version: a command is a Markdown file in .claude/commands/ (project) or ~/.claude/commands/ (personal). The filename becomes the command name. Frontmatter controls the description, argument hint, permitted tools and model. Inside the body, $ARGUMENTS and $0, $1 carry what you typed, @file pulls in a file’s contents, and !`command` injects live shell output before Claude reads a word.

Where command files live

Location decides who gets the command and where it works:

Location Path Scope
Project .claude/commands/ in your repo Anyone who clones the repo; commit it and your team shares it
Personal ~/.claude/commands/ in your home directory Every project on your machine, only for you

The filename, minus the .md extension, is the command name. A file at .claude/commands/commit.md gives you /commit. There is no registration step and no config file to update: save the file, and the command appears in the / menu.

One honest note on formats. Anthropic’s docs now describe the .claude/commands/ file as the older format: skills are the newer home for the same idea, and a command file and a skill support the same frontmatter, except that command files have no name or paths field. Existing command files still work, and for a short, single-file workflow you type yourself, they remain the fastest route. When a workflow grows supporting files or needs to trigger on its own, graduate it using Claude Code Skills, Explained.

Anatomy of a command file

A command file is YAML frontmatter between --- markers, then Markdown instructions. Every field is optional, but four do most of the work:

Field What it does
description One line shown in the / menu; also how Claude judges what the command is for
argument-hint Placeholder text shown during autocomplete, e.g. [pr-number]
allowed-tools Tools Claude may use without asking permission during the turn that runs the command
model The model used for the turn when you invoke the command by name

Two habits follow from that table. First, write the description like a label you will scan under time pressure, because that is what it is. Second, treat allowed-tools as a safety feature, not a convenience: a command that only reads a diff should not hold permission to write files. The permission model behind this is covered in Claude Code Permissions and Sandboxing.

The four moving parts

Arguments: $ARGUMENTS and $0, $1

Everything you type after the command name arrives as text you can place inside the prompt. $ARGUMENTS expands to the full string. Positional placeholders are zero-based: $0 is the first argument, $1 the second. Wrap a multi-word value in quotes to keep it as one argument, so /draft "landing page copy" fast makes $0 equal to landing page copy.

If the body has no placeholder at all, Claude Code appends what you typed as ARGUMENTS: <value> at the end, so the input is never silently dropped. A placeholder with no matching argument stays in the text unchanged, which is worth knowing when a command seems to ignore an input: check your numbering first.

File references: @path

Writing @ followed by a file path in the command body pulls that file’s contents into the prompt when the command runs. This is the clean way to give a command a standing reference: a style guide, a checklist, a pricing table. The command stays short, the reference stays editable, and every run uses the current version of the file rather than a copy you pasted last month.

Live shell output: !command

The !`<command>` syntax runs a shell command first and replaces the placeholder with its output, so Claude receives real data instead of a description of data. A review command can inject the actual diff; a standup command can inject yesterday’s commits. Multi-line shell goes in a fenced block opened with ```! instead.

Two cautions from the docs. If an injected command fails, the whole invocation aborts and Claude never sees the command body, so keep injected commands boring and reliable. And injected commands run under your permission rules without prompting, which is one more reason to scope allowed-tools tightly.

Model choice per command

The model field lets a routine command run on a cheaper, faster model while your session stays on your main one. Summaries, changelog drafts and format conversions rarely need your strongest model. Routing routine work down is one of the levers in The Claude Code Cost Ladder, and per-command routing is the most precise way to apply it.

Five commands worth copying

1. /commit — a commit message writer that reads the real diff

---
description: Write a commit message from the staged diff and commit it
argument-hint: [optional-scope]
allowed-tools: Bash(git diff:*), Bash(git status:*), Bash(git commit:*)
model: haiku
---

Staged changes:
!`git diff --staged`

Write a commit message for these changes: subject line under 60
characters, then a short body explaining why, not what. If $ARGUMENTS
names a scope, prefix the subject with it. Show me the message, then
commit with it.

The injection means the message describes the diff you actually staged, not the one Claude guesses from open files. Pinning a small model keeps a ten-second task off your main model’s allowance.

2. /review-pr — a PR reviewer with the diff injected

---
description: Review a pull request by number
argument-hint: [pr-number]
allowed-tools: Bash(gh pr diff:*), Bash(gh pr view:*)
---

Pull request context:
!`gh pr view $ARGUMENTS`
!`gh pr diff $ARGUMENTS`

Review this pull request. Lead with anything that could break in
production, then correctness issues, then style. For each finding,
name the file and line. End with a one-line verdict: safe to merge,
merge with fixes, or needs rework.

This mirrors the pattern in Anthropic’s own docs example: fetch live PR data with the GitHub CLI, inject it, then give the review a fixed shape so results are comparable across runs. A fixed output shape is what turns a prompt into a tool; the same principle drives the briefs in Subagent Briefs That Get Used.

3. /log-error — feed failures back into CLAUDE.md

---
description: Log a mistake pattern into CLAUDE.md so it stops repeating
argument-hint: [what-went-wrong]
---

Something went wrong in this session: $ARGUMENTS

Write one rule that would have prevented it, in the imperative,
under 25 words. Add it to the mistakes section of this project's
CLAUDE.md. If a similar rule already exists, sharpen that rule
instead of adding a duplicate. Show me the line you added.

This one comes from a widely shared Reddit post collecting patterns from, in its author’s words, 2,000 hours of LLM-assisted coding (u/agenticlab1 on r/ClaudeAI, as relayed in community digests): log every failure as a rule, and let the file compound. It works because it attacks the loop at the source; see Debugging Agent Loops for the failure patterns worth logging. Keep the file lean, though — the discipline in The CLAUDE.md That Actually Works is what stops the mistakes section from becoming a swamp.

4. /frontend:component — a namespaced scaffolder

Save this one at .claude/commands/frontend/component.md, and the subdirectory becomes part of the name:

---
description: Scaffold a new frontend component in project style
argument-hint: [component-name]
---

Create a component named $0 in src/components. Match the structure,
naming and styling approach of @src/components/Button.tsx. Include
the props type, a default export, and a short usage example in a
comment at the top. Do not add new dependencies.

Namespacing is covered in its own section below; the point here is that one folder turns a pile of commands into a small, organised library. The @ reference makes the new component match an existing one you are proud of, which beats three paragraphs describing your style.

5. /standup — a personal command in ~/.claude/commands/

---
description: Draft a standup update from recent commits
allowed-tools: Bash(git log:*)
---

Yesterday's commits across my recent work:
!`git log --since="yesterday" --oneline --all`

Turn these into a standup update: three bullets on what shipped,
one on what is next, one on blockers. Plain language a non-engineer
can follow. If the log is empty, say so instead of inventing work.

Personal commands are where your cross-project habits belong: standups, weekly reviews, invoice summaries. Because they live in your home directory, they follow you into every repo, and they never leak into a client’s codebase when you commit.

Namespacing with subdirectories

Once you pass a dozen commands, a flat list gets hard to scan. Any subdirectory inside commands/ becomes a namespace: the path, with each / replaced by :, prefixes the command name. So .claude/commands/frontend/component.md is /frontend:component, and .claude/commands/git/changelog.md would be /git:changelog.

Group by job, not by tool: writing/, git/, review/, ops/. The same trick keeps a shared team library usable, and it is the organisational habit behind Sharing Skills Across Projects and Teams.

Commands vs skills vs subagents

These three get confused because all three hold instructions. The difference is who decides, and where the work runs:

Custom command Skill Subagent
Trigger You type /name You type /name, or Claude loads it when relevant Claude delegates, or you ask for a delegation
Form One Markdown file A folder with SKILL.md plus supporting files A Markdown agent definition with its own context
Best for A fixed workflow you run on purpose A procedure with reference material, used often A bounded job that would flood your main context

Rules of thumb. If you always want to be the one who starts it, and it fits in one file, write a command. If Claude should reach for it on its own, or it needs scripts and reference files alongside, write a skill — Convert Your Repeated Prompts Into Skills gives a sorting method, and Installing Claude Skills Safely covers auditing ones you did not write. If the job produces a pile of intermediate output you never want to read, delegate it; Subagents vs One Long Session draws that line. Note that a command can also grow a fork: set context: fork in frontmatter and it runs inside a subagent with the command body as its task.

Four mistakes that make commands disappoint

If a command exists but never fires the way you expect, the diagnosis steps in Why Your Claude Skill Is Not Triggering apply to command files too, since the two formats share the same loading machinery.

FAQ

Do custom commands still work now that skills exist? Yes. Anthropic’s docs describe .claude/commands/ files as the older format that still works, sharing the same frontmatter as skills except name and paths. New work that needs supporting files or automatic triggering belongs in a skill; a one-file workflow you invoke yourself is fine as a command.

What is the difference between $ARGUMENTS and $0? $ARGUMENTS expands to everything you typed after the command name, as one string. $0, $1 and so on pick out individual arguments by position, starting at zero. Use $ARGUMENTS for free-form input like a topic, and positional placeholders when the command takes two or three distinct inputs, like a filename and a format.

Can a command run shell commands before Claude sees it? Yes, with the !`command` syntax: the command runs first and its output replaces the placeholder in the prompt. If the shell command fails, the invocation aborts, and injected commands are checked against your permission rules rather than prompting you, so scope allowed-tools deliberately.

Where do I put a command I want in every project? In ~/.claude/commands/ in your home directory. Project commands belong in the repo’s .claude/commands/ so they are versioned and shared with anyone who clones it.

How is a custom command different from a hook? A command is a prompt you invoke; it tells Claude what to do. A hook is code Claude Code itself runs on an event, like formatting a file after every edit, whether or not Claude remembers to. For guarantees, use hooks — 5 Claude Code Hooks That Catch the Mistakes Agents Actually Make shows the pattern.

Verdict

Start with the prompt you paste most. One file, one description, one placeholder, and you have a command; add arguments and shell injection only when a real run shows you the need. Build /commit and /review-pr first if you code, /log-error if you keep watching the same mistake happen twice. When one of your commands outgrows a single file — reference docs, scripts, a need to trigger itself — that is the signal to promote it into a skill, and Write Your First Claude Skill is the next step.

Category: Claude Code & Context Engineering · Tags: #claude-code #skills #tutorial

Next step: this article is part of Claude Code guides, which covers the full topic from first setup to advanced use.

Related guides