Using Claude Code to write better git commit messages

Harish GargHarish Garg
1 min read

i am really bad at writing git commit messages. most of my messuages would be a 1,2,3 or “save“. As long as you are working solo on projects, this is fine. But working on git repos with multiple people on it are going you a tongue wagging.

I hate it so much so that I once wrote a whole tool 2 years back to use gpt-3 to write commit messages for me.

But now I have found an easier & better way.

I delegate the work of writing a good git commit message to claude code.

git diff | claude -p --model haiku "Summarize the changes in this git diff output."

or if you have already staged the changes, then…

git diff --staged | claude -p --model haiku "Generate a concise commit message summarizing the changes in this git diff output."

of if you want to save it to a file first…

git diff --staged | claude -p --model haiku "Generate a concise commit message summarizing the changes in this git diff output." > commit_message.txt

If you noticed, i am passing the —model option with “haiku“ so that it doesn’t uses lot of higher cost sonnet or opus tokens. you could use whatever you want. But I have found “haiku“ to be pretty good at this simple job.

0
Subscribe to my newsletter

Read articles from Harish Garg directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harish Garg
Harish Garg

I build systems that blend AI and automation to solve real-world problems