AI Commit Message Generator is a powerful command-line tool that uses Claude AI to automatically generate well-structured and meaningful Git commit messages based on your staged code changes.
- Uses Claude AI (e.g., Claude 3.7 Sonnet) to analyze your staged
git diff - Generates commit messages with:
- A concise summary line
- Detailed bullet points of changes
- Supports flexible configuration using
.envfiles or environment variables - Offers helpful CLI flags like
--dry,--edit, and--out - Allows excluding specific file patterns (e.g.,
*.log,dist/*) from the diff using theGITM_EXCLUDE_PATTERNSenvironment variable - Automatically copies the message to your clipboard
- Provides consistent, high-quality commit messages across your project
Implement user authentication and improve error handling
- Add user login and registration functionality
- Implement JWT-based authentication system
- Create middleware for protected routes
- Enhance error handling in API endpoints
- Update user model with password hashing
- Add input validation for user-related operationsMake sure the following are installed on your system:
- Git
- Bash
curljqpbcopy(on macOS) or adjust clipboard logic for your OS- A Claude API key from Anthropic
-
Clone this repository:
git clone https://github.com/ayyazzafar/ai-commit-message-generator.git
-
Move the
gitmscript to a directory in yourPATH(e.g.,~/bin/):sudo mv ai-commit-message-generator/gitm /usr/local/bin/ sudo chmod +x /usr/local/bin/gitm
-
Create a config file at
~/.config/gitm/.envand add your API key and preferences:CLAUDE_API_KEY=sk-your-api-key-here CLAUDE_MODEL=claude-3-7-sonnet CLAUDE_VERSION=2023-06-01 # Optional: Space-separated list of patterns to exclude from the diff # GITM_EXCLUDE_PATTERNS="*.log build/* temp/**/*.tmp"
π Do not store secrets in public/shared folders like
~/bin.
-
Stage your changes with
git add:git add . -
Run the generator:
gitm
-
Then commit using the generated message:
git commit -m "$(pbpaste)"
| Flag | Description | Default |
|---|---|---|
--dry |
Show message preview without copying or committing | Not set (proceeds to copy/save) |
--edit |
Open message in your default editor before using it | Not set (does not open in editor) |
--out=message.txt |
Save message to a file instead of clipboard | Not set (copies to clipboard) |
--env=/path/to/.env |
Load environment config from custom path | $HOME/.config/gitm/.env (or GITM_ENV_FILE) |
--include-lock-files |
Include package-lock.json and pnpm-lock.yaml files in commit message generation |
Not set (lock files excluded) |
--help |
Display usage instructions | Not set (proceeds with generation) |
You can customize the tool using:
-
A default
.envfile:~/.config/gitm/.env
-
The
GITM_ENV_FILEenvironment variable:export GITM_ENV_FILE=/secure/location/my.envYou can also set other environment variables like
CLAUDE_MODEL,CLAUDE_VERSION, orGITM_EXCLUDE_PATTERNSin a similar way, or within your shell's configuration file (e.g.,.zshrc,.bashrc).Example for
GITM_EXCLUDE_PATTERNS:export GITM_EXCLUDE_PATTERNS="*.log build/* docs/**/*.md"
-
Or directly with
--envat runtime:gitm --env=/secure/location/my.env
- Captures staged changes using `