Generates a commit message from your staged changes, so you can run git commit and get a
conventional commit message without writing one.
# Stage something git add . # Commit without a message. The message is generated for you. git commit
You get something like:
feat(auth): add email validation function
- Reads the staged diff, the branch name, and the previous commit message
- Writes a Conventional Commits message
- Works with OpenAI, DeepSeek, Azure OpenAI, and any OpenAI-compatible endpoint
- If the API call fails, the commit goes through with an empty message instead of blocking you
- A message you pass with
git commit -mis left alone
Install it in the project you want it for, then register the git hook:
# npm npm install --save-dev @light-cat/ai-commit-msg # or pnpm pnpm add --save-dev @light-cat/ai-commit-msg # Registers the prepare-commit-msg hook (installs simple-git-hooks if you do not have it) pnpm exec ai-commit setup
Or install it globally and set up each project:
npm install -g @light-cat/ai-commit-msg cd /path/to/your/project pnpm exec ai-commit setup
Put a .env in the git root, or ~/.ai-commit.env for a key you want everywhere. Environment
variables you set yourself still take priority.
# Required. OPENAI_API_KEY is also accepted. AI_API_KEY=your-api-key-here # Optional. Defaults shown. AI_API_BASE_URL=https://api.openai.com/v1 AI_MODEL=gpt-5.6-luna AI_TIMEOUT_MS=30000 AI_REASONING_EFFORT=low
OPENAI_API_KEY, OPENAI_BASE_URL, and OPENAI_MODEL are accepted as aliases.
Requests go to the Responses API, and fall
back to /chat/completions automatically when the endpoint does not serve /responses (a 404 or
405). That covers self-hosted and third-party gateways that only implement Chat Completions, so any
OpenAI-compatible endpoint works either way.
AI_REASONING_EFFORT controls how much the model reasons before answering, and defaults to low:
| Value | Effect |
|---|---|
none |
No reasoning. Fastest, and the cheapest for a task this small. |
low |
Default. A little reasoning, which helps when the diff mixes a feature and a refactor. |
medium / high / xhigh / max |
More reasoning. Slower and more expensive; rarely needed for a commit message. |
Not every provider accepts every level. DeepSeek supports low, high, and max, and rejects the
others; OpenAI accepts the full set. Endpoints that reject the parameter are retried once without
it, so older gateways keep working.
| Provider | AI_API_BASE_URL |
AI_MODEL |
|---|---|---|
| OpenAI | https://api.openai.com/v1 |
gpt-5.6-luna (default), or any chat model you have access to |
| DeepSeek | https://api.deepseek.com |
deepseek-flash or deepseek-v4-pro |
| Azure OpenAI | Your Azure endpoint | Your deployment name. Set OPENAI_API_VERSION if your endpoint needs it. |
| Local or other | Your OpenAI-compatible endpoint | The model name that endpoint expects |
- OpenAI: platform.openai.com
- DeepSeek: platform.deepseek.com
If you do not create a .ai-commitrc, messages are generated in Chinese. To get English, create
.ai-commitrc in your project root or home directory with:
language: en
The same file lets you replace the prompts entirely. See
.ai-commitrc.example for the available variables ({{diff}}, {{branch}},
{{lastCommit}}) and a full example of both languages.
After ai-commit setup, commit without a message:
git add .
git commitThe tool reads the staged changes, sends them to the model, and writes the result into the commit message file.
pnpm exec ai-commit setupThis installs the hook and configures simple-git-hooks if your project does not already use it.
If you already use simple-git-hooks, add this to package.json:
{
"simple-git-hooks": {
"prepare-commit-msg": "pnpm exec ai-commit"
}
}With lefthook:
# lefthook.yml pre-commit: commands: generate-commit-msg: run: pnpm exec ai-commit
# Print the generated message without writing it pnpm exec ai-commit --dry-run # Show what is sent to the model pnpm exec ai-commit --verbose # Help pnpm exec ai-commit --help
git committriggers theprepare-commit-msghook.- The tool collects the staged diff (
git diff --cached), the branch name, and the last commit message. - It sends those to the configured endpoint and asks for a conventional commit message.
- The result is written to the commit message file.
The diff is sent to the model in full up to 8000 characters. Past that, the budget is spread across the changed files instead of cutting the list short, so every file is still represented, and the files whose diffs were trimmed are named at the end.
Staged change:
diff --git a/src/auth.ts b/src/auth.ts +export function validateEmail(email: string): boolean { + return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); +}
Generated message:
feat(auth): add email validation function
Check that .env exists in the git root and contains AI_API_KEY, or set it in your environment.
- Make sure something is staged.
git addfirst. - Run
pnpm exec ai-commit --verboseto see what happened. - Check that your API key has credit and access to the model.
- Confirm the hook is installed:
cat .git/hooks/prepare-commit-msg
Pass one and the tool skips generation:
git commit -m "your message"See CONTRIBUTING.md for local development and debugging.
MIT
Source: github.com/EvilIrving/ai-commit
Also by the author: Light Stats, a native macOS menu bar monitor.