#!/bin/bash # Configure Claude Code Monitor hooks with custom backend URL set -e # Get backend URL from user or use localhost read -p "Enter backend URL (default: http://localhost:8000): " BACKEND_URL BACKEND_URL=${BACKEND_URL:-http://localhost:8000} echo "Configuring hooks to use: $BACKEND_URL" # Create temporary directory TEMP_DIR=$(mktemp -d) trap "rm -rf $TEMP_DIR" EXIT # Copy hooks to temp directory cp *.sh "$TEMP_DIR/" # Update each hook with the configured URL for hook in "$TEMP_DIR"/*.sh; do if [ -f "$hook" ] && [ "$(basename "$hook")" != "configure.sh" ]; then # Replace the MONITOR_URL line with hardcoded URL sed -i.bak "s|MONITOR_URL=\"\${CLAUDE_MONITOR_URL:-http://localhost:8000}\"|MONITOR_URL=\"$BACKEND_URL\"|g" "$hook" rm -f "${hook}.bak" fi done # Install to ~/.claude/hooks/ mkdir -p ~/.claude/hooks cp "$TEMP_DIR"/*.sh ~/.claude/hooks/ chmod +x ~/.claude/hooks/*.sh echo "✓ Hooks installed and configured successfully!" echo "✓ Backend URL: $BACKEND_URL" echo "" echo "Test with:" echo " echo '{\"session_id\":\"test\",\"timestamp\":1234567890}' | ~/.claude/hooks/session_start.sh"