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

@ -10,103 +10,94 @@ YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
CLAUDE_CONFIG_DIR="$HOME/.config/claude"
HOOKS_CONFIG_FILE="$CLAUDE_CONFIG_DIR/hooks.json"
CLAUDE_HOOKS_CMD="$HOME/.local/bin/claude-hooks"
echo -e "${BLUE}Claude Code Hooks Uninstallation${NC}"
echo "===================================="
# Warn user about data loss
echo -e "${YELLOW}WARNING:${NC} This will remove:"
echo "- Hook configuration from Claude Code"
echo "- All learned patterns and session data"
echo "- Backup files (if in project directory)"
# Check if hooks are installed
if [ ! -f "$HOOKS_CONFIG_FILE" ] && [ ! -f "$CLAUDE_HOOKS_CMD" ]; then
echo -e "${YELLOW}No Claude Hooks installation found${NC}"
echo "Nothing to uninstall."
exit 0
fi
echo -e "${YELLOW}This will remove Claude Hooks from your system:${NC}"
echo "- Remove hooks configuration: $HOOKS_CONFIG_FILE"
echo "- Remove claude-hooks command: $CLAUDE_HOOKS_CMD"
echo "- Preserve hook data and backups"
echo ""
read -p "Are you sure you want to continue? (y/N): " -n 1 -r
read -p "Continue with uninstallation? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Uninstallation cancelled."
exit 0
fi
# Remove hooks from Claude settings
# Remove hooks configuration
echo -n "Removing hooks configuration... "
if [ -f "$HOOKS_CONFIG_FILE" ]; then
rm -f "$HOOKS_CONFIG_FILE"
echo -e "${GREEN}SUCCESS${NC}"
else
echo -e "${YELLOW}Not found${NC}"
fi
# Remove claude-hooks command
echo -n "Removing claude-hooks command... "
if [ -f "$CLAUDE_HOOKS_CMD" ]; then
rm -f "$CLAUDE_HOOKS_CMD"
echo -e "${GREEN}SUCCESS${NC}"
else
echo -e "${YELLOW}Not found${NC}"
fi
# Remove from Claude settings if it exists
if [ -f "$HOME/.config/claude/settings.json" ]; then
echo -n "Removing hooks from Claude settings... "
# Backup settings
cp "$HOME/.config/claude/settings.json" "$HOME/.config/claude/settings.json.backup"
# Remove hooks configuration
python3 << 'EOF'
if grep -q "hooks" "$HOME/.config/claude/settings.json" 2>/dev/null; then
# Backup settings
cp "$HOME/.config/claude/settings.json" "$HOME/.config/claude/settings.json.backup"
# Remove hooks from settings
python3 << EOF
import json
import sys
import os
try:
with open('/home/usr/.config/claude/settings.json', 'r') as f:
settings_path = os.path.expanduser('~/.config/claude/settings.json')
with open(settings_path, 'r') as f:
settings = json.load(f)
# Remove hooks section
# Remove hooks key if it exists
if 'hooks' in settings:
del settings['hooks']
with open('/home/usr/.config/claude/settings.json', 'w') as f:
with open(settings_path, 'w') as f:
json.dump(settings, f, indent=2)
print("SUCCESS")
else:
print("NO HOOKS FOUND")
print("Not found in settings")
except Exception as e:
print(f"ERROR: {e}")
sys.exit(1)
EOF
echo -e "${GREEN}Hooks removed from Claude settings${NC}"
else
echo -e "${YELLOW}No Claude settings file found${NC}"
fi
# Remove hooks configuration file
if [ -f "$HOOKS_CONFIG_FILE" ]; then
echo -n "Removing hooks configuration file... "
rm -f "$HOOKS_CONFIG_FILE"
echo -e "${GREEN}SUCCESS${NC}"
fi
# Ask about removing data
echo ""
read -p "Remove learned patterns and session data? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -n "Removing hook data... "
rm -rf ".claude_hooks"
rm -f "LAST_SESSION.md" "ACTIVE_TODOS.md" "RECOVERY_GUIDE.md"
echo -e "${GREEN}SUCCESS${NC}"
fi
# Ask about removing project files
echo ""
read -p "Remove project files (hooks, scripts, etc.)? This cannot be undone! (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
CLAUDE_HOOKS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
echo -n "Removing project files... "
cd ..
rm -rf "$CLAUDE_HOOKS_DIR"
echo -e "${GREEN}SUCCESS${NC}"
echo ""
echo -e "${GREEN}Complete uninstallation finished!${NC}"
echo "All files have been removed."
else
echo ""
echo -e "${GREEN}Partial uninstallation finished!${NC}"
echo "Hooks disabled, but project files remain."
echo -e "${GREEN}SUCCESS${NC}"
else
echo -e "${YELLOW}Not found in settings${NC}"
fi
fi
echo ""
echo -e "${BLUE}Post-uninstallation:${NC}"
echo "1. Restart Claude Code to ensure hooks are disabled"
echo "2. Check that no hook-related errors appear"
echo "3. Your backup files (if any) remain in git history"
echo -e "${GREEN}Uninstallation Complete!${NC}"
echo ""
echo -e "${GREEN}Claude Code Hooks successfully removed.${NC}"
echo -e "${BLUE}Next Steps:${NC}"
echo "1. Restart Claude Code to deactivate hooks"
echo "2. Hook data and backups are preserved in case you reinstall"
echo ""
echo -e "${YELLOW}Note:${NC} To completely remove all data, delete the claude-hooks directory manually"