All articles

Writing Your First Custom Slash Command

If you find yourself typing the same instructions again and again, turn them into a custom slash command. It's just a Markdown file, and the payoff is a reusable command you invoke with a slash.

Create the file

Custom commands live in a commands folder. For a command that belongs to the current project, use .claude/commands/:

.claude/commands/changelog.md

The filename becomes the command name. So changelog.md gives you /changelog.

Write the prompt

The body of the file is the prompt Claude runs when you call the command. Keep it as plain instructions:

Summarize the commits since the last tag and draft a changelog
entry grouped into Added, Changed, and Fixed.

Save it, and /changelog is ready to use.

Add frontmatter for control

You can put an optional frontmatter block at the top to set a few things:

---
description: Draft a changelog from recent commits
allowed-tools: Bash(git *)
model: sonnet
---
  • description shows up when you browse commands, so you remember what it does.
  • allowed-tools limits which tools the command may use.
  • model pins the command to a specific model.

All three are optional — a bare Markdown file with just a prompt works fine.

Why bother

Any multi-step instruction you repeat is a candidate: generating a changelog, running a specific review, scaffolding a file the way your team likes it. Writing it once means it runs the same way every time, and anyone on the project gets it too. Next up we'll make these commands flexible by feeding them arguments.

Comments

Be the first to comment.