定制 mi-lopez/claude-git-hook 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mi-lopez/claude-git-hook

Composer 安装命令:

composer require mi-lopez/claude-git-hook

包简介

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

README 文档

README

CI Latest Stable Version License PHP Version Require

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

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

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

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

Via Composer (Recommended)

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

The hook will be automatically installed after Composer finishes.

Manual Installation

  1. Clone this repository
  2. Run the installer:
php src/Installer.php

Configuration

1. Get Claude API Key

  1. Visit Anthropic Console
  2. Create an account or sign in
  3. Generate an 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

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

# 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

The hook automatically extracts issue numbers from branch names:

  • feature/CAM-942-implement-authCAM-942
  • CAM-942-implement-authCAM-942
  • TRIGB2B-42141-fix-loginTRIGB2B-42141
  • bugfix/PROJ-123-memory-leakPROJ-123
  • feature-branch → No issue extracted

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

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

Environment Variables

  • CLAUDE_API_KEY: Your Claude API key (required)

Custom Configuration

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

Requirements

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

Troubleshooting

Hook Not Working

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

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

API Key Issues

# Verify API key is set
echo $CLAUDE_API_KEY

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

Permission Issues

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

Debug Information

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

Development

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

# Install dev dependencies
composer install

# Run tests
composer test

# Run tests with coverage
composer test-coverage

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

This project follows PSR-12 coding standards:

# Check code style
composer cs-check

# Fix code style
composer cs-fix

License

MIT License. See LICENSE file for details.

Support

Changelog

v1.0.0

  • 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

mi-lopez/claude-git-hook 适用场景与选型建议

mi-lopez/claude-git-hook 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「git」 「HOOK」 「automation」 「commit」 「ai」 「conventional-commits」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mi-lopez/claude-git-hook 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mi-lopez/claude-git-hook 我们能提供哪些服务?
定制开发 / 二次开发

基于 mi-lopez/claude-git-hook 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-06