Model or dataset
guanguans/ai-commit avatar
guanguans/ai-commit

guanguans/ai-commit: A PHP CLI That Turns Your Git Diff Into a Conventional Commit

Automagically generate conventional git commit messages with AI. - 使用 AI 自动生成约定式 git 提交信息。

394 stars22 forksPHPMIT

At a glance

What is it?
guanguans/ai-commit is a PHP 8.2 CLI that sends your staged git diff to a chosen AI provider and writes the resulting subject and body into a real commit. It is a good fit if you already live in a terminal and want conventional-commit formatting enforced by a prompt rather than by discipline.
Who is it for?
Adopt guanguans/ai-commit if your team already writes conventional commits and you want the subject line drafted from the staged diff without leaving the shell. Skip it if you work mainly in an IDE, if you cannot send diffs to an external provider, or if PHP 8.2 is not available on the machine.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What guanguans/ai-commit actually removes from your day

Writing a commit message is a small task that happens dozens of times a week, and it is the one place where a team's formatting convention usually decays. guanguans/ai-commit targets exactly that gap. It reads the staged diff, asks a language model to summarise it, and hands back a subject line and body in conventional-commit shape, for example a subject of the form chore(ai-commit): update tape and gif resources with a bulleted body underneath.

The audience is narrow and specific: developers who commit from a terminal, who already accept the conventional-commit prefix set (feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert), and who are willing to route their diff through a third-party model. If your workflow is a GUI git client, this tool does not meet you there. The README lists no editor extension, no VS Code integration and no JetBrains plugin, so anyone searching for an in-editor button will not find one here.

The generator abstraction and how a diff becomes a commit

The design is a pluggable generator layer rather than a single hardcoded API call. The README marks Bito CLI, ERNIE-Bot-turbo, ERNIE-Bot, GitHub Copilot CLI, GitHub Models CLI, Moonshot, OpenAI Chat and OpenAI as supported, with one unchecked entry left open in the list. Each generator has its own config namespace, which is why setup is a series of config set commands against keys such as generators.openai_chat.api_key or generators.bito_cli.binary.

Two families of generator exist. API-key generators (OpenAI, OpenAI Chat, Moonshot, the two ERNIE variants) need a secret. CLI-backed generators (Bito, GitHub Copilot CLI, GitHub Models CLI) instead shell out to a local binary, and the README marks their binary path as optional, which suggests the tool falls back to a default command name on PATH. That distinction matters for anyone in a regulated environment: the CLI-backed path may reuse credentials your existing tooling already holds.

The flow at commit time is interactive. The tool generates a message, then prompts you to choose a commit type, with auto as the first option for automatic type selection. It then prints the proposed subject and body in a table and asks Do you want to commit this message? (yes/no) [yes]. The README shows flags --generator, --no-edit, --no-verify and --ansi on the commit command. The tool does not push, and nothing in the README suggests it amends or rewrites history.

Installing guanguans/ai-commit and making your first AI commit

The README gives two install routes. The first downloads a prebuilt file from the repository and marks it executable, which avoids a Composer install entirely. The second uses Composer, globally or per project, and the README passes --dev in both cases.

bash
curl 'https://raw.githubusercontent.com/guanguans/ai-commit/main/builds/ai-commit' -o ai-commit -#
chmod +x ai-commit

After that, the file is run directly as ./ai-commit. If you prefer Composer, the global form puts the binary on your Composer bin path:

bash
composer global require guanguans/ai-commit --dev -v # global
composer require guanguans/ai-commit --dev -v # local

Now configure at least one generator. The README's quick start shows a key per provider; the OpenAI Chat one is the example used throughout its demo output. The --global flag writes to your user-level config rather than the current project.

bash
./ai-commit config set generators.openai_chat.api_key sk-... --global
./ai-commit config set generator openai_chat --global

The second command sets the default generator, which the README marks as optional. Then stage some work and run the commit command. The README also shows passing a generator per invocation instead of setting a default.

bash
./ai-commit commit
./ai-commit commit --generator=github_copilot_cli

What you should see: a generating line, a numbered commit-type prompt, the raw model response in a JSON-ish block with subject and body keys, then a bordered table showing both fields, and finally the yes/no confirmation before the commit is written. The README's captured run ends with Successfully generated and committed message. There is also a config file at .env.example in the repository root listing APP_ENV, BITO_CLI_PATH, ERNIE_API_KEY, ERNIE_SECRET_KEY and OPENAI_API_KEY, which is the environment-variable route for the same credentials.

Where guanguans/ai-commit gets in your way

