Automatically generate intelligent commit messages using Claude AI. This package installs a git hook that analyzes your code changes and creates descriptive commit messages following conventional commit standards with automatic issue extraction from branch names.
- π€ AI-powered: Uses Claude AI to analyze code changes
- π Conventional commits: Follows standard commit message format
- π― Issue extraction: Automatically extracts issue numbers from branch names
- π Fallback system: Works even when API is unavailable
- π Easy installation: Simple Composer package
- β‘ Fast setup: Automatic installation via Composer scripts
- π No Python dependency: Works with basic Unix tools
Generated messages follow this format:
[ISSUE-123] type: short descriptive title
Detailed description of what changed and why.
Include technical details and impact.
issue: ISSUE-123
Input: Branch feature/CAM-942-implement-auth with authentication code changes
Output:
[CAM-942] feat: implement user authentication system
Add JWT-based authentication with login, logout, and token refresh.
Includes middleware for route protection and session management.
issue: CAM-942
composer require mi-lopez/claude-git-hook --devThe hook will be automatically installed after Composer finishes.
- Clone this repository
- Run the installer:
php src/Installer.php- Visit Anthropic Console
- Create an account or sign in
- Generate an API key
# Use the CLI tool to configure interactively
./vendor/bin/claude-git-hook configureOr set manually:
# Set environment variable
export CLAUDE_API_KEY="your-api-key-here"
# Make it permanent
echo 'export CLAUDE_API_KEY="your-api-key-here"' >> ~/.bashrc
source ~/.bashrcOnce installed and configured, the hook works automatically:
# Make your changes on a branch like: feature/CAM-123-new-feature
git add .
# Commit - message will be generated automatically
git commit
# Result:
# [CAM-123] feat: implement new feature functionality
#
# Add comprehensive feature implementation with proper error handling.
# Includes unit tests and documentation updates.
#
# issue: CAM-123# Check installation status
./vendor/bin/claude-git-hook status
# Reinstall hook
./vendor/bin/claude-git-hook install
# Remove hook
./vendor/bin/claude-git-hook uninstall
# Configure API key
./vendor/bin/claude-git-hook configure
# Debug information
./vendor/bin/claude-git-hook debugThe hook automatically extracts issue numbers from branch names:
- β
feature/CAM-942-implement-authβCAM-942 - β
CAM-942-implement-authβCAM-942 - β
TRIGB2B-42141-fix-loginβTRIGB2B-42141 - β
bugfix/PROJ-123-memory-leakβPROJ-123 - β
feature-branchβ No issue extracted
- Code Analysis: When you run
git commit, the hook captures your staged changes - Branch Analysis: Extracts issue number from current branch name
- AI Processing: Sends the diff to Claude AI for analysis
- Message Generation: Claude generates a structured commit message
- Fallback: If API fails, generates a basic message based on file analysis
The generated messages use conventional commit types:
feat: New featuresfix: Bug fixesdocs: Documentation changesstyle: Code style changesrefactor: Code refactoringtest: Test changeschore: Maintenance tasks
CLAUDE_API_KEY: Your Claude API key (required)
You can modify the hook behavior by editing .git/hooks/prepare-commit-msg directly.
- Git repository
- curl (for API calls)
- Basic Unix tools (grep, sed, tr)
- Claude API key
# Check status
./vendor/bin/claude-git-hook status
# Reinstall
./vendor/bin/claude-git-hook install# Verify API key is set
echo $CLAUDE_API_KEY
# Reconfigure
./vendor/bin/claude-git-hook configure# Fix hook permissions
chmod +x .git/hooks/prepare-commit-msg# Get detailed debug info
./vendor/bin/claude-git-hook debugβββ composer.json # Package configuration
βββ src/
β βββ Installer.php # Installation logic
βββ bin/
β βββ claude-git-hook # CLI command
βββ tests/ # PHPUnit tests
βββ .github/
β βββ workflows/ # GitHub Actions
βββ README.md # Documentation
# Install dev dependencies
composer install
# Run tests
composer test
# Run tests with coverage
composer test-coverage- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run the test suite
- Submit a pull request
This project follows PSR-12 coding standards:
# Check code style
composer cs-check
# Fix code style
composer cs-fixMIT License. See LICENSE file for details.
- π Documentation
- π Issues
- π¬ Discussions
- Initial release
- Basic commit message generation
- Issue extraction from branch names
- Composer package support
- CLI interface
- Fallback system
- No Python dependency
Made with β€οΈ and AI by mi-lopez