Having AI‑generated commit messages directly integrated into LazyGit
If you use LazyGit every day, you already know how it turns Git from a chore into something you can actually enjoy. But there is one part of the workflow that still tends to feel a bit tedious: writing good commit messages. In this post, I show how to plug OpenAI models directly into LazyGit using a tiny one‑file BASH script, so you can get AI‑generated commit messages based on your actual diffs, without waiting for external tools to catch up with the new OpenAI Responses API.
The result is a minimal, focused tool you can drop into your setup today: lgaicm. It behaves like a mini aichat that does exactly one thing: generate commit messages from Git diffs, optimized for LazyGit.
Why AI‑generated commit messages in LazyGit?
Commit messages matter. They are the story of your codebase. But let's be honest:
- After a long coding session, your brain is often too tired to craft a clean, descriptive message.
- Keeping consistency (especially with Conventional Commits) is easy to forget.
-
You sometimes end up with messages like
fix stufforwipthat are basically useless later.
Large language models are actually great at this. Feed them a Git diff, tell them your preferred commit style, and they will happily produce:
- Structured summaries of your changes.
-
Messages that match your favorite style, like
feat:,fix:,chore:, etc. - Multiple alternatives you can pick from.
And LazyGit, with its support for custom commands and menus, is the perfect place to integrate this. You press a key, LazyGit calls your AI helper, shows you a list of generated messages, and you commit with one key press.
The aichat idea, and the OpenAI Responses API roadblock
The inspiration for this whole setup came from a GitHub issue in the LazyGit repo: lazygit/issues/3212.
In that issue, someone proposed a neat approach: integrate AI‑generated commit messages into LazyGit using an external tool called aichat. It's a CLI chat client for various AI providers, and it can be scripted to do commit‑message generation from diffs. Sounds perfect.
But there was a catch.
OpenAI is moving to the Responses API for its newer and recommended models. Meanwhile, in that same LazyGit issue, sigoden, the maintainer of aichat, clearly stated that aichat will not support the new Responses API.
That puts you in an awkward position if, like many developers, you've already subscribed to OpenAI and want to use the newest models in your daily workflow. You essentially have three choices:
- Stick to old APIs or models just to keep aichat happy (not ideal).
- Fork aichat and re‑architect it around the Responses API, hoping not to break all its other built‑in features.
- Build something small and focused that only does commit messages.
Option 2 sounds powerful but quickly becomes a time sink. aichat does a lot of things: multi‑provider support, chat sessions, configuration, templating, etc. Swapping out its core API layer for Responses would mean reading and understanding a lot of code, then carefully testing everything so you don't regress important features.
That is way more work than necessary if you just want one thing:
“Give me a conventional commit message for my current diff, using an OpenAI model that talks via the Responses API.”
The minimal solution: lgaicm, a one‑file Bash script
Instead of forking aichat or waiting for new features, the approach I take is brutally simple:
-
Write a single BASH script that:
- Generates a Git diff from your working tree.
- Sends that diff to the OpenAI Responses API.
- Receives and prints a list of commit message suggestions, one per line.
- Wire that script into LazyGit as a custom command that powers a menu.
That script lives in its own tiny project: rakotomandimby/lgaicm.
Think of lgaicm
as a hyper‑minimal aichat clone that only does one
thing: generate commit messages from diffs using OpenAI's Responses
API.
Why a one‑file script is actually a feature
A single BASH file may sound too simple, but that's exactly why it works so well:
- Easy to audit: You can open the script and see everything it does in a few minutes.
- Easy to fork or tweak: Want to change the model, temperature, or prompt style? It's one file.
- No dependency hell: No need to install a complex tool or track its versions. It's just Bash + curl + Git.
- Tailored for one workflow: Instead of a general chat client, lgaicm is optimized for commit message generation in LazyGit.
Getting started with lgaicm
Let's go through the steps to put this into your own setup. You'll need:
- A working Git + LazyGit environment.
- An OpenAI API key (paid subscription, since you want the new models).
- A shell environment where you can create symlinks and export env vars.
1. Clone the repository
First, clone the lgaicm project locally:
git clone https://github.com/rakotomandimby/lgaicm
cd lgaicm
2. Expose the script on your PATH
The project contains a single BASH script,
lgaicm.sh, that you want to invoke from anywhere. The easiest way is to create a
symbolic link in a directory that is already on your
PATH, such as
/usr/local/bin.
ln -s "$(pwd)/lgaicm" /usr/local/bin/lgaicm
After that, you should be able to run
lgaicm from any Git repository.
3. Set your OPENAI_API_KEY
lgaicm uses the OpenAI Responses API directly over HTTP, so you have to
provide your API key in the environment. The script expects
OPENAI_API_KEY to be set:
export OPENAI_API_KEY="sk-..." # put your real key here
You can add that line to your shell profile
(~/.bashrc,
~/.zshrc, etc.) so it's available in all terminals, including the one LazyGit
uses.
Treat your API key like a password: don't commit it to Git, don't paste it into screenshots, and avoid putting it into scripts that live in your repository.
Integrating lgaicm into LazyGit
LazyGit has a very powerful customCommands system. You can attach a keybinding to a command, prompt the user for input, show menus, and then execute shell commands with templated arguments.
Here’s a complete example configuration that wires lgaicm into LazyGit so you can:
-
Press
Ctrl+Ainside LazyGit. - Pick a commit type (or let AI auto‑decide).
- Choose a commit message from an AI‑generated menu.
- Commit with that message.
customCommands:
- key: ""
description: "AI-powered conventional commit"
context: "global"
loadingText: "Generating commit messages..."
prompts:
- type: "menu"
key: "Type"
title: "Type of change"
options:
- name: "feat"
description: "A new feature"
value: "feat"
- name: "fix"
description: "A bug fix"
value: "fix"
- name: "chore"
description: "Maintenance / tooling / non-user-facing"
value: "chore"
- name: "docs"
description: "Documentation only"
value: "docs"
- name: "style"
description: "Formatting / linting / no behavior change"
value: "style"
- name: "refactor"
description: "Refactor without behavior change"
value: "refactor"
- name: "perf"
description: "Performance improvement"
value: "perf"
- name: "test"
description: "Add or update tests"
value: "test"
- type: "menuFromCommand"
title: "AI Generated Commit Messages"
key: "CommitFile"
command: "lgaicm suggest --type {{.Form.Type}}"
filter: '^(?P