Add NPM distribution support with hybrid installation approach

Major changes:
- Add package.json with NPM packaging configuration
- Create Node.js CLI interface (bin/claude-hooks.js) with full command set
- Convert bash scripts to Python for better npm integration
- Add npm postinstall/preuninstall hooks for automatic setup
- Update bootstrap prompt to recommend NPM method with git fallback
- Enhance README with NPM-first documentation
- Maintain backward compatibility with existing git installation

Features:
- npm install -g claude-hooks for easy distribution
- claude-hooks init/status/test/backup/uninstall commands
- Automatic Python dependency installation
- Conflict detection and prevention
- Hybrid approach supporting both npm and git workflows

This resolves installation complexity while maintaining developer flexibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ryan Malloy 2025-07-19 21:03:13 -06:00
parent 1e169a5d45
commit 9445e09c48
13 changed files with 1055 additions and 107 deletions

View file

@ -1,58 +1,84 @@
# Claude Code Hooks
# Claude Hooks
Intelligent hooks system that makes Claude Code smarter, safer, and more reliable through learning and automation.
Intelligent hooks system for Claude Code that provides command validation, session continuity, and learning capabilities using Claude Code's native hooks architecture.
## What Is This?
Claude Code Hooks transforms your Claude experience by adding:
- **🧠 Learning Intelligence** - Remembers what works in your environment and suggests alternatives for commands that typically fail
- **🛡️ Safety Protection** - Blocks dangerous operations and warns about risky commands before they execute
- **💾 Automatic Backups** - Preserves your work before context limits are reached, with seamless session restoration
- **🔄 Session Continuity** - Maintains context across Claude restarts with detailed session summaries
## Quick Install
## Quick Start
```bash
git clone https://github.com/your-org/claude-hooks.git
cd claude-hooks
./scripts/install.sh
# Install globally via npm
npm install -g claude-hooks
# Initialize hooks
claude-hooks init
# Test installation
claude-hooks test
# Restart Claude Code to activate
```
The installer automatically configures Claude Code. Restart Claude and the hooks will start working immediately.
## Features
## See It in Action
🧠 **Shadow Learning** - Learns from command failures and suggests working alternatives
📊 **Context Monitoring** - Automatically backs up work before context limits
**Smart Validation** - Blocks dangerous commands with intelligent suggestions
🔄 **Session Continuity** - Maintains history and state across Claude restarts
## Usage
After installation, Claude Hooks runs automatically:
- **Command Learning**: Try `pip install requests` → suggests `pip3 install requests`
- **Auto Backup**: Triggers before context limits or manually with `claude-hooks backup`
- **Status Check**: Run `claude-hooks status` to verify installation
- **Manual Test**: Use `claude-hooks test` to verify all components
## Commands
Try a command that often fails:
```bash
pip install requests
claude-hooks init # Initialize after npm install
claude-hooks status # Check installation status
claude-hooks test # Run test suite
claude-hooks backup # Create manual backup
claude-hooks uninstall # Remove hooks configuration
claude-hooks --help # Show all commands
```
With hooks enabled, you'll see:
```
⚠️ Warning: pip commands often fail (confidence: 88%)
💡 Suggestion: Use "pip3 install requests"
## How It Works
Claude Hooks uses Claude Code's native hook system with four key integration points:
- **UserPromptSubmit**: Monitors context usage and triggers backups
- **PreToolUse[Bash]**: Validates commands and suggests alternatives
- **PostToolUse[*]**: Logs activity and learns from patterns
- **Stop**: Finalizes sessions and creates continuation docs
## Installation Methods
### NPM (Recommended)
```bash
npm install -g claude-hooks
claude-hooks init
```
The system learned this pattern from your environment and is preventing you from repeating a known failure.
### Git (Development)
```bash
git clone https://git.supported.systems/rsp2k/claude-hooks.git
cd claude-hooks && ./scripts/install.sh
```
## Documentation
**📚 [Complete Documentation](docs/README.md)** - Organized by your current needs
**🎓 New to Claude Hooks?** → [Tutorial](docs/tutorial/getting-started.md) (30 minutes)
**🛠️ Need to solve a problem?** → [How-To Guides](docs/README.md#-how-to-guides)
**📖 Looking up commands?** → [Reference](docs/README.md#-reference)
**💡 Want to understand how it works?** → [Explanations](docs/README.md#-explanation)
- [Getting Started Tutorial](docs/tutorial/getting-started.md)
- [Architecture Explanation](docs/explanation/architecture.md)
- [How-to Guides](docs/how-to/)
- [Reference Documentation](docs/reference/)
## Requirements
- Python 3.8+
- Claude Code
- Git (optional, for enhanced backup features)
- **Node.js** 16+ (for npm installation)
- **Python** 3.8+ (for hook scripts)
- **Claude Code** (hooks integrate with Claude's native system)
## License