Skip to content

m7medVision/lazycommit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lazycommit

AI-powered Git commit message generator that analyzes your staged changes and outputs conventional commit messages.

Features

  • Generates configurable number of commit message suggestions from your staged diff
  • Generates 10 pull request titles based on the diff between the current branch and a target branch
  • Providers: GitHub Copilot (default), OpenAI, Anthropic (Claude Code CLI)
  • Multi-language support: English and Spanish
  • Interactive config to pick provider/model/language and set keys
  • Simple output suitable for piping into TUI menus (one message per line)

Installation

go install github.com/m7medvision/lazycommit@latest

Or build from source:

git clone https://github.com/m7medvision/lazycommit.git
cd lazycommit
go build -o lazycommit main.go

CLI

  • Root command: lazycommit
  • Subcommands:
    • lazycommit commit — prints 10 suggested commit messages to stdout, one per line, based on git diff --cached.
    • lazycommit pr <target-branch> — prints 10 suggested pull request titles to stdout, one per line, based on diff between current branch and <target-branch>.
    • lazycommit config get — prints the active provider, model and language.
    • lazycommit config set — interactive setup for provider, API key, model, and language.

Exit behaviors:

  • If no staged changes: prints "No staged changes to commit." and exits 0.
  • On config/LLM errors: prints to stderr and exits non‑zero.

Examples

Generate suggestions after staging changes:

git add .
lazycommit commit

Pipe the first suggestion to commit (bash example):

MSG=$(lazycommit commit | sed -n '1p')
[ -n "$MSG" ] && git commit -m "$MSG"

Pick interactively with fzf:

git add .
lazycommit commit | fzf --prompt='Pick commit> ' | xargs -r -I {} git commit -m "{}"

Generate PR titles against main branch:

lazycommit pr main

Configuration

lazycommit uses a two-file configuration system to separate sensitive provider settings from shareable prompt configurations:

1. Provider Configuration (~/.config/.lazycommit.yaml)

Contains API keys, tokens, and provider-specific settings. Do not share this file.

active_provider: copilot # default if a GitHub token is found
language: en # commit message language: "en" (English) or "es" (Spanish)
providers:
  copilot:
    api_key: "$GITHUB_TOKEN"   # Uses GitHub token; token is exchanged internally
    model: "gpt-4o"            # or "openai/gpt-4o"; both accepted
    # endpoint_url: "https://api.githubcopilot.com"  # Optional - uses default if not specified
  openai:
    api_key: "$OPENAI_API_KEY"
    model: "gpt-4o"
    # endpoint_url: "https://api.openai.com/v1"  # Optional - uses default if not specified
  anthropic:
    model: "claude-haiku-4-5"  # Uses Claude Code CLI - no API key needed
    num_suggestions: 10        # Number of commit suggestions to generate
  # Custom provider example (e.g., local Ollama):
  # local:
  #   api_key: "not-needed"
  #   model: "llama3.1:8b"
  #   endpoint_url: "http://localhost:11434/v1"

Anthropic Provider (Claude Code CLI)

The Anthropic provider integrates with your local Claude Code CLI installation:

  • No API key required: Uses your existing Claude Code authentication
  • Fast and cost-effective: Leverages Claude Haiku model
  • Configurable: Set custom number of suggestions per provider

Requirements:

  • Claude Code CLI installed and authenticated
  • Command claude available in PATH

2. Prompt Configuration (~/.config/.lazycommit.prompts.yaml)

Contains prompt templates and message configurations. Safe to share in dotfiles and Git.

This file is automatically created on first run with sensible defaults:

system_message: "You are a helpful assistant that generates git commit messages, and pull request titles."
commit_message_template: "Based on the following git diff, generate 10 conventional commit messages. Each message should be on a new line, without any numbering or bullet points:\n\n%s"
pr_title_template: "Based on the following git diff, generate 10 pull request title suggestions. Each title should be on a new line, without any numbering or bullet points:\n\n%s"

Custom Endpoints

You can configure custom API endpoints for any provider, which is useful for:

  • Local AI models: Ollama, LM Studio, or other local inference servers
  • Enterprise proxies: Internal API gateways or proxy servers
  • Alternative providers: Any OpenAI-compatible API endpoint

The endpoint_url field is optional. If not specified, the official endpoint for that provider will be used.

Examples

Ollama (local):

active_provider: openai  # Use openai provider for Ollama compatibility
providers:
  openai:
    api_key: "ollama"  # Ollama doesn't require real API keys
    model: "llama3.1:8b"
    endpoint_url: "http://localhost:11434/v1"

Language Configuration

lazycommit supports generating commit messages in different languages. Set the language field in your config:

language: es  # Spanish
# or
language: en  # English (default)

You can also configure it interactively:

lazycommit config set  # Select language in the interactive menu

The language setting automatically instructs the AI to generate commit messages in the specified language, regardless of the provider used.

Supported languages:

  • en - English (default)
  • es - Spanish (Español)

Integration with TUI Git clients

Because lazycommit commit prints plain lines, it plugs nicely into menu UIs.

Lazygit custom command

Add this to ~/.config/lazygit/config.yml:

customCommands:
  - key: "<c-a>" # ctrl + a
    description: "pick AI commit"
    command: 'git commit -m "{{.Form.Msg}}"'
    context: "files"
    prompts:
      - type: "menuFromCommand"
        title: "ai Commits"
        key: "Msg"
        command: "lazycommit commit"
        filter: '^(?P<raw>.+)$'
        valueFormat: "{{ .raw }}"
        labelFormat: "{{ .raw | green }}"

This config will allows you to edit the commit message after picking from lazycommit suggestions.

  - key: "<c-b>" # ctrl + b
    description: "Pick AI commit (edit before committing)"
    context: "files"
    command: >
      bash -c 'msg="{{.Form.Msg}}"; echo "$msg" > .git/COMMIT_EDITMSG && ${EDITOR:-nvim} .git/COMMIT_EDITMSG && if [ -s .git/COMMIT_EDITMSG ]; then

        git commit -F .git/COMMIT_EDITMSG;
      else

        echo "Commit message is empty, commit aborted.";
      fi'

    prompts:
      - type: "menuFromCommand"
        title: "ai Commits"
        key: "Msg"
        command: "lazycommit commit"
        filter: '^(?P<raw>.+)$'
        valueFormat: "{{ .raw }}"
        labelFormat: "{{ .raw | green }}"
    output: terminal

Troubleshooting

  • "No staged changes to commit." — run git add first.
  • "API key not set" — set the appropriate key in .lazycommit.yaml or env var and rerun.
  • Copilot errors about token exchange — ensure your GitHub token has models scope or is valid; try setting GITHUB_TOKEN.

License

MIT

About

using AI to generate commit message suggestions

Resources

Stars

Watchers

Forks