Add config file support for hook backend URL
Hooks now read backend URL from ~/.claude/monitor_url config file, making it easier to configure for remote/VM deployments without relying on environment variables. Priority order: 1. Config file (~/.claude/monitor_url) 2. Environment variable (CLAUDE_MONITOR_URL) 3. Default (http://localhost:8000) This fixes the issue where Claude Code doesn't see environment variables when not started from a configured shell. Usage: echo "http://your-vm:8000" > ~/.claude/monitor_url cp .claude/hooks/*.sh ~/.claude/hooks/ chmod +x ~/.claude/hooks/*.sh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ These hooks capture Claude Code events and send them to the monitoring backend.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Copy hooks to Claude Code directory
|
# Copy hooks to Claude Code directory
|
||||||
cp -r .claude/hooks/* ~/.claude/hooks/
|
cp .claude/hooks/*.sh ~/.claude/hooks/
|
||||||
|
|
||||||
# Make hooks executable
|
# Make hooks executable
|
||||||
chmod +x ~/.claude/hooks/*.sh
|
chmod +x ~/.claude/hooks/*.sh
|
||||||
@@ -18,30 +18,54 @@ The hooks will automatically use `http://localhost:8000` as the backend URL.
|
|||||||
|
|
||||||
### Remote/VM Installation
|
### 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:
|
For remote installations, set the `CLAUDE_MONITOR_URL` environment variable:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
|
# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
|
||||||
export CLAUDE_MONITOR_URL="http://your-vm-ip:8000"
|
export CLAUDE_MONITOR_URL="http://your-vm-ip:8000"
|
||||||
|
|
||||||
# Or for a specific domain
|
# IMPORTANT: Restart terminal or run
|
||||||
export CLAUDE_MONITOR_URL="http://monitor.example.com:8000"
|
source ~/.bashrc
|
||||||
|
|
||||||
# Then copy and enable hooks
|
# Then copy and enable hooks
|
||||||
cp -r .claude/hooks/* ~/.claude/hooks/
|
cp .claude/hooks/*.sh ~/.claude/hooks/
|
||||||
chmod +x ~/.claude/hooks/*.sh
|
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
|
```bash
|
||||||
# For VM with IP 192.168.1.100
|
# Backend on port 8000
|
||||||
export CLAUDE_MONITOR_URL="http://192.168.1.100:8000"
|
echo "http://192.168.1.100:8000" > ~/.claude/monitor_url
|
||||||
|
|
||||||
# Or if backend is exposed via nginx on port 3000
|
# Backend via nginx on port 3000
|
||||||
export CLAUDE_MONITOR_URL="http://192.168.1.100:3000"
|
echo "http://192.168.1.100:3000" > ~/.claude/monitor_url
|
||||||
|
|
||||||
|
# With domain
|
||||||
|
echo "http://monitor.example.com:8000" > ~/.claude/monitor_url
|
||||||
```
|
```
|
||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|||||||
37
.claude/hooks/configure.sh
Normal file
37
.claude/hooks/configure.sh
Normal file
@@ -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"
|
||||||
@@ -33,8 +33,12 @@ PAYLOAD=$(jq -n \
|
|||||||
}')
|
}')
|
||||||
|
|
||||||
# Send to backend API (asynchronous, non-blocking)
|
# Send to backend API (asynchronous, non-blocking)
|
||||||
# Use CLAUDE_MONITOR_URL environment variable or default to localhost
|
# Priority: 1) Config file, 2) Environment variable, 3) Default localhost
|
||||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
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 \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
@@ -27,8 +27,12 @@ PAYLOAD=$(jq -n \
|
|||||||
}')
|
}')
|
||||||
|
|
||||||
# Send to backend API (asynchronous, non-blocking)
|
# Send to backend API (asynchronous, non-blocking)
|
||||||
# Use CLAUDE_MONITOR_URL environment variable or default to localhost
|
# Priority: 1) Environment variable, 2) Config file, 3) Default localhost
|
||||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
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 \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ PAYLOAD=$(jq -n \
|
|||||||
}')
|
}')
|
||||||
|
|
||||||
# Send to backend API (asynchronous, non-blocking)
|
# Send to backend API (asynchronous, non-blocking)
|
||||||
# Use CLAUDE_MONITOR_URL environment variable or default to localhost
|
# Priority: 1) Config file, 2) Environment variable, 3) Default localhost
|
||||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
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 \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ PAYLOAD=$(jq -n \
|
|||||||
}')
|
}')
|
||||||
|
|
||||||
# Send to backend API (asynchronous, non-blocking)
|
# Send to backend API (asynchronous, non-blocking)
|
||||||
# Use CLAUDE_MONITOR_URL environment variable or default to localhost
|
# Priority: 1) Config file, 2) Environment variable, 3) Default localhost
|
||||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
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 \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
@@ -24,8 +24,12 @@ PAYLOAD=$(jq -n \
|
|||||||
}')
|
}')
|
||||||
|
|
||||||
# Send to backend API (asynchronous, non-blocking)
|
# Send to backend API (asynchronous, non-blocking)
|
||||||
# Use CLAUDE_MONITOR_URL environment variable or default to localhost
|
# Priority: 1) Config file, 2) Environment variable, 3) Default localhost
|
||||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
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 \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
@@ -27,8 +27,12 @@ PAYLOAD=$(jq -n \
|
|||||||
}')
|
}')
|
||||||
|
|
||||||
# Send to backend API (asynchronous, non-blocking)
|
# Send to backend API (asynchronous, non-blocking)
|
||||||
# Use CLAUDE_MONITOR_URL environment variable or default to localhost
|
# Priority: 1) Config file, 2) Environment variable, 3) Default localhost
|
||||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
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 \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|||||||
Reference in New Issue
Block a user