Fed up with crafting commit messages by hand?
mrgoonie/cmai.git
for the original shell script.- OpenRouter for providing the AI API.
- Conventional Commits for the commit message format.
- Keep a Changelog for the changelog format.
- https://github.com/insulineru/ai-commit
- https://github.com/compilerla/conventional-pre-commit
git
installed and configuredpre-commit
installed and configuredjq
installed- Used for escaping JSON
- An OpenRouter API key
curl
installed
Export API key for OpenRouter
Option 1: Store in .env file (recommended):
echo "OPENROUTER_API_KEY=your_key_here" > .env
source .env
Option 2: Use credential storage (alternative)
export OPENROUTER_API_KEY="$(pass show openrouter/api_key)"
Welcome to prepare-commit-msg
, a git hook that automatically generates conventional commit messages using AI based on
your staged git changes. Your commit messages will look like this:
- π€ AI-powered commit message generation (using
google/gemini-flash-1.5-8b
- SUPER CHEAP!)- Around $0.00001/commit -> $1 per 100K commit messages!
- π Follows Conventional Commits format
- π Debug mode for troubleshooting
- Install
pre-commit
. - Add hook configuration to
.pre-commit-config.yaml
.# See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/partcad/pre-commit rev: v1.1.0 hooks: - id: prepare-commit-msg verbose: true
By default, only filenames collected using git diff --cached --name-status
will be sent to OpenRouter. If you want to
share commit diffs using git diff --cached
with OpenRouter and get more detailed commit messages, you can use the
--open-source
option.
If you set custom
args
you will have to provide--commit-msg-filename
as last argument.
- id: prepare-commit-msg
args: [
"--debug",
"--open-source",
"--commit-msg-filename",
]
- π€ AI-powered commit message generation (using
google/gemini-flash-1.5-8b
- SUPER CHEAP!)- Around $0.00001/commit -> $1 per 100K commit messages!
- π Follows Keep a Changelog format
- π Debug mode for troubleshooting
- Install
pre-commit
. - Add hook configuration to
.pre-commit-config.yaml
.# See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/partcad/pre-commit rev: v1.1.0 hooks: - id: keep-a-changelog verbose: true
- API key is stored in environment variable or secure credential storage
- No data is persisted except the API key in your secure storage
- All communication is done via HTTPS
- By default, only file names are sent to OpenRouter
- When using
--open-source
, complete diffs are sent - Consider reviewing changes before staging to avoid leaking sensitive data
When you use the --open-source
option, the complete diffs of your staged changes are sent to the OpenRouter API to
generate more detailed commit messages. This means that the actual content of your code changes β including additions,
deletions, and modifications β is transmitted over the network. While OpenRouter uses secure HTTPS connections to
protect data in transit, sharing full diffs can potentially expose sensitive code, proprietary algorithms, or
confidential information. It's important to ensure that your code does not contain any sensitive or private data before
using this option. By default, only filenames collected using git diff --cached --name-status
are sent, minimizing the
amount of information shared.
- API is rate limited to prevent abuse
- Costs approximately $0.00001 per commit
- Large diffs may incur higher costs
Consider reading at least following docs for pre-commit
:
You can use following snippet for local testing:
# Stage some changes
git add .
# Trigger hook
pre-commit try-repo \
--verbose \
--hook-stage=prepare-commit-msg \
--commit-msg-filename=$(mktemp) \
. \
prepare-commit-msg \
--verbose \
--all-files \
...but it's easier just work in the fork directly and let .pre-commit-hooks.yaml
do the magic for you.
- Original work in upstream
mrgoonie/cmai.git
licensed under MIT - This fork is licensed under Apache License 2.0
- Integrate with 1Password.
- Allow truncate data which is sent to OpenRouter.
- Cross-platform support (Windows, Linux, macOS)
- Allow direct usage of LLMs.
- Add Ollama integration.
- Move to JSON format.
- Use JSON schema for response validation.
- Send only current version number of the changelog.
- Let LLM decide which version part should be updated (major, minor, patch).
- Move to JSON format.
- Format message to wrap at 50 characters.
- Create dedicated hook for updating
CHANGELOG.md
- Add GitHub stars chart.
- Allow override user prompt.
- Allow override system prompt.