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.

FAQ

Can it draft a message from just the diff?
Yes, verified live — feeding it git diff --staged produced a one-line Conventional Commits message.
Can I restrict its permissions?
Yes — limit --allowedTools to read-only git commands so it can't commit/push on its own.
Does this work for PR descriptions too?
Yes, just point it at a branch diff instead of the staged diff.
Should I use the generated message as-is?
No — always confirm it captured the actual intent of the change.
How do I enforce the format?
Start with a line in CLAUDE.md's output-format block; a hook-based check is a possible (untested here) extension.