# Using Claude Code to write better git commit messages

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.](https://github.com/harish-garg/ai-git-tool)

But now I have found an easier & better way.

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

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

or if you have already staged the changes, then…

```bash
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…

```bash
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.
