An AI-powered Git commit assistant that analyzes your staged changes and generates a Conventional Commit title and description using OpenRouter.
β οΈ ImportantOpenRouter models may be removed, deprecated, or rotated over time. Make sure you add your own model name to your
.envfile before running the script.
Instead of staring at a diff trying to figure out what to write, run:
git add .
git aicommitThe AI generates the commit message, lets you review or edit it, and then creates the commit for you.
No Git editor. No Vim. No commit-message template.
- π€ AI-generated Conventional Commit titles
- π AI-generated commit descriptions
- βοΈ Edit the title before committing
- βοΈ Edit the description before committing
- βοΈ Choose title-only commits
- π Analyzes staged files and the actual staged diff
- π§ Uses recent commit history for context
- π Keeps generated commit titles concise
- π§© Supports Conventional Commit types, scopes, and breaking changes
- β‘ Runs directly through a simple Git alias
- π Uses OpenRouter's API
- π Supports fallback models when the configured model is unavailable
- π― Supports choosing a model for a single command
- π No framework or heavy dependencies
- π« No Git hook required
When you run:
git aicommitthe generator first asks whether you want a title only or a title + description commit.
git aicommit
β
βΌ
Analyze staged changes
β
βΌ
Generate title
β
ββββββΌβββββ
βΌ βΌ βΌ
Yes Edit No
β β β
β βΌ β
β Review β
β again β
ββββββ¬βββββ
β
βΌ
git commit
The title is generated first.
While you review or edit the title, the description is generated in the background. This means the description can already be ready by the time you finish reviewing the title.
git aicommit
β
βΌ
Analyze staged changes
β
βΌ
Generate title
β
βββββββββ΄βββββββββ
β β
βΌ βΌ
Review title Generate description
β in background
β β
ββββββββΌβββββββ β
βΌ βΌ βΌ β
Yes Edit No β
β β β β
β βΌ β β
β Review β β
β again β β
ββββββββ¬βββββββ β
β β
βββββββββ¬βββββββββ
βΌ
Review description
β
ββββββββΌβββββββ
βΌ βΌ βΌ
Yes Edit No
β β β
β βΌ β
β Review β
β again β
ββββββββ¬βββββββ
β
βΌ
git commit
When starting the command, you'll choose the type of commit you want:
What would you like to generate?
[1] Title only
[2] Title + description
[N] Cancel
Choose [1/2/n]:
For a title-only commit:
Generating AI commit title...
Generated commit title:
feat: add AI commit generation
[Y] Yes
[E] Edit
[N] Cancel
Choose [Y/e/n]: y
Committing...
[master 4c91a2f] feat: add AI commit generation
For a title + description commit:
Generating AI commit title...
Generated commit title:
feat: add AI commit generation
Generating AI commit description in background...
[Y] Yes
[E] Edit
[N] Cancel
Choose [Y/e/n]: y
If you choose to skip the description, the commit is created using the title only:
feat: add AI commit generation
The generator builds its context from your repository instead of asking the model to blindly guess what changed.
It provides:
For example:
M README.md
A ai_commit.py
The actual output of:
git diff --cachedThis is the primary source of truth for the generated commit.
Recent commit subjects are also provided so the generated message can better match the existing style of the repository.
The diff is limited to a configurable size before being sent to the API to avoid unnecessarily large requests.
Generated titles follow the Conventional Commits format:
<type>: <description>
Supported types:
feat
fix
docs
refactor
perf
test
chore
build
ci
feat: add user authentication
fix: prevent duplicate API requests
docs: update installation instructions
refactor(auth): simplify login flow
perf: reduce image processing overhead
Breaking changes are also supported:
feat!: remove legacy authentication API
or:
feat(api)!: change response format
- Git
- Python 3
- An OpenRouter API key
No Python packages are required.
Clone the repository or download it to your computer.
git clone https://github.com/RealUnfazed/AI-CommitMsg.git
cd AI-CommitMsgCopy the provided example configuration:
Copy-Item .env.example .envcopy .env.example .envOpen .env and set your API key:
OPENROUTER_API_KEY=your-api-keyYou can also change the default model and other settings in this file.
Tell Git where ai_commit.py is located:
git config --global alias.aicommit '!python "C:/path/to/ai_commit.py"'For example:
git config --global alias.aicommit '!python "C:/Users/Unfazed/Documents/Python/AI-CommitMsg/ai_commit.py"'Go to any Git repository, stage your changes, and run:
git add .
git aicommitThat's it.
The available configuration options are provided in .env.example.
A typical .env looks like:
# OpenRouter
OPENROUTER_API_KEY=YOUR_OPENROUTER_API_KEY
# Default model
OPENROUTER_MODEL=nvidia/nemotron-3-ultra-550b-a55b:free
# Comma-separated fallback models
OPENROUTER_FALLBACK_MODELS=
# OpenRouter API
OPENROUTER_URL=https://openrouter.ai/api/v1/chat/completions
OPENROUTER_HTTP_REFERER=https://github.com/RealUnfazed
OPENROUTER_TITLE=AI Conventional Commit Generator
# Generation
MAX_DIFF_CHARS=30000
MAX_HISTORY_COMMITS=30
MAX_TOKENS=180
REQUEST_TIMEOUT=120
TEMPERATURE=0Most users only need to configure:
OPENROUTER_API_KEY=your-api-key
OPENROUTER_MODEL=your-modelThe other options can be left at their defaults.
You can configure additional models in .env:
OPENROUTER_FALLBACK_MODELS=model-one,model-two,model-threeFor example:
OPENROUTER_MODEL=primary/model
OPENROUTER_FALLBACK_MODELS=fallback/model-one,fallback/model-twoIf the primary model is temporarily unavailable, overloaded, or rate-limited, the generator can try the configured fallback models.
This can be especially useful when using free models.
You can override the default model for a single run:
git aicommit --model "another/model"For example:
git aicommit --model "nvidia/nemotron-3-ultra-550b-a55b:free"This only affects that command and does not change your .env.
The project is designed to be used through:
git aicommitIf you need to change the alias later, remove the existing one:
git config --global --unset alias.aicommitThen configure it again:
git config --global alias.aicommit '!python "C:/path/to/ai_commit.py"'You can check the current alias with:
git config --global --get alias.aicommitStage the changes you want included:
git add .Then run:
git aicommitThe generator will ask:
What would you like to generate?
[1] Title only
[2] Title + description
[N] Cancel
Choose [1/2/n]:
Choose this when you only want a Conventional Commit title:
feat: add user authentication
Choose this when you want both:
feat: add user authentication
Add authentication support for user accounts and
protect authenticated routes.
Normal Git commits still work normally:
git commitBut git aicommit is the command that invokes the AI generator.
If the generated title isn't quite right:
[E] Edit
You can enter a replacement title.
The replacement is validated against the Conventional Commit format before continuing.
The same applies to the generated description:
[E] Edit
You can rewrite it before committing.
If you selected the title + description workflow, you can choose:
[N] No description
The commit is still created using the title only:
feat: add AI commit generation
AI-CommitMsg/
β
βββ ai_commit.py
βββ .env.example
βββ .gitignore
βββ README.md
βββ LICENSE
The generator is intentionally kept as a single Python script.
There is no framework, package manager, or build step.
The tool sends the following repository information to the configured OpenRouter model:
- Staged file names
- Staged diff
- Recent commit subjects
The tool does not send your entire repository automatically.
Only the information included in the generated prompt is sent to OpenRouter.
Be careful when staging files containing sensitive information such as:
- API keys
- Passwords
- Credentials
- Private keys
- Tokens
The model can misunderstand complicated changes or choose a less-than-ideal commit type.
Always review the generated title and description before committing.
Very large staged diffs are limited before being sent to the model.
This keeps API requests from becoming unnecessarily large, but means the model may not see every line of an extremely large change.
The limit can be configured with:
MAX_DIFF_CHARS=30000Running:
git aicommitwithout staged changes will stop with:
There are no staged changes.
Stage your changes first:
git add .OpenRouter models, especially free models, can occasionally be unavailable, overloaded, or rate-limited.
Configure fallback models if you want additional options.
This project does not require a Git hook.
The entire workflow is handled directly through:
git aicommitThis is intentional.
The AI workflow needs interactive steps for:
- Choosing title-only or title + description
- Title confirmation
- Title editing
- Description confirmation
- Description editing
- Skipping the description
A standalone Git command provides much cleaner control over that workflow than prepare-commit-msg.
- Python
- Git
- OpenRouter API
- Conventional Commits
- Python
urllib - Python
subprocess - Python
json
No external Python dependencies are required.
This project is licensed under the MIT License.
See the LICENSE file for the complete license text.
If you find this useful, consider giving the repository a β on GitHub.
Made with β€οΈ by RealUnfazed.