claude-hooks-setup
v1.0.1
Published
Automatically setup Claude Code hooks and settings configuration
Readme
Claude Hooks Setup
🚀 Automatically setup Claude Code with intelligent git hooks and configuration for seamless AI-powered development workflow.
✨ Features
- Intelligent Commit Messages: Automatically generates git commit messages from your Claude assistant interactions
- Zero Configuration: One command setup - finds your
.claudedirectory automatically - Cross-Platform: Works on macOS, Windows, and Linux
- Smart Text Processing: Cleans up commit messages by removing unnecessary punctuation and formatting
- Git Integration: Only commits when there are actual changes and you're in a git repository
- Safe Operations: Includes safeguards to prevent commit loops and errors
🚀 Quick Start
Installation
npm install -g claude-hooks-setupSetup
claude-hooks-setupThat's it! The tool will:
- 🔍 Find your Claude Code configuration directory
- 📝 Create/update the stop hook for automatic commits
- ⚙️ Configure your
settings.jsonwith recommended settings - ✅ Validate the setup
📋 How It Works
Automatic Commit Messages
When you finish an interaction with Claude Code, the hook will:
- Extract the last assistant message from your session
- Clean the text by removing unnecessary formatting (stars, extra commas, etc.)
- Generate a commit message with format:
feat: [cleaned message content] - Commit your changes automatically (only if you're in a git repo with changes)
Example
If Claude's last message was:
已优化 `testBasicSetters` 方法,**主要改进包括:**
1. **配置化测试数据** - 使用 `testConfig` 对象集中管理测试参数
2. **详细日志记录** - 每个设置操作都有独立的成功日志The generated commit message will be:
feat: 已优化 testBasicSetters 方法,主要改进包括: 1. 配置化测试数据 - 使用 testConfig 对象集中管理测试参数 2. 详细日志记录 - 每个设置操作都有独立的成功日志🔧 Configuration
The tool automatically configures your Claude Code settings.json with:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "node ~/.claude/hooks/auto-commit-hook.js"
}
]
}
]
},
"editor": {
"auto_save": true,
"format_on_save": true
},
"git": {
"auto_commit": true,
"commit_on_stop": true
},
"ui": {
"show_token_count": true,
"confirm_before_exit": false
},
"logging": {
"level": "info",
"enable_hooks_logging": true
}
}📁 Directory Structure
After setup, your .claude directory will look like:
~/.claude/
├── settings.json # Claude Code configuration
├── hooks/
│ └── auto-commit-hook.js # Auto-commit hook
└── ... (other Claude files)🛠️ Manual Configuration
If you prefer manual setup or need to customize:
Find Your Claude Directory
The tool searches for .claude in these locations:
macOS:
~/.claude~/Library/Application Support/Claude~/Library/Application Support/claude
Windows:
%APPDATA%\\Claude%APPDATA%\\claude%LOCALAPPDATA%\\Claude%LOCALAPPDATA%\\claude
Linux:
~/.claude~/.config/claude~/.local/share/claude
Environment Variable
Set CLAUDE_CONFIG_PATH to specify a custom location:
export CLAUDE_CONFIG_PATH=/path/to/your/claude/config
claude-hooks-setup🔄 Upgrading
To update to the latest version:
npm update -g claude-hooks-setup
claude-hooks-setup # Re-run to update hooks🚫 Disabling
To temporarily disable auto-commits, edit your settings.json:
{
"hooks": {
"Stop": []
}
}Or remove the specific hook object from the Stop array.
🐛 Troubleshooting
Hook Not Triggering
- Check Claude Code restart: Restart Claude Code after setup
- Verify settings: Ensure
settings.jsonhas the correct hook path - Check permissions: Ensure the hook file is executable (Unix systems)
Commit Issues
- Git repository: The hook only works in git repositories
- Git configuration: Ensure git user name/email are configured
- File changes: The hook only commits when there are actual changes
Directory Not Found
- Manual path: Use
CLAUDE_CONFIG_PATHenvironment variable - Create manually: Create
~/.claudedirectory if needed - Permissions: Ensure you have write access to the directory
📝 CLI Options
claude-hooks-setup --help # Show help
claude-hooks-setup --version # Show version🤝 Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Development Setup
git clone https://github.com/xzj-abc/claude-hooks-setup.git
cd claude-hooks-setup
npm install
npm link # For local testing📄 License
MIT License - see LICENSE file for details.
🔗 Related
Made with ❤️ for the Claude Code community
