Writing Your Own Slash Command
A markdown file in .claude/commands/ becomes a callable workflow.
Custom slash commands are how you turn a repeated prompt into a one-keystroke action. Write the prompt as markdown, save it under .claude/commands/, type /your-command, done.
The use cases are endless: /review-pr, /write-tests, /draft-changelog, /find-todos. Each one is a small specialized agent run you've made repeatable. And when a command outgrows one file — it needs reference docs, scripts, or templates — graduate it to an Agent Skill (next lesson).
Create the commands folder
Inside your repo, create the directory if it doesn't exist.
mkdir -p .claude/commandsVerify.claude/commands/ exists at your project root.Author the command
Write a markdown file with the prompt you want fired. Use $ARGUMENTS for inline arguments.
# .claude/commands/review-pr.md Act as a senior reviewer. Look at the diff for the current branch. Flag: missing tests, unsafe SQL, leaky abstractions, dead code. If I named a focus area: $ARGUMENTSVerify.claude/commands/review-pr.md exists with that content.Use it
From any session in that repo, type the command.
/review-pr auth moduleVerifyThe agent runs the prompt with 'auth module' substituted into $ARGUMENTS.Iterate
Run the command. If the output is too long, too short, or wrong — edit the markdown and re-run. Slash commands evolve like any other prompt.
/review-prVerifyAfter edits, the new behavior is live on the next invocation. No reload needed.