Skip to content

Repository files navigation

AI Commit

中文文档

AI-powered Git commit message generator. Analyzes your staged changes and generates Conventional Commits formatted messages using any OpenAI-compatible LLM or Claude Code.

demo

Install

Homebrew (macOS)

brew tap lifedever/tap
brew install ai-commit

Newer Homebrew versions require a one-time approval for third-party taps. If you see an "untrusted tap" error, run brew trust lifedever/tap and retry.

Shell Script (macOS / Linux)

curl -fsSL https://raw.githubusercontent.com/lifedever/ai-commit/main/install.sh | bash

Requires: Git, Node.js >= 22.19, npm

Configuration

Set your API key (add to ~/.bashrc or ~/.zshrc for persistence):

export AI_COMMIT_API_KEY="sk-your-api-key"

By default, it uses DeepSeek. To use other providers:

# OpenAIexport AI_COMMIT_API_URL="https://api.openai.com/v1/chat/completions"export AI_COMMIT_MODEL="gpt-4o-mini"# Volcengineexport AI_COMMIT_API_URL="https://ark.cn-beijing.volces.com/api/v3/chat/completions"export AI_COMMIT_MODEL="deepseek-v3-2-251201"# Local Ollamaexport AI_COMMIT_API_KEY="ollama"export AI_COMMIT_API_URL="http://localhost:11434/v1/chat/completions"export AI_COMMIT_MODEL="qwen2.5"

Any OpenAI API-compatible service works out of the box.

Claude Code Provider

If you have Claude Code installed, you can use it as the provider. Claude Code can read your source files for better context understanding, producing higher-quality commit messages.

export AI_COMMIT_PROVIDER="claude"# No API key needed — Claude Code manages its own authentication

Large diffs: When staged changes exceed 15K characters, ai-commit automatically truncates the diff and passes it directly to Claude instead of letting Claude read files itself. This prevents timeouts on very large changesets.

Usage

# Stage your changes first
git add .# Generate commit message (interactive)
ai-commit
# Auto-commit without confirmation
ai-commit -y
# Stage all tracked changes first (like git commit -a)
ai-commit -a
# Preview only, don't commit
ai-commit --dry-run
# Use Chinese for commit message
ai-commit -l zh
# Use a specific model
ai-commit -m gpt-4o-mini
# Add emoji to commit message (e.g. ✨ feat: add feature)
ai-commit --emoji
# Use Claude Code as provider
ai-commit -p claude
# Or set it permanentlyexport AI_COMMIT_PROVIDER="claude"
ai-commit

If nothing is staged but tracked files have unstaged changes, ai-commit lists them and asks whether to stage them (y/N). Untracked files are never staged automatically — git add them explicitly. With -y, nothing is ever staged implicitly.

Options

OptionDescription
-V, --versionShow version number
-a, --allStage all tracked changes first (like git commit -a; untracked files excluded)
-y, --yesAuto-commit without confirmation
-l, --language <lang>Set commit message language (en / zh)
-m, --model <model>Use a specific model
-e, --emojiAdd emoji to commit message
-p, --provider <provider>LLM provider (openai / claude)
-d, --dry-runPreview message only, don't commit
--updateUpdate ai-commit to the latest version
--uninstallUninstall ai-commit
-h, --helpShow help

Generation Stats

After each generation, a dim summary line is displayed showing:

──────────────────────────────────────────────────
feat(auth): add JWT token refresh mechanism
──────────────────────────────────────────────────
provider: openai · model: deepseek-chat · tokens: 156 · time: 2.8s

Auto Update Check

Each run automatically checks for new versions (non-blocking, cached for 24 hours). If a newer version is available:

💡 New version v1.4.0 available, run ai-commit --update to update

Git Alias (Optional)

git config --global alias.ac '!ai-commit'# Then use:
git ac

Update

ai-commit --update

Uninstall

ai-commit --uninstall

Environment Variables

VariableDescriptionDefault
AI_COMMIT_PROVIDERLLM provider (openai / claude)openai
AI_COMMIT_API_KEYRequired for openai provider. Your LLM API key-
AI_COMMIT_API_URLAPI endpointhttps://api.deepseek.com/v1/chat/completions
AI_COMMIT_MODELModel namedeepseek-chat
AI_COMMIT_LANGUAGEMessage language and CLI language (en / zh)en
AI_COMMIT_MAX_TOKENSMax tokens for generation500
AI_COMMIT_EMOJIAlways add emoji (true / false)false

Proxy

OpenAI provider supports system proxy via standard environment variables:

export HTTPS_PROXY="http://127.0.0.1:7890"# orexport HTTP_PROXY="http://127.0.0.1:7890"

Both HTTPS_PROXY / https_proxy and HTTP_PROXY / http_proxy are recognized. NO_PROXY / no_proxy is also supported to bypass proxy for specific hosts.

Changelog

See CHANGELOG.md for release history.

License

MIT

About

AI-powered Git commit message generator. Analyzes your staged changes and generates Conventional Commits formatted messages using any OpenAI-compatible LLM.

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages