Skip to main content

AI generated commit messages

Project description

Release Notes Downloads GitHub CI Status License: MIT

Generate Commit Messages With 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:

  • Ability to easily customize prompts on a per-repo basis
  • Smart exclusions (e.g., lock files) that still generate useful messages without bloating the AI prompt
  • Optional difftastic integration for syntax-aware diffs that improve message quality
  • Support for multiple AI providers via pydantic-ai, with Google Gemini as the default

Installation

uvx aiautocommit

Note: OpenAI, Anthropic, and Gemini (Google) are supported by default. To install all providers supported by Pydantic AI, use pip install "aiautocommit[all-providers]".

Features

  • Generates conventional commit messages
  • Customizable prompts and exclusions
  • Pre-commit hook integration
  • Supports custom config directories
  • CLI flag for version checking (--version)
  • Does not generate a commit during a merge or reversion (when an existing autogen'd msg exists)
  • Automatic lock file handling: recognizable lock files (e.g., uv.lock, package-lock.json) generate specific conventional messages (e.g., chore(deps): update uv.lock) even when they are excluded from the AI prompt.
  • Optional difftastic integration for syntax-aware semantic diffs

Getting Started

Set your API key (works for any provider, Google Gemini is the default):

export AIAUTOCOMMIT_AI_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

Automatic Lock File Handling

Lock files (like uv.lock, package-lock.json, Gemfile.lock, etc.) are frequently updated but don't provide much context for an AI-generated message. By default, these are excluded from the AI prompt to save tokens and improve quality.

However, if you stage only lock files, aiautocommit will detect them and automatically generate a conventional commit message:

  • uv.lock -> chore(deps): update uv.lock
  • package-lock.json -> chore(deps): update package-lock.json
  • .terraform.lock.hcl -> chore(deps): update .terraform.lock.hcl
  • Mixed lock files -> chore(deps): update lock files

If any non-lock files are staged alongside them, the AI will ignore the lock files (based on your exclusions) and focus on the meaningful code changes.

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_PATH=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:

  • commit_prompt.txt: Template for generating commit messages
  • excluded_files.txt: List of files or glob patterns (e.g., mise*lock) 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
        AIAUTOCOMMIT_LOG_LEVEL: info
      skip:
        merge:
        rebase:
        # only run this if the tool exists
        run: ! which aiautocommit > /dev/null

Environment Variables

All environment variables used by aiautocommit or its providers can be prefixed with AIAUTOCOMMIT_ to take precedence over the standard variable.

  • AIAUTOCOMMIT_AI_KEY: Universal API key. aiautocommit internally maps this to the correct provider-specific variable (e.g., GOOGLE_API_KEY, OPENAI_API_KEY) based on your active model.
  • AIAUTOCOMMIT_MODEL: AI model to use, in provider:model format (default: gemini:gemini-3-flash-preview). Examples: anthropic:claude-3-5-sonnet-latest, openai:gpt-4o.
  • AIAUTOCOMMIT_CONFIG: Custom config directory path
  • AIAUTOCOMMIT_DIFFTASTIC: Enable difftastic for syntax-aware diffs (set to "1", "true", or "yes")
  • AIAUTOCOMMIT_LOG_LEVEL: Logging verbosity
  • AIAUTOCOMMIT_LOG_PATH: Custom log file path

Ensure you have the corresponding API key set in AIAUTOCOMMIT_AI_KEY.

Model Configuration

aiautocommit uses pydantic-ai under the hood, supporting a wide range of providers including OpenAI, Anthropic, and Gemini (via VertexAI or Generative AI) by default. You can specify the model using the provider:model syntax in the AIAUTOCOMMIT_MODEL environment variable.

Google Gemini models use "thinking" (Chain of Thought) with a minimal budget to improve accuracy.

Common examples:

  • gemini:gemini-3-flash-preview (default)
  • openai:gpt-4o
  • anthropic:claude-3-5-sonnet-latest
  • gemini:gemini-1.5-pro
  • ollama:llama3 (for local models)

Ensure you have the corresponding API key set in your environment (e.g., ANTHROPIC_API_KEY for Anthropic models).

Writing Good Commit Messages

Some guides to writing good commit messages:

Credits

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.


This project was created from iloveitaly/python-package-template

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.17.0.tar.gz (17.9 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.17.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiautocommit-0.17.0.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiautocommit-0.17.0.tar.gz
Algorithm Hash digest
SHA256 6b52a2af8493b4bb49d8442bc10c86b334f73da2ba89ff86e8a0a2d6ada2e6fd
MD5 03a14897a73a34c21eb102c99353c8db
BLAKE2b-256 2f37fde34bb878b60f1bdee0bb0f60d03d47f197e4ac9bead304a85c8b5cd0df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiautocommit-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiautocommit-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cec80cf560e171a320ac2e0bfa38cc4ba5f93c9466644a10f6eb241ead7fbdd8
MD5 6fa9e1d3f813a72b798e575ea5c35421
BLAKE2b-256 e4bd0cee2e69f1469f27d2ea2fed28b399fc0bb55e31af00bdb8227ccf17241c

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