CommitGPT is a tool that generates commit messages using Claude, an AI model by Anthropic. It aims to improve the consistency and quality of git commit messages by integrating AI assistance into the development workflow.
- Go 1.x
- Git
- Pandoc
- libsecret (for storing the API key securely)
If you have Nix installed, you can build and install CommitGPT using the following commands:
nix-build
nix-env -i ./resultThis will build the project and install the binary in your Nix profile. The binary is wrapped in a shell script that sets up the necessary environment variables, so you can use it directly as a prepare-commit-msg git-hook (see Usage).
To install CommitGPT using Go, follow these steps:
-
Clone the repository:
git clone https://github.com/au-phiware/commitgpt.git cd commitgpt -
Build the project:
go build -o commitgpt
-
Install the binary:
go install
Before using CommitGPT, you need to set up your Anthropic API key:
-
Store your API key securely using
secret-tool:secret-tool store --label="Anthropic API Key" anthropic-api-key commitgpt -
Create a directory for logs:
mkdir -p ~/.config/anthropic/logs
To use CommitGPT as a Git hook for preparing commit messages:
-
Create a file named
prepare-commit-msgin your Git repository's.git/hooks/directory with the following content:#!/bin/sh export ANTHROPIC_API_KEY=$(secret-tool lookup anthropic-api-key commitgpt) export ANTHROPIC_LOG_DIR=~/.config/anthropic/logs commitgpt $1 $2 $3
-
Make the hook executable:
chmod +x .git/hooks/prepare-commit-msg
Now, when you make a commit, CommitGPT will automatically generate a commit message based on your changes.
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
This project uses the Claude API by Anthropic to generate commit messages.
The metaprompting technique used in this project is based on the Metaprompt Workbook by Anthropic. You can find the workbook here: Metaprompt Workbook. We highly recommend checking it out to understand the underlying methodology of our commit message generation process.