Soiposervices Logo
How to automatically generate a commit message - Blog Post Image
13 April, 2026

How to automatically generate a commit message

Icon Writer

Luigi Laezza

Coding tips

For years, my git history was cluttered with generic "wip" commit messages that did nothing for anyone who had to inspect the changes later on. If a teammate looked through a commit from six months ago, "wip" offered no insight. This problem led me to reconsider how I document my changes.

I decided to automate a part of my workflow. Rather than breaking my flow by pausing to write a detailed commit message, I integrated Claude into my shell via a simple bash function. With one command, I can have a commit message generated automatically based on the changes in my git diff.

My Commit Function

Here's the core part of the function:

function commit() {
  commitMessage="$*"

  git add .

  if [ "$commitMessage" = "" ]; then
     diff_input=$(echo "=== Summary ===" && git diff --cached --stat && echo -e "\n=== Diff (truncated if large) ===" && git diff --cached | head -c 50000)
     commitMessage=$(echo "$diff_input" | claude -p "Write a single-line commit message for this diff. Output ONLY the message, no quotes, no explanation, no markdown.")

     git commit -m "$commitMessage"
     return
  fi

  eval "git commit -a -m '${commitMessage}'"
}

Using the function without arguments stages your changes and sends a summary and a truncated diff to Claude. Claude then returns a single-line commit message that clearly describes the change. If you provide your own message, it is used directly.

Dotfiles and Their Importance

Dotfiles (like .zshrc or .bashrc) control the behavior of your terminal and command line tools. Keeping these files in a git repository lets you easily replicate your development environment across machines. In my setup, I include this automated commit function among other useful tools in my dotfiles.

How the AI Generation Works

Instead of sending the entire diff to Claude, I send two carefully selected pieces of information:

  1. Summary: Generated by git diff --cached --stat, showing a concise picture of file changes.
  2. Diff (truncated): Limited to 50,000 characters to avoid overloading Claude with unnecessary details.

Claude processes this input with the prompt "Write a single-line commit message for this diff..." and returns a commit message like:

  • Add caching layer to user repository
  • Fix N+1 query in post index
  • Remove deprecated payment gateway integration

These messages replace the vague "wip" messages with practical descriptions.

Adding a Spinner for a Smoother Experience

To improve the user experience, especially while waiting the 2-3 seconds it takes for Claude to generate a message, I added a spinner animation. This small detail provides visual feedback and transforms the process into a more polished tool. The full function includes steps for launching the spinner in the background, handling interrupts, and cleaning up after the message is generated.

By automating commit messages, I’ve streamlined my workflow without compromising on quality, making it easier for my team to understand the changes over time.

Related Articles

An easy guide on how to send html emails

An easy guide on how to send html emails

Ever wondered how to send emails using your GMAIL account? Wonder no more, on Mailtrap.io there is a great article on how to send HTML emails using your GMAIL

By Luigi Laezza
AWS costly mistake framework

AWS costly mistake framework

An in-depth look at how a missing VPC Endpoint in AWS turned routine S3 data transfers into a costly mistake, and ways to prevent it.

By Luigi Laezza

Get in touch with us!

We are here to help you get started with your next project

Get a free quote on your next project Arrow Icon

Subscribe to our newsletter

We are here to offer you our talent.

Our Partners

Github Icon LinkedIn Icon X Icon Facebook Icon Instagram Icon RSS Icon
Copyright © 2026 SoipoServices. | All Rights Reserved | Subscribe to our newsletter | Privacy Policy | Cookie Policy