Skip to main content

AI generated commit messages

Project description

Release Notes Downloads Python Versions GitHub CI Status License: MIT

aiautocommit

Generate intelligent commit messages using AI. aiautocommit analyzes your staged changes and creates conventional commit messages, handling both small tweaks and large changesets effectively.

Yes, there are a lot of these. Main ways this is different:

  • Simple codebase. < 400 LOC and most of it is prompts and comments.
  • Ability to easily customize prompts on a per-repo basis

Installation

uvx aiautocommit

Or via pip:

pip install aiautocommit

MCP Server Configuration

Tool Configuration Location Notes
Claude Desktop macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Standard MCP JSON format with mcpServers object
Claude Code ~/.claude.json Can also use claude mcp add CLI command
Cursor Global: ~/.cursor/mcp.json
Project: .cursor/mcp.json
Standard MCP JSON format
GitHub Copilot Repo: .vscode/mcp.json
Personal: VS Code settings.json
Requires VS Code 1.102+, standard MCP format
Google Gemini Interactive: .idx/mcp.json
CLI: .gemini/settings.json
Standard MCP JSON format

Features

  • Generates conventional commit messages
  • Customizable prompts and exclusions
  • Pre-commit hook integration
  • Supports custom config directories
  • Does not generate a commit during a merge or reversion (when an existing autogen'd msg exists)
  • Optional difftastic integration for syntax-aware semantic diffs

Getting Started

Set your OpenAI API key:

export OPENAI_API_KEY=<YOUR API KEY>

Stage your changes and run aiautocommit:

git add .

# this will generate a commit message and commit the changes
aiautocommit commit

# or, just to see what it will do
aiautocommit commit --print-message

Using the CLI directly is the best way to debug and tinker with the project as well.

Difftastic Integration (Optional)

aiautocommit can optionally use difftastic for syntax-aware diffs that understand code structure rather than just line-by-line changes. This helps the AI distinguish between refactoring (variable renames, code movement) and actual functional changes, leading to more accurate commit messages. Install with brew install difftastic (macOS) or cargo install difftastic (Linux/Windows), then enable with:

aiautocommit commit --difftastic

Customization

Logging

First, you'll want to enable logging so you can extract the diff and prompt and iterate on it in ChatGPT:

export AIAUTOCOMMIT_LOG_LEVEL=DEBUG
export AIAUTOCOMMIT_LOG_FILE=aiautocommit.log

Now, you'll have a nice log you can tail and fiddle with from there.

Using Config Directory

aiautocommit looks for configuration files in these locations (in priority order):

  • .aiautocommit/ in current directory
  • $XDG_CONFIG_HOME/aiautocommit/ (defaults to ~/.config/aiautocommit/)
  • Custom path via aiautocommit_CONFIG environment variable

To get started with customization:

aiautocommit dump-prompts

This creates a .aiautocommit/ directory with:

  • diff_prompt.txt: Template for generating diff summaries
  • commit_prompt.txt: Template for generating commit messages
  • exclusions.txt: List of files to exclude from processing
  • commit_suffix.txt: Static suffix to append to commit messages. Useful for trailers.

Installing Pre-commit Hook

To automatically generate commit messages during git commits:

aiautocommit install-pre-commit

Learn more about git hooks here.

Customize Scopes

First, dump the prompts into your project:

aiautocommit dump-prompts

Then add your scope specification to the commit prompt:

#### 4. **Scopes**

Optional scopes (e.g., `feat(api):`):
- `api`: API endpoints, controllers, services.
- `frontend`: React components, styles, state management.
- `migration`: Database schema changes.
- `jobs`: Background jobs, scheduled tasks.
- `infra`: Infrastructure, networking, deployment, containerization.
- `prompt`: Updates to LLM or AI prompts.

Lefthook Configuration

Lefthook is an excellent tool for managing git hooks. To use aiautocommit with lefthook, add the following to your .lefthook.yml:

prepare-commit-msg:
  commands:
    aiautocommit:
      run: aiautocommit commit --output-file "{1}"
      interactive: true
      env:
        # without this, lefthook will run in an infinite loop
        LEFTHOOK: 0
        # ensures that LOG_LEVEL config of the current project does not interfere with aiautocommit
        LOG_LEVEL: info
        OPENAI_LOG: warn
      skip:
        merge:
        rebase:
        # only run this if the tool exists
        run: ! which aiautocommit > /dev/null

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key
  • AIAUTOCOMMIT_OPENAI_API_KEY: Unique API key for OpenAI, overrides OPENAI_API_KEY (useful for tracking or costing purposes)
  • AIAUTOCOMMIT_MODEL: AI model to use (default: gpt-4-mini)
  • AIAUTOCOMMIT_CONFIG: Custom config directory path
  • AIAUTOCOMMIT_DIFFTASTIC: Enable difftastic for syntax-aware diffs (set to "1", "true", or "yes")
  • LOG_LEVEL: Logging verbosity
  • AIAUTOCOMMIT_LOG_PATH: Custom log file path

Writing Good Commit Messages

Some guides to writing good commit messages:

Privacy Disclaimer

gpt-commit uses the OpenAI API to generate commit messages. Both file names and contents from files that contain staged changes will be shared with OpenAI when using gpt-commit. OpenAI will process this data according to their terms of use and API data usage policies. On March 1st 2023 OpenAI pledged that by default, they would not use data submitted by customers via their API to train or improve their models, and that this data will be retained for a maximum of 30 days, after which it will be deleted.

Special Thanks

This project inspired this project. It had a very simple codebase. I've taken the idea and expanded it to include a lot more features, specifically per-project prompt customization.

Related Projects

I looked at a bunch of projects before building this one.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiautocommit-0.14.0.tar.gz (68.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiautocommit-0.14.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file aiautocommit-0.14.0.tar.gz.

File metadata

  • Download URL: aiautocommit-0.14.0.tar.gz
  • Upload date:
  • Size: 68.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for aiautocommit-0.14.0.tar.gz
Algorithm Hash digest
SHA256 24ad94450f88f5d2f9dae3e3fae401cf8cc49da5b21789b044e33b627f427d75
MD5 4d9130ca8c9e6f3edd2745a7a3220aa8
BLAKE2b-256 dbb2168e464869ea3f0d24fa2c0db97044f4239c58ba4b8ff1a04e2054ed326b

See more details on using hashes here.

File details

Details for the file aiautocommit-0.14.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiautocommit-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a24b820a4c17c3498d323ecd0bd147f6f3262417dbae5b0e8bcb51f0f13804e1
MD5 fcb80dfc8a1b156a6d2ae3fe4cb2be2c
BLAKE2b-256 6b02fbeaee742cc93a11525518e9cdaaaac889c0edef858ac00c53d45d9b5a24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page