Generating commit messages & PR descriptions with Claude Code
Show it just the diff and get a one-line Conventional Commit — verified live.
Automating the commit-message chore
Claude Code can read `git diff` and turn it into a message, so you can hand it just the diff and get a formatted suggestion back.
Verified live: staged diff → one-line message
With a staged diff (a zero-division fix plus a new function) in a scratch repo:
$ claude -p "Look only at git diff --staged and suggest a one-line\
Conventional Commits message. Don't run git commit." \
--allowedTools "Bash(git diff*),Bash(git status*)"
Real output:
feat(math): subtract関数を追加しdivideのゼロ除算チェックを実装
(Note: mixes a feature and a fix — split into two commits if you prefer.)Keep permissions read-only
Restrict `--allowedTools` to `Bash(git diff*)`/`Bash(git status*)` so it can't sneak in a commit or push on its own.
Letting it commit too
Add `Bash(git add*)`/`Bash(git commit*)` if you want it to act, but keep destructive ops like `git push --force` in `permissions.deny` (verified in the hooks article).
Fix the format once, in CLAUDE.md
State "commit messages use Conventional Commits" once in your CLAUDE.md output-format block instead of repeating it in every prompt.
The same trick works for PR descriptions
Swap the target from the staged diff to `git diff main...HEAD` to draft a PR description instead.