PHPackages                             mi-lopez/claude-git-hook - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mi-lopez/claude-git-hook

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mi-lopez/claude-git-hook
========================

Git hook that uses Claude AI to automatically generate commit messages with issue extraction

v1.0.0(11mo ago)112MITPHPPHP &gt;=7.4CI passing

Since Jun 6Pushed 11mo agoCompare

[ Source](https://github.com/mi-lopez/claude-git-hook)[ Packagist](https://packagist.org/packages/mi-lopez/claude-git-hook)[ Docs](https://github.com/mi-lopez/claude-git-hook)[ RSS](/packages/mi-lopez-claude-git-hook/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Claude Git Hook
===============

[](#claude-git-hook)

[![CI](https://github.com/mi-lopez/claude-git-hook/workflows/CI/badge.svg)](https://github.com/mi-lopez/claude-git-hook/actions)[![Latest Stable Version](https://camo.githubusercontent.com/7e6a007ff782f4953966883882207621f997cf7f0a5e6aabb0989f1b278f07c3/68747470733a2f2f706f7365722e707567782e6f72672f6d692d6c6f70657a2f636c617564652d6769742d686f6f6b2f76)](https://packagist.org/packages/mi-lopez/claude-git-hook)[![License](https://camo.githubusercontent.com/4bdbab4527145560dc274a383f36c8f1142090571c5ac67586c8d0a53f3f1831/68747470733a2f2f706f7365722e707567782e6f72672f6d692d6c6f70657a2f636c617564652d6769742d686f6f6b2f6c6963656e7365)](https://packagist.org/packages/mi-lopez/claude-git-hook)[![PHP Version Require](https://camo.githubusercontent.com/367291d2bccefdef3b8bab4054f44ef2bb239888a05127fa2e2d75afc5f279cd/68747470733a2f2f706f7365722e707567782e6f72672f6d692d6c6f70657a2f636c617564652d6769742d686f6f6b2f726571756972652f706870)](https://packagist.org/packages/mi-lopez/claude-git-hook)

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.

Features
--------

[](#features)

- 🤖 **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

Commit Message Format
---------------------

[](#commit-message-format)

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

```

### Examples

[](#examples)

**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

```

Installation
------------

[](#installation)

### Via Composer (Recommended)

[](#via-composer-recommended)

```
composer require mi-lopez/claude-git-hook --dev
```

The hook will be automatically installed after Composer finishes.

### Manual Installation

[](#manual-installation)

1. Clone this repository
2. Run the installer:

```
php src/Installer.php
```

Configuration
-------------

[](#configuration)

### 1. Get Claude API Key

[](#1-get-claude-api-key)

1. Visit [Anthropic Console](https://console.anthropic.com/)
2. Create an account or sign in
3. Generate an API key

### 2. Configure API Key

[](#2-configure-api-key)

```
# Use the CLI tool to configure interactively
./vendor/bin/claude-git-hook configure
```

Or 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 ~/.bashrc
```

Usage
-----

[](#usage)

Once 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
```

### Manual Commands

[](#manual-commands)

```
# 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 debug
```

Branch Name Patterns
--------------------

[](#branch-name-patterns)

The 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

How It Works
------------

[](#how-it-works)

1. **Code Analysis**: When you run `git commit`, the hook captures your staged changes
2. **Branch Analysis**: Extracts issue number from current branch name
3. **AI Processing**: Sends the diff to Claude AI for analysis
4. **Message Generation**: Claude generates a structured commit message
5. **Fallback**: If API fails, generates a basic message based on file analysis

Commit Message Types
--------------------

[](#commit-message-types)

The generated messages use conventional commit types:

- `feat`: New features
- `fix`: Bug fixes
- `docs`: Documentation changes
- `style`: Code style changes
- `refactor`: Code refactoring
- `test`: Test changes
- `chore`: Maintenance tasks

Configuration Options
---------------------

[](#configuration-options)

### Environment Variables

[](#environment-variables)

- `CLAUDE_API_KEY`: Your Claude API key (required)

### Custom Configuration

[](#custom-configuration)

You can modify the hook behavior by editing `.git/hooks/prepare-commit-msg` directly.

Requirements
------------

[](#requirements)

- Git repository
- curl (for API calls)
- Basic Unix tools (grep, sed, tr)
- Claude API key

Troubleshooting
---------------

[](#troubleshooting)

### Hook Not Working

[](#hook-not-working)

```
# Check status
./vendor/bin/claude-git-hook status

# Reinstall
./vendor/bin/claude-git-hook install
```

### API Key Issues

[](#api-key-issues)

```
# Verify API key is set
echo $CLAUDE_API_KEY

# Reconfigure
./vendor/bin/claude-git-hook configure
```

### Permission Issues

[](#permission-issues)

```
# Fix hook permissions
chmod +x .git/hooks/prepare-commit-msg
```

### Debug Information

[](#debug-information)

```
# Get detailed debug info
./vendor/bin/claude-git-hook debug
```

Development
-----------

[](#development)

### Project Structure

[](#project-structure)

```
├── 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

```

### Running Tests

[](#running-tests)

```
# Install dev dependencies
composer install

# Run tests
composer test

# Run tests with coverage
composer test-coverage
```

### Contributing

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Run the test suite
6. Submit a pull request

### Code Style

[](#code-style)

This project follows PSR-12 coding standards:

```
# Check code style
composer cs-check

# Fix code style
composer cs-fix
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

- 📖 [Documentation](https://github.com/mi-lopez/claude-git-hook/wiki)
- 🐛 [Issues](https://github.com/mi-lopez/claude-git-hook/issues)
- 💬 [Discussions](https://github.com/mi-lopez/claude-git-hook/discussions)

Changelog
---------

[](#changelog)

### v1.0.0

[](#v100)

- 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](https://github.com/mi-lopez)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance54

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

336d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/955cdd3d991a7262d20e0526bf87e07f040eb5ea81b6df6b16ddb502574d6a3f?d=identicon)[mi-lopez](/maintainers/mi-lopez)

---

Top Contributors

[![mi-lopez](https://avatars.githubusercontent.com/u/15022191?v=4)](https://github.com/mi-lopez "mi-lopez (3 commits)")

---

Tags

automationaigitHOOKcommitclaudeconventional-commits

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mi-lopez-claude-git-hook/health.svg)

```
[![Health](https://phpackages.com/badges/mi-lopez-claude-git-hook/health.svg)](https://phpackages.com/packages/mi-lopez-claude-git-hook)
```

###  Alternatives

[ramsey/conventional-commits

A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook action!

1931.2M120](/packages/ramsey-conventional-commits)[marcocesarato/php-conventional-changelog

Generate changelogs and release notes from a project's commit messages and metadata and automate versioning with semver.org and conventionalcommits.org

2511.3M107](/packages/marcocesarato-php-conventional-changelog)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[bruli/php-git-hooks

Git hooks for PHP projects.

675370.8k5](/packages/bruli-php-git-hooks)[mischasigtermans/laravel-altitude

Claude Code agents for the TALL stack, powered by Laravel Boost

1139.2k](/packages/mischasigtermans-laravel-altitude)[amphibee/laravel-pint-pre-commit

Laravel Pint pre-commit hook allow you to analyse your code with the awesome Laravel Pint.

1943.9k](/packages/amphibee-laravel-pint-pre-commit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
