Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save swartzrock/2dc9277a5cbb1d8ae155a59b73d5af9b to your computer and use it in GitHub Desktop.

Select an option

Save swartzrock/2dc9277a5cbb1d8ae155a59b73d5af9b to your computer and use it in GitHub Desktop.
A guide to setting up a custom command in Lazygit to generate git-commit messages with an LLM using LLM-Now

Never write a Lazygit commit message again!

This gist shows how to generate git-commit messages with LLM-Now in Lazygit.

Installation

  1. Install LLM-Now using brew install swartzrock/tap/llm-now (macOS / Linux) or downloading a native executable from the releases page.
  2. Set up an alias for a good provider and model in llm-now.
    1. I'm using haiku (Claude Haiku 4.5) here which works well.
    2. You can set up an alias by running llm-now --input "write a one-line poem about dogs" and selecting a local, cli, or cloud provider (with an API key env var). If you prefer to have llm-now securely store your api key run llm-now and choose Add or manage API keys… first.
  3. Go to your lazygit config directory (cd $(lazygit --cd)) and copy the config.yml and llm-now-functions.sh files below into the directory (or merge with your existing config.yml file).
    1. Hint: set XDG_CONFIG_HOME=~/.config on macOS if you don't like working in the Application Support directory and don't want to change the hard-coded ~/.config/lazygit paths in the examples.
    2. Change the key to one that you'll remember.

Usage

In lazygit switch to the Files tab, press <space> to stage one or more files and press z to view and edit the generated git commit message then <enter> to commit the changes.

# Include our llm_commit_message() function
os:
shellFunctionsFile: ~/.config/lazygit/llm-now-functions.sh
customCommands:
# Generate a commit message with llm-now
- key: "z"
context: files
description: Show a custom git commit input with a generated commit message
prompts:
- type: input
title: Commit summary [generated]
key: Summary
initialValue: >-
{{ runCommand "/bin/zsh -c 'source ~/.config/lazygit/llm-now-functions.sh; llm_commit_message'" }}
command: git commit --message {{.Form.Summary | quote}}
loadingText: Committing staged changes
output: log
llm_commit_message() {
local diff
if ! diff=$(git diff --cached); then
return 1
fi
if [ -z "$diff" ]; then
printf 'llm_commit_message: no staged changes\n' >&2
return 1
fi
{
printf '%s\n\n' \
'Write a Conventional Commit message for this staged diff. Return only the message.'
printf '%s\n' "$diff"
} | llm-now haiku
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment