Skip to content

feat(commit): add AI-generated commit message support.#5389

Open
Blankeos wants to merge 2 commits intojesseduffield:masterfrom
Blankeos:feat/intuitive-ai-commit-messages
Open

feat(commit): add AI-generated commit message support.#5389
Blankeos wants to merge 2 commits intojesseduffield:masterfrom
Blankeos:feat/intuitive-ai-commit-messages

Conversation

@Blankeos
Copy link

@Blankeos Blankeos commented Mar 18, 2026

PR Description

Adds support for generating commit messages from staged changes using AI, via two approaches:

  • CLI: pipes the staged diff to any shell command (e.g. claude -p "...", codex, opencode run "...", codex exec "...", etc.) - utilizing non-interactive cli modes of your favorite agents!
  • API: calls any OpenAI-compatible HTTP endpoint directly

It's also intuitive because it's editable, it just fills out the commit input fields so you can check before committing. Other custom workarounds before this PR had no choice but to run git commit immediately.

Note: You must configure under git.commit.ai in your lazygit config. API keys can be referenced via
{env:MY_VAR} to keep secrets out of config files — lazygit also supports a .env file in the
config directory for this. Inspired by OpenCode

A new keybinding in the commit message panel triggers generation and shows a "Generating..."
status while waiting. Editing and submitting are blocked until the response arrives.

lazygitPR-opt.mp4

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide) - Added TestParseAIOutput (6 cases) in commits_helper_test.go and TestEnvInterpolate (4 cases) in app_config_test.go — all 10 pass
  • Text is internationalised (see here) - 4 new strings
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here) - New AI AIConfig struct added. It's hot-reloaded as I've tested.
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Add configuration options for generating commit messages using AI via
CLI commands or OpenAI-compatible APIs. Includes support for .env files
and {env:VAR} syntax for secure API key management.
Comment on lines +362 to +382
# AI commit message generation config
ai:
# CLI-based generation: runs a command with the staged diff piped to stdin.
# Example: "claude -p 'Generate a conventional commit message for this diff:'"
cli:
# The shell command to run. The staged diff is piped to stdin.
command: ""

# OpenAI-compatible API generation
api:
# OpenAI-compatible base URL, e.g. "https://api.openai.com/v1"
endpoint: ""

# Model name, e.g. "gpt-4o" or "llama3"
model: ""

# API key value. Use {env:MY_API_KEY} to read from an environment variable.
apiKey: ""

# System prompt. Defaults to a conventional commit prompt if omitted.
systemPrompt: ""
Copy link
Contributor

@ruudk ruudk Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't think we should make the integration like this. All we need is a command that can be triggered to generate a commit. Then the user can configure it however they want. No need for custom integrations and vendor specific things.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate a PR.

I hope you mean generate a commit . And also.. if I get this right, you're saying:

  • ai.cli.command - is good
  • ai.api fields - is bad because lazygit shouldn't have integrations like this.

I agree I think it'll keep this PR a lot leaner. And less burden on lazygit.

      # OpenAI-compatible API generation
      api:
        # OpenAI-compatible base URL, e.g. "https://api.openai.com/v1"
        endpoint: ""

        # Model name, e.g. "gpt-4o" or "llama3"
        model: ""

        # API key value. Use {env:MY_API_KEY} to read from an environment variable.
        apiKey: ""

        # System prompt. Defaults to a conventional commit prompt if omitted.
        systemPrompt: ""

I thought of adding it because people might just wanna hook up their own ai integrations as quickly as possible without installing a coding agent / anything. If that's the case, there should probably be a recommended minimal cli used alongside here just for this purpose. The closest I know is (https://github.com/simonw/llm). But tbh I think I could just make one in rust.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant commit indeed.

Yeah I have the feeling this will never be accepted with all that custom logic. So the simpler the change will be, the better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made that minimal CLI: https://github.com/Blankeos/modelcli

I'll go ahead and tweak an alternate PR with those minimal changes.

@Blankeos
Copy link
Author

Blankeos commented Mar 19, 2026

I made a simplified PR here btw: #5395

A command-only version. No more of the OpenAI compatible endpoint.

@ruudk
Copy link
Contributor

ruudk commented Mar 19, 2026

Better, this one can be closed then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants