Skip to main content

git-commit-msg-ai

AI-powered git commit message generator that follows the Conventional Commits specification.

CI PyPI Python License: MIT Downloads

Prerequisites

  • Python 3.14+

  • An Anthropic API key set as an environment variable:

    export ANTHROPIC_API_KEY=sk-ant-...   # macOS/Linux
    
    [System.Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', 'sk-ant-...', 'User')   # Windows
    

Development Setup

Clone the repository, create a virtual environment, and install the project in editable mode with all dev dependencies:

python -m venv .venv

Activate the virtual environment:

# macOS/Linux
source .venv/bin/activate

# Windows PowerShell
.venv\Scripts\Activate.ps1

Install the project and dev dependencies:

pip install -e ".[dev]"

After activation the git-commit-msg-ai entry-point is on your PATH. You can also run the dev toolchain:

pytest                # run tests with coverage
ruff check .          # lint
ruff format --check . # format check
mypy .                # type-check

Installation

pip install git-commit-msg-ai

Usage

Stage your changes, then run the tool from inside any git repository:

git add <files>
git-commit-msg-ai

The tool will:

  1. Read your staged diff
  2. Generate a commit message using Claude AI
  3. Print the message and prompt you to choose:
[a]ccept / [e]dit / [r]eject / [f]eedback:
  • a - commits immediately with the generated message
  • e - opens the message in your $EDITOR (defaults to notepad on Windows, vi on Linux/macOS), lets you modify it, then commits
  • r - exits without committing
  • f - prompts you for natural-language feedback, regenerates the message incorporating that feedback, and loops back so you can keep refining until satisfied

The tool automatically reads the current branch name and recent commit history and includes them in the request to the AI. This helps the AI match the commit style already established in the project. No configuration is required to enable this; see Configuration to control how many recent commits are included.

Commit message format

Generated messages follow the Conventional Commits specification:

<type>(<optional scope>): <short subject>

- Bullet explaining why this change was made
- Another reason if applicable

For breaking changes, the subject line gets a ! and a footer is added:

feat(api)!: remove deprecated endpoint

- Endpoint was unused and blocking the new auth rollout

BREAKING CHANGE: /v1/legacy is no longer available

Supported types: feat, fix, revert, build, ci, docs, perf, refactor, style, test (configurable — see Configuration)

revert commits always follow this format: the subject line begins with revert: followed by the header of the reverted commit, and the body must contain This reverts commit <hash>.

Configuration

The set of optional commit types the AI may use can be customised through a config file. feat, fix, and revert are always included regardless of any configuration.

Config file locations and precedence

The tool checks the following locations in order, using the first one that defines a given setting:

  1. Project-level — pyproject.toml walked up from the current working directory, under [tool.git-commit-msg-ai]
  2. User-level — ~/.git-commit-msg-ai.toml in your home directory
  3. Built-in defaults — used when neither config file is present or neither defines the setting

Config file formats

Project-level (pyproject.toml):

[tool.git-commit-msg-ai]
types = ["build", "ci", "docs", "perf", "refactor", "style", "test"]
context_commits = 10  # include last 10 commits for context (default: 5)

User-level (~/.git-commit-msg-ai.toml):

types = ["build", "ci", "docs", "chore"]
context_commits = 0  # disable commit context

Setting types = [] restricts the AI to only the three mandatory types (feat, fix, revert).

context_commits controls how many recent commit messages are sent to the AI as context. The default is 5. Set it to 0 to disable context entirely.

Default optional types

Type Purpose
build Changes to the build system or external dependencies
ci Changes to CI configuration files and scripts
docs Documentation-only changes
perf A code change that improves performance
refactor A code change that neither fixes a bug nor adds a feature
style Changes that do not affect the meaning of the code (whitespace, formatting)
test Adding missing tests or correcting existing tests

CI/CD

Every push to main and every pull request runs the full CI pipeline (lint, type-check, tests, build).

Pushing a version tag (e.g. v1.5.2) triggers the CD pipeline:

  1. Tests are re-run as a gate
  2. The tag version is verified to match the version in pyproject.toml
  3. The package is built and published to PyPI
  4. A GitHub Release is created with release notes generated by Claude Sonnet from the commit log

Releasing a new version:

# 1. Bump the version in pyproject.toml
# 2. Commit and push
git add pyproject.toml
git commit -m "chore: bump version to 2.3.0"
git push origin main
# 3. Tag and push - this triggers the CD pipeline
git tag v2.3.0
git push origin v2.3.0

Debugging

When a failure occurs (git error, API error, editor error), the tool always prints an error message to stderr. Diagnostic logs are disabled by default; to enable them, set the GIT_COMMIT_AI_LOG_LEVEL environment variable before running the command. Both error messages and logs are written to stderr and do not interfere with the generated commit message on stdout.

Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL

# macOS/Linux - show all internal diagnostic messages
GIT_COMMIT_AI_LOG_LEVEL=DEBUG git-commit-msg-ai

# Windows PowerShell
$env:GIT_COMMIT_AI_LOG_LEVEL = 'DEBUG'
git-commit-msg-ai
Level What you see
DEBUG git commands run, API model/token params, temp file paths, char counts
INFO commit message generated (with char count), commit created
WARNING no staged changes found
ERROR git not found, API failures, editor errors

License

This project is released under the MIT License.

Metadata

Release files for git-commit-msg-ai 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-commit-msg-ai 2.3.0
File Size Uploaded Provenance Actions
git_commit_msg_ai-2.3.0.tar.gz 21.5 kB With provenance Details for git_commit_msg_ai-2.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for git-commit-msg-ai 2.3.0
File Interpreter ABI Platform Actions
git_commit_msg_ai-2.3.0-py3-none-any.whl Python 3 none any Details for git_commit_msg_ai-2.3.0-py3-none-any.whl

Total release size: 34.2 kB

Release files / git_commit_msg_ai-2.3.0.tar.gz

Download URL git_commit_msg_ai-2.3.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
48f6b2a10dc0d4b6c814433586f8146100765944e507e6617e857813d58770b2
BLAKE2b-256 checksum
How to use checksums
74cdacfd33f31479b60c1dc8ddba80a55f95c46ab46ded0955bd2ea9962d08bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Release files / git_commit_msg_ai-2.3.0-py3-none-any.whl

Download URL git_commit_msg_ai-2.3.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55f03947fbbee1e8653098f92c6a63e4b030368708469f784f1c0eb5545ca3ad
BLAKE2b-256 checksum
How to use checksums
6aa97a5a688aab39cb1d32dbe4a54e50cd151b0a360dfa8663342b375a7dc104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Security for git-commit-msg-ai 2.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for git_commit_msg_ai-2.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page