diff --git a/.claude/hooks/README.md b/.claude/hooks/README.md index 0e2f940..bd06cfe 100644 --- a/.claude/hooks/README.md +++ b/.claude/hooks/README.md @@ -8,7 +8,7 @@ These hooks capture Claude Code events and send them to the monitoring backend. ```bash # Copy hooks to Claude Code directory -cp -r .claude/hooks/* ~/.claude/hooks/ +cp .claude/hooks/*.sh ~/.claude/hooks/ # Make hooks executable chmod +x ~/.claude/hooks/*.sh @@ -18,30 +18,54 @@ The hooks will automatically use `http://localhost:8000` as the backend URL. ### Remote/VM Installation +**Method 1: Config File (Recommended)** + +Create a config file with your backend URL: + +```bash +# Set backend URL in config file +echo "http://your-vm-ip:8000" > ~/.claude/monitor_url + +# Or for specific domain +echo "http://monitor.example.com:8000" > ~/.claude/monitor_url + +# Copy and enable hooks +cp .claude/hooks/*.sh ~/.claude/hooks/ +chmod +x ~/.claude/hooks/*.sh +``` + +**Method 2: Environment Variable** + For remote installations, set the `CLAUDE_MONITOR_URL` environment variable: ```bash # Add to your shell profile (~/.bashrc, ~/.zshrc, etc.) export CLAUDE_MONITOR_URL="http://your-vm-ip:8000" -# Or for a specific domain -export CLAUDE_MONITOR_URL="http://monitor.example.com:8000" +# IMPORTANT: Restart terminal or run +source ~/.bashrc # Then copy and enable hooks -cp -r .claude/hooks/* ~/.claude/hooks/ +cp .claude/hooks/*.sh ~/.claude/hooks/ chmod +x ~/.claude/hooks/*.sh ``` -### Docker Deployment with Port 3000 +**Priority Order:** +1. Config file (`~/.claude/monitor_url`) - highest priority +2. Environment variable (`CLAUDE_MONITOR_URL`) +3. Default (`http://localhost:8000`) -If you're running the monitor with Docker (frontend on port 3000), use: +### Docker Deployment Examples ```bash -# For VM with IP 192.168.1.100 -export CLAUDE_MONITOR_URL="http://192.168.1.100:8000" +# Backend on port 8000 +echo "http://192.168.1.100:8000" > ~/.claude/monitor_url -# Or if backend is exposed via nginx on port 3000 -export CLAUDE_MONITOR_URL="http://192.168.1.100:3000" +# Backend via nginx on port 3000 +echo "http://192.168.1.100:3000" > ~/.claude/monitor_url + +# With domain +echo "http://monitor.example.com:8000" > ~/.claude/monitor_url ``` ## Verification diff --git a/.claude/hooks/configure.sh b/.claude/hooks/configure.sh new file mode 100644 index 0000000..fd7f11d --- /dev/null +++ b/.claude/hooks/configure.sh @@ -0,0 +1,37 @@ +#!/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" diff --git a/.claude/hooks/post_tool_use.sh b/.claude/hooks/post_tool_use.sh index a875e63..84861f6 100755 --- a/.claude/hooks/post_tool_use.sh +++ b/.claude/hooks/post_tool_use.sh @@ -33,8 +33,12 @@ PAYLOAD=$(jq -n \ }') # Send to backend API (asynchronous, non-blocking) -# Use CLAUDE_MONITOR_URL environment variable or default to localhost -MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +# Priority: 1) Config file, 2) Environment variable, 3) Default localhost +if [ -f ~/.claude/monitor_url ]; then + MONITOR_URL=$(cat ~/.claude/monitor_url) +else + MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +fi curl -X POST \ -H "Content-Type: application/json" \ diff --git a/.claude/hooks/pre_tool_use.sh b/.claude/hooks/pre_tool_use.sh index 8f76c2a..a3fc326 100755 --- a/.claude/hooks/pre_tool_use.sh +++ b/.claude/hooks/pre_tool_use.sh @@ -27,8 +27,12 @@ PAYLOAD=$(jq -n \ }') # Send to backend API (asynchronous, non-blocking) -# Use CLAUDE_MONITOR_URL environment variable or default to localhost -MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +# Priority: 1) Environment variable, 2) Config file, 3) Default localhost +if [ -f ~/.claude/monitor_url ]; then + MONITOR_URL=$(cat ~/.claude/monitor_url) +else + MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +fi curl -X POST \ -H "Content-Type: application/json" \ diff --git a/.claude/hooks/session_end.sh b/.claude/hooks/session_end.sh index 638c090..a43c796 100755 --- a/.claude/hooks/session_end.sh +++ b/.claude/hooks/session_end.sh @@ -21,8 +21,12 @@ PAYLOAD=$(jq -n \ }') # Send to backend API (asynchronous, non-blocking) -# Use CLAUDE_MONITOR_URL environment variable or default to localhost -MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +# Priority: 1) Config file, 2) Environment variable, 3) Default localhost +if [ -f ~/.claude/monitor_url ]; then + MONITOR_URL=$(cat ~/.claude/monitor_url) +else + MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +fi curl -X POST \ -H "Content-Type: application/json" \ diff --git a/.claude/hooks/session_start.sh b/.claude/hooks/session_start.sh index 86cae6a..6139bb1 100755 --- a/.claude/hooks/session_start.sh +++ b/.claude/hooks/session_start.sh @@ -21,8 +21,12 @@ PAYLOAD=$(jq -n \ }') # Send to backend API (asynchronous, non-blocking) -# Use CLAUDE_MONITOR_URL environment variable or default to localhost -MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +# Priority: 1) Config file, 2) Environment variable, 3) Default localhost +if [ -f ~/.claude/monitor_url ]; then + MONITOR_URL=$(cat ~/.claude/monitor_url) +else + MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +fi curl -X POST \ -H "Content-Type: application/json" \ diff --git a/.claude/hooks/subagent_stop.sh b/.claude/hooks/subagent_stop.sh index 8ee1d65..c7685f4 100755 --- a/.claude/hooks/subagent_stop.sh +++ b/.claude/hooks/subagent_stop.sh @@ -24,8 +24,12 @@ PAYLOAD=$(jq -n \ }') # Send to backend API (asynchronous, non-blocking) -# Use CLAUDE_MONITOR_URL environment variable or default to localhost -MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +# Priority: 1) Config file, 2) Environment variable, 3) Default localhost +if [ -f ~/.claude/monitor_url ]; then + MONITOR_URL=$(cat ~/.claude/monitor_url) +else + MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +fi curl -X POST \ -H "Content-Type: application/json" \ diff --git a/.claude/hooks/user_prompt.sh b/.claude/hooks/user_prompt.sh index fea8ede..7e40ed5 100755 --- a/.claude/hooks/user_prompt.sh +++ b/.claude/hooks/user_prompt.sh @@ -27,8 +27,12 @@ PAYLOAD=$(jq -n \ }') # Send to backend API (asynchronous, non-blocking) -# Use CLAUDE_MONITOR_URL environment variable or default to localhost -MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +# Priority: 1) Config file, 2) Environment variable, 3) Default localhost +if [ -f ~/.claude/monitor_url ]; then + MONITOR_URL=$(cat ~/.claude/monitor_url) +else + MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}" +fi curl -X POST \ -H "Content-Type: application/json" \