Published on , Aurélien Vandaële

How to create custom slash commands in Claude Code: my /commit, /pr and /update-branch

Create a Markdown file in .claude/commands/ (or ~/.claude/commands/ for all your projects): commit.md becomes /commit. A header with a description, then the steps, written as a procedure. For a command that acts on git or on a server, add disable-model-invocation: true, otherwise Claude can run it on its own. I have six, and the rule that matters most in /commit fits in one line: commit only the files the session changed, by explicit path.

The problem: the same instruction, retyped and half followed

Some requests come back ten times a day: commit, open a pull request, bring a branch up to date. Typed by hand, they change every time. One day you forget to say “no git add -A”, the next you forget to ask for the changelog update. The agent does what you told it, not what you had in mind yesterday.

A slash command freezes the procedure. I type /commit, and Claude gets the same steps, in the same order, with the same prohibitions. What I learned once, I no longer explain again.

The method: one file per command

The file name gives the command name: .claude/commands/deploy.md runs with /deploy, and a subfolder adds a prefix (frontend/component.md gives /frontend:component). Mine live in ~/.claude/commands/, so they are available in every project.

The Claude Code documentation changed its vocabulary: custom commands have been merged into skills. Files in .claude/commands/ still work and accept the same header as a skill, except name and paths. The practical difference: a skill is a folder, with its SKILL.md and files next to it, scripts for example. My rule: a procedure that fits in a single text stays a command, a procedure that needs scripts becomes a skill. My whole testing and review chain is made of skills for that reason.

The header fields I use or recommend:

  • `description`: what the command does. It is also what Claude reads to decide whether to run it on its own.
  • `disable-model-invocation: true`: Claude can no longer run the command by itself, you have to type it. The documentation cites /commit and /deploy as the use case: you do not want Claude deciding to deploy because the code looks ready to it.
  • `argument-hint`: the hint shown during autocomplete, for example [branch].
  • `$ARGUMENTS` in the text: replaced by what you type after the command. Without the placeholder, Claude Code still appends the arguments at the end, as ARGUMENTS: <value>. That is why my /update-branch main works with no placeholder in the file.
  • `allowed-tools`: the tools Claude can use without asking, for the turn in which the command runs.

A line starting with ` !command runs before the content is sent to Claude, and its output replaces the line. Handy to hand git status` or the diff to a commit command straight away.

A real example: my /commit command

My /commit runs three phases, and each one comes from a failure:

  • A side-effect analysis before committing. For every changed file, the agent rereads the whole file and its direct neighbours: a changed signature with callers left behind, error handling removed, displayed text hardcoded instead of a translation key. It returns a status: BLOCK stops everything, WARN asks me, OK carries on silently. No style remarks, the linter handles those.
  • Only the session's files, by path. The agent lists the files it changed in this session and adds them one by one: git add -- <file>. Never git add -A, git add . or git add -u. A file it is unsure about is left out.
  • A check before the commit. git diff --cached --name-only must list exactly the session's files plus the changelog. One extra file and the command stops and reports it: it most likely comes from another session.

The rest is discipline: one changelog line per change, a conventional commit message derived from those lines, never an invented version number, no AI mention in the message. I also have a /commit-simple, the same without the analysis, for a typo or a comment.

The two other commands I use every day follow the same logic. /pr stops if changes are uncommitted, reads every commit on the branch and not just the last one, and refuses to push to main. /update-branch rebases the branch onto its parent, but first presents the plan and waits for my approval: number of commits to replay, shared branch or not. It pushes with --force-with-lease, never --force, and aborts the rebase if conflicts cascade over several commits.

The limits: what a command does not guarantee

  • A written rule is still a request. /commit forbids any AI mention in the message. On one of my projects, an agent still added a Co-Authored-By line to four commits in a row, because another instruction said the opposite. The rule now also lives in a hook, which blocks the commit whatever the model thinks. I tell that story in the hooks article.
  • My own files lacked `disable-model-invocation`. Rereading the documentation for this article, I saw that by default Claude can run a command without me typing it. For /update-branch, which rewrites history and force-pushes, the only protection was the sentence “ask for confirmation” in the text. That field is the fix to apply to any command that writes anywhere beyond the working folder.
  • The command only sees its own session. The check in /commit stops my commit from carrying another session's files. It does not stop another session, committing without a path, from carrying mine. It happened on 26 October: the fix is one worktree per session, detailed in the parallel sessions article.

How to get started

Take the request you retype most often and write it as a numbered procedure, with its prohibitions at the end:

---
description: Commit only the files changed in this session
disable-model-invocation: true
---

## Current state
!`git status --short`

1. List the files changed in this session.
2. Add them one by one: git add -- <file>.
3. Check that git diff --cached --name-only lists nothing else.
4. Commit with a conventional message.

Forbidden: git add -A, git add ., git commit -a.

Save this text as ~/.claude/commands/commit.md, type / in Claude Code, and the command shows up in the menu. Then, every time it fails, add the rule that would have prevented the failure. If the rule must hold even when the model forgets it, move it into a hook. And the day the command needs a script, turn it into a skill: choosing between a skill and a subagent is covered in this article.

Article written with the help of AI, from my daily practice and my projects.

The whole notebook