Skip to content

bhupendra05/ai-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ai-commit

Never write a git commit message again. Stage your changes, run ai-commit, and let AI write a Conventional Commit message from your diff.

Python License PyPI

$ git add src/auth.py tests/test_auth.py
$ ai-commit

Staged: src/auth.py, tests/test_auth.py  +47 -12

╭─ Suggested commit message ─────────────────────────────────────╮
│  feat(auth): add JWT refresh token rotation with Redis backing  │
│                                                                  │
│  Implements sliding window refresh tokens. Old tokens are       │
│  invalidated on use to prevent replay attacks.                   │
╰──────────────────────────────────────────────────────────────────╯

Action [commit/edit/abort]: commit
✓ Committed!

Features

  • Conventional Commits formatfeat, fix, refactor, chore, etc. — automatically
  • Multiple backends — OpenAI GPT-4o-mini, Anthropic Claude, local Ollama (no API key)
  • Git hook support — auto-generates message on every git commit, opens editor to review
  • Generate alternatives — ask for N options and pick your favourite
  • Edit before commit — drop into $EDITOR if you want to tweak
  • Per-project config — set default backend/model in .ai-commit
  • Dry run mode — see the message without committing

Installation

pip install ai-commit

# With OpenAI backend (default)
pip install "ai-commit[openai]"

# With Anthropic backend
pip install "ai-commit[anthropic]"

# Everything
pip install "ai-commit[all]"

Setup

cp .env.example .env
# Add your API key(s)

Or set env vars directly:

export OPENAI_API_KEY=sk-...

Usage

Basic (stage → generate → commit)

git add .
ai-commit

Choose backend

ai-commit --backend anthropic
ai-commit --backend ollama --model llama3.2   # no API key needed
ai-commit --backend openai --model gpt-4o

Generate multiple options

ai-commit --count 3

Dry run (just print, don't commit)

ai-commit --dry-run

Skip confirmation prompt

ai-commit --yes

Install git hook (auto-generate on every commit)

# Install in current repo
ai-commit hook install

# Uninstall
ai-commit hook uninstall

After installing the hook, every git commit automatically generates an AI message. Your $EDITOR opens so you can review and edit it before the commit finalises.

Set default backend

# Per-project
ai-commit config --backend anthropic --model claude-3-haiku-20240307

# Global
ai-commit config --backend ollama --model llama3.2 --global

Configuration

~/.ai-commit or .ai-commit in your project root:

{
  "backend": "openai",
  "model": "gpt-4o-mini"
}

Supported Backends

Backend Model Requires
openai gpt-4o-mini (default), gpt-4o OPENAI_API_KEY
anthropic claude-3-haiku (default), claude-3-5-sonnet ANTHROPIC_API_KEY
ollama llama3.2 (default), mistral, phi3… Local Ollama running

Project Structure

ai-commit/
├── ai_commit/
│   ├── cli.py        # Click CLI (generate / hook / config)
│   ├── diff.py       # Git staged diff extraction
│   ├── generator.py  # OpenAI / Anthropic / Ollama backends
│   └── hook.py       # Git prepare-commit-msg hook installer
├── requirements.txt
└── setup.py

Contributing

PRs welcome! Adding a new LLM provider is as simple as adding a class in generator.py.

License

MIT © bhupendra05

About

AI-generated git commit messages from your staged diff — OpenAI, Anthropic, Ollama

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages