- Zero Third-Party Dependencies — Powered strictly by the Python 3.9+ standard library (
json,urllib,subprocess,fnmatch) with no externalpippackages required. - Seamless
prepare-commit-msgWorkflow — Generates full Conventional Commits messages ongit commit, or appends structured details when you rungit commit -m "summary". - Smart Diff Compression &
.opencommitignoreFiltering — Automatically excludes lockfiles, minified bundles, and custom.opencommitignorepatterns while truncating oversized diffs to stay within token budgets. - Universal OpenAI-Compatible Support — Works out of the box with DeepSeek, OpenAI, Ollama, vLLM, and any
/v1/chat/completionsendpoint. - Multi-Language Output — Supports commit generation in English (
en), Simplified/Traditional Chinese (zh,zh-TW), Japanese (ja), and Korean (ko). - Graceful Fallback — Never blocks your Git workflow; if the network or API fails, your commit proceeds normally.
Add ai-commit to your .pre-commit-config.yaml and install the prepare-commit-msg hook:
repos:
- repo: https://github.com/mcocdaa/ai-commit.git
rev: v1.0.0 # Run `pre-commit autoupdate` for the latest release
hooks:
- id: ai-commitpip install pre-commit
pre-commit install --hook-type prepare-commit-msgexport AI_COMMIT_API_KEY="sk-..."
git add -A && git commitConfigure via environment variables, project .ai-commit.json, or global ~/.ai-commit.json (precedence: ENV > ./.ai-commit.json > ~/.ai-commit.json):
| Environment Variable | .ai-commit.json Key |
Default | Description |
|---|---|---|---|
AI_COMMIT_API_KEY |
api_key |
"" |
API key for the OpenAI-compatible provider |
AI_COMMIT_API_BASE_URL |
api_base_url |
https://api.deepseek.com |
Base URL for chat completions API |
AI_COMMIT_MODEL |
model |
deepseek-v4-flash |
Model identifier used for generation |
AI_COMMIT_LANGUAGE |
language |
en |
Output language (en, zh, zh-TW, ja, ko) |
AI_COMMIT_MAX_DIFF_LINES |
max_diff_lines |
1000 |
Max diff lines per file before abbreviation |
AI_COMMIT_MAX_OUTPUT_TOKENS |
max_output_tokens |
2048 |
Max tokens for generated response |
AI_COMMIT_IGNORE_FILE |
ignore_file |
.opencommitignore |
Ignore file for excluding paths from diff analysis |
AI_COMMIT_THINKING |
thinking |
false |
Enable/disable reasoning mode on DeepSeek models |
AI_COMMIT_DEBUG |
debug |
false |
Print diagnostic pipeline logs to stderr |
Advanced Configuration & Troubleshooting
{
"api_base_url": "https://api.deepseek.com",
"model": "deepseek-v4-flash",
"max_diff_lines": 1000,
"language": "en",
"ignore_file": ".opencommitignore",
"thinking": false
}Lockfiles (uv.lock, package-lock.json, pnpm-lock.yaml, Cargo.lock, poetry.lock) and *.min.js / *.min.css are ignored by default. Add custom .gitignore-style patterns in .opencommitignore:
*.md
dist/
fixtures/*.json- Verbose Hook Output: Set
AI_COMMIT_DEBUG=trueand addverbose: trueunder- id: ai-commitin.pre-commit-config.yamlto inspect diff filtering and API payloads. - Avoid Duplicate Hook Runs: If you use both
pre-commitandprepare-commit-msghooks, adddefault_stages: [pre-commit]at the top of.pre-commit-config.yaml.
Released under the MIT License.
