/commit-msg: Conventional Commits message from staged changes
A Claude Code slash command that reads your staged diff and recent history, then writes a Conventional Commits message with a precise subject and a body explaining why, and offers to commit it.
Skill in Engineering by AISkillHub Library
What it does
`/commit-msg` turns the staged diff into a commit message that follows the Conventional Commits format (`type(scope): subject`) and matches how your repository already writes commits.
**What it does** - Injects `git diff --cached` and the last 15 commit subjects into the prompt, so Claude sees exactly what is staged and your house style. - Chooses the type (`feat`, `fix`, `refactor`, `perf`, `docs`, `test`, `build`, `ci`, `chore`, `revert`) based on what the change does, not on which files changed. - Picks a scope from the area of code if your history uses scopes. - Writes a subject in the imperative mood, 72 characters or fewer, without a trailing period. - Adds a body when the reason is not obvious from the subject, and a `BREAKING CHANGE:` footer when a public interface changed. - Warns if the staged changes look like two unrelated changes that should be separate commits.
**What it will not do** It does not stage files, and it does not commit until you confirm. It does not invent issue numbers; it only adds a reference such as `Refs: #123` if you pass one or it appears in the branch name.
**Example** Staged: a fix to rounding in `src/cart/totals.ts` plus a new test. Output: ``` fix(cart): round line totals before summing
Totals were summed at full precision and rounded once, so carts with many discounted items could be off by one cent from the invoice. ```
How to use it
1. Save the file below as `.claude/commands/commit-msg.md` in your repository (or `~/.claude/commands/commit-msg.md` for all projects). 2. Stage your changes with `git add`. 3. In Claude Code run `/commit-msg`. Optional context goes after the command: `/commit-msg closes #412` or `/commit-msg scope=api`. 4. Review the message. Reply "commit" to have Claude run `git commit` with it (you will be asked to approve the command), or copy it.
Files
Save each file at the path shown, relative to your project root.