The hard requirement is PHP >= 8.2. That is a recent floor, and it rules the tool out on older build images, on long-term-support distributions that ship PHP 8.1, and on machines where you would rather not install a PHP runtime at all. The standalone build file softens this only if the bundled runtime is self-contained, which the README does not state.

The second limitation is the confirmation prompt. The README's demo run is interactive by design: you pick a commit type, then answer yes or no. The --no-edit flag appears in the example command, but the README does not document what it suppresses, and it does not describe a fully non-interactive mode suitable for a pre-commit hook or CI job. If you want commits generated without a human at the keyboard, the README is silent on how to get there.

Third, the diff leaves your machine. Every supported generator is either a remote API or a CLI that talks to one, so the staged content of your commit is sent to OpenAI, Baidu, Moonshot or GitHub depending on configuration. For repositories containing secrets, customer data or regulated code, that is a policy question before it is a tooling question. The README does not document a local or offline model option.

Finally, the README does not document rollback, undo, or how to correct a message after the tool has committed it. The confirmation step is the only checkpoint shown.

How this differs from commitizen and commitlint

commitizen and commitlint, both listed among the repository topics, solve the neighbouring problem rather than the same one. commitizen prompts you for a type, a scope and a description, then assembles the message from your answers. The text still comes from you. commitlint checks a finished message against a ruleset and fails the commit if it does not conform.

guanguans/ai-commit inverts the order: the text is drafted from the diff first, and the type prompt exists so you can override the model's classification. That means the quality of the output depends on the model's reading of the diff, not on your recall of the last hour's work. It also means a model that misreads a refactor as a fix will produce a confidently wrong subject line, and the table preview is the only place you will catch it. commitlint would reject a malformed message but cannot tell whether the description is accurate. Neither approach catches a lie; only one of them requires you to know what the change was.

Maintenance, upgrades and the MIT licence

The repository is not archived, and the last push was on 2026-09-12, two days before this writing, so the project is being touched. The release cadence is less even: 1.15.3 landed on 2024-11-10, 1.15.4 on 2025-05-03, and 1.15.5 on 2025-05-17. The gap between 1.15.3 and 1.15.4 is roughly six months, and no release has been tagged since May 2025 despite the recent commits, so pin a version rather than tracking main.

Upgrade cost is mostly configuration surface. The config keys are namespaced per generator (generators.openai.api_key, generators.moonshot.api_key, and so on), so adding or swapping a provider is a config set command rather than a code change. The risk is provider drift: when OpenAI, Baidu or Moonshot change an endpoint or a response shape, the corresponding generator has to be updated, and the README does not describe a compatibility policy or a deprecation window.

The project is MIT licensed, which permits commercial and private use and modification. The licence covers the tool; it does not cover what you send to the model provider, and it does not cover the provider's own terms. Review those separately, and treat this as a description of the licence text rather than legal advice.

Editorial conclusion

Adopt guanguans/ai-commit if your team already writes conventional commits and you want the subject line drafted from the staged diff without leaving the shell. Skip it if you work mainly in an IDE, if you cannot send diffs to an external provider, or if PHP 8.2 is not available on the machine. Before rolling it out, run ai-commit config set generator openai_chat --global and check which provider the config file actually resolves to, because the default is not documented in the README.

Frequently asked questions

What is guanguans/ai-commit and what does it do?

It is a PHP command-line tool that generates conventional git commit messages with AI. It reads your staged changes, asks a configured model for a subject and body, shows them in a table, and commits after you confirm.

Is guanguans/ai-commit free to use?

The tool itself is MIT licensed, so the software is free to use and modify. The AI providers it calls are separate services, and the README does not state their pricing or whether any free tier exists.

Which AI providers does guanguans/ai-commit support?

The README lists Bito CLI, ERNIE-Bot-turbo, ERNIE-Bot, GitHub Copilot CLI, GitHub Models CLI, Moonshot, OpenAI Chat and OpenAI, with one further entry left unchecked. You select one with the generator config key or the --generator flag.

Does guanguans/ai-commit work in VS Code or JetBrains IDEs?

No. The README documents a terminal CLI only, with no VS Code extension or JetBrains plugin listed. It is installed via a downloaded build file or Composer and run as ./ai-commit.

What PHP version does guanguans/ai-commit require?

The README states PHP >= 8.2 as the requirement. There is also a standalone build file you can download and chmod +x, which the README presents as an alternative to installing through Composer.

Official sources

  1. guanguans/ai-commit on GitHub
  2. Issues
  3. License: MIT
  4. README
  5. Releases
Community notes

Community notes