Skip to main content

Auto-generating Conventional Commits with Claude Code

· One min read

Claude Code can handle git operations automatically, but I usually check the generated code first before committing. This keeps everything under my control. However, there's still one problem: as a non-native English speaker, writing good commit messages in English is difficult.

I found a solution from the community - using a git alias to let Claude Code create commit messages automatically based on your code changes.

Just add this git alias to your ~/.gitconfig:

[alias]
ca = "!(git commit -m \"$(git diff --staged | claude -p 'Based on these staged changes, generate a single line commit message following conventional commit format. Choose the correct type (feat/fix/docs/refactor/style/test/chore) based on what was modified. Return only the commit message without explanation.')\" && git log --stat -1)"

After you stage your changes with git add, run git ca. This sends your staged changes to Claude Code, which automatically creates a proper Conventional Commit message.