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

@ -18,6 +18,24 @@ HOOKS_CONFIG_FILE="$CLAUDE_CONFIG_DIR/hooks.json"
echo -e "${BLUE}Claude Code Hooks Installation${NC}"
echo "=================================="
# Check for existing installation
echo -n "Checking for existing Claude Hooks installation... "
if [ -f "$HOOKS_CONFIG_FILE" ] || command -v claude-hooks >/dev/null 2>&1; then
echo -e "${RED}CONFLICT DETECTED${NC}"
echo ""
echo -e "${YELLOW}⚠️ Claude Hooks is already installed!${NC}"
echo " This would create conflicts since hooks are user-wide."
echo ""
echo -e "${BLUE}To proceed:${NC}"
echo "1. Uninstall existing hooks: claude-hooks uninstall"
echo "2. Or manually remove: rm -rf ~/.config/claude/hooks.json ~/.local/bin/claude-hooks"
echo "3. Then run this installer again"
echo ""
exit 1
else
echo -e "${GREEN}No conflicts found${NC}"
fi
# Check Python version
echo -n "Checking Python version... "
if ! python3 --version >/dev/null 2>&1; then
@ -67,6 +85,70 @@ echo -n "Creating runtime directories... "
mkdir -p "$CLAUDE_HOOKS_DIR/.claude_hooks/"{backups,logs,patterns}
echo -e "${GREEN}SUCCESS${NC}"
# Create claude-hooks command
echo -n "Creating claude-hooks command... "
mkdir -p "$HOME/.local/bin"
cat > "$HOME/.local/bin/claude-hooks" << 'EOF'
#!/bin/bash
# Claude Hooks Command Line Interface
CLAUDE_HOOKS_DIR="$(dirname "$(readlink -f "$0")")/../.."
if [ ! -d "$CLAUDE_HOOKS_DIR/claude-hooks" ]; then
# Fallback: look for installation in common locations
for dir in "/opt/claude-hooks" "$HOME/claude-hooks" "$HOME/.local/share/claude-hooks"; do
if [ -d "$dir" ]; then
CLAUDE_HOOKS_DIR="$dir"
break
fi
done
fi
case "$1" in
"status")
echo "Claude Hooks Status:"
if [ -f "$HOME/.config/claude/hooks.json" ]; then
echo "✓ Hooks configuration installed"
else
echo "✗ No hooks configuration found"
fi
if command -v python3 >/dev/null 2>&1; then
echo "✓ Python 3 available"
else
echo "✗ Python 3 not found"
fi
;;
"uninstall")
if [ -f "$CLAUDE_HOOKS_DIR/claude-hooks/scripts/uninstall.sh" ]; then
exec "$CLAUDE_HOOKS_DIR/claude-hooks/scripts/uninstall.sh"
else
echo "Error: Uninstall script not found"
echo "Manual removal: rm -rf ~/.config/claude/hooks.json ~/.local/bin/claude-hooks"
exit 1
fi
;;
"test")
if [ -f "$CLAUDE_HOOKS_DIR/claude-hooks/scripts/test.sh" ]; then
exec "$CLAUDE_HOOKS_DIR/claude-hooks/scripts/test.sh"
else
echo "Error: Test script not found"
exit 1
fi
;;
*)
echo "Claude Hooks CLI"
echo "Usage: claude-hooks {status|uninstall|test}"
echo ""
echo "Commands:"
echo " status - Show installation status"
echo " uninstall - Remove Claude Hooks"
echo " test - Run hook tests"
;;
esac
EOF
chmod +x "$HOME/.local/bin/claude-hooks"
echo -e "${GREEN}SUCCESS${NC}"
# Test hook scripts
echo -n "Testing hook scripts... "
if python3 "$CLAUDE_HOOKS_DIR/hooks/context_monitor.py" <<< '{"prompt": "test"}' >/dev/null 2>&1; then