From 8b35d95e9b3d7ea2bd1fb09eaff2b3202ea66700 Mon Sep 17 00:00:00 2001 From: "felix.zoesch" Date: Mon, 15 Dec 2025 16:16:43 +0100 Subject: [PATCH] Make hooks configurable for remote/VM deployments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All hooks now use CLAUDE_MONITOR_URL environment variable to allow configuration for remote deployments. Defaults to http://localhost:8000 for local development. Changes: - All hooks now read CLAUDE_MONITOR_URL from environment - Added README.md with installation instructions for local and remote setups - Includes troubleshooting guide for common issues Usage: export CLAUDE_MONITOR_URL="http://vm-ip:8000" cp -r .claude/hooks/* ~/.claude/hooks/ chmod +x ~/.claude/hooks/*.sh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .claude/hooks/README.md | 97 ++++++++++++++++++++++++++++++++++ .claude/hooks/post_tool_use.sh | 5 +- .claude/hooks/pre_tool_use.sh | 5 +- .claude/hooks/session_end.sh | 5 +- .claude/hooks/session_start.sh | 5 +- .claude/hooks/subagent_stop.sh | 5 +- .claude/hooks/user_prompt.sh | 5 +- 7 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 .claude/hooks/README.md diff --git a/.claude/hooks/README.md b/.claude/hooks/README.md new file mode 100644 index 0000000..0e2f940 --- /dev/null +++ b/.claude/hooks/README.md @@ -0,0 +1,97 @@ +# Claude Code Monitor Hooks + +These hooks capture Claude Code events and send them to the monitoring backend. + +## Installation + +### Local Installation (localhost) + +```bash +# Copy hooks to Claude Code directory +cp -r .claude/hooks/* ~/.claude/hooks/ + +# Make hooks executable +chmod +x ~/.claude/hooks/*.sh +``` + +The hooks will automatically use `http://localhost:8000` as the backend URL. + +### Remote/VM Installation + +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" + +# Then copy and enable hooks +cp -r .claude/hooks/* ~/.claude/hooks/ +chmod +x ~/.claude/hooks/*.sh +``` + +### Docker Deployment with Port 3000 + +If you're running the monitor with Docker (frontend on port 3000), use: + +```bash +# For VM with IP 192.168.1.100 +export CLAUDE_MONITOR_URL="http://192.168.1.100:8000" + +# Or if backend is exposed via nginx on port 3000 +export CLAUDE_MONITOR_URL="http://192.168.1.100:3000" +``` + +## Verification + +Test if hooks are working: + +```bash +# Check if environment variable is set +echo $CLAUDE_MONITOR_URL + +# Manually test a hook +echo '{"session_id":"test","timestamp":1234567890}' | ~/.claude/hooks/session_start.sh + +# Check backend logs for the test event +curl http://your-backend:8000/api/events | jq +``` + +## Available Hooks + +- `pre_tool_use.sh` - Before tool execution +- `post_tool_use.sh` - After tool execution +- `user_prompt.sh` - When user submits a prompt +- `session_start.sh` - Session initialization +- `session_end.sh` - Session termination +- `subagent_stop.sh` - Agent completion + +## Troubleshooting + +### No events appearing in dashboard + +1. Check if `CLAUDE_MONITOR_URL` is set correctly: + ```bash + echo $CLAUDE_MONITOR_URL + ``` + +2. Verify backend is reachable: + ```bash + curl $CLAUDE_MONITOR_URL/health + ``` + +3. Check hook permissions: + ```bash + ls -la ~/.claude/hooks/*.sh + ``` + +4. Test hook manually: + ```bash + echo '{"session_id":"test","timestamp":1234567890}' | ~/.claude/hooks/session_start.sh + ``` + +### Events only work locally + +Make sure to set `CLAUDE_MONITOR_URL` in your shell profile and restart your terminal. diff --git a/.claude/hooks/post_tool_use.sh b/.claude/hooks/post_tool_use.sh index 1a7401f..a875e63 100755 --- a/.claude/hooks/post_tool_use.sh +++ b/.claude/hooks/post_tool_use.sh @@ -33,10 +33,13 @@ 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}" + curl -X POST \ -H "Content-Type: application/json" \ -d "$PAYLOAD" \ - http://localhost:8000/api/events \ + "${MONITOR_URL}/api/events" \ --max-time 2 \ --silent \ --show-error \ diff --git a/.claude/hooks/pre_tool_use.sh b/.claude/hooks/pre_tool_use.sh index eb87fed..8f76c2a 100755 --- a/.claude/hooks/pre_tool_use.sh +++ b/.claude/hooks/pre_tool_use.sh @@ -27,10 +27,13 @@ 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}" + curl -X POST \ -H "Content-Type: application/json" \ -d "$PAYLOAD" \ - http://localhost:8000/api/events \ + "${MONITOR_URL}/api/events" \ --max-time 2 \ --silent \ --show-error \ diff --git a/.claude/hooks/session_end.sh b/.claude/hooks/session_end.sh index 44511bc..638c090 100755 --- a/.claude/hooks/session_end.sh +++ b/.claude/hooks/session_end.sh @@ -21,10 +21,13 @@ 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}" + curl -X POST \ -H "Content-Type: application/json" \ -d "$PAYLOAD" \ - http://localhost:8000/api/events \ + "${MONITOR_URL}/api/events" \ --max-time 2 \ --silent \ --show-error \ diff --git a/.claude/hooks/session_start.sh b/.claude/hooks/session_start.sh index 1119a5d..86cae6a 100755 --- a/.claude/hooks/session_start.sh +++ b/.claude/hooks/session_start.sh @@ -21,10 +21,13 @@ 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}" + curl -X POST \ -H "Content-Type: application/json" \ -d "$PAYLOAD" \ - http://localhost:8000/api/events \ + "${MONITOR_URL}/api/events" \ --max-time 2 \ --silent \ --show-error \ diff --git a/.claude/hooks/subagent_stop.sh b/.claude/hooks/subagent_stop.sh index 0400ca7..8ee1d65 100755 --- a/.claude/hooks/subagent_stop.sh +++ b/.claude/hooks/subagent_stop.sh @@ -24,10 +24,13 @@ 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}" + curl -X POST \ -H "Content-Type: application/json" \ -d "$PAYLOAD" \ - http://localhost:8000/api/events \ + "${MONITOR_URL}/api/events" \ --max-time 2 \ --silent \ --show-error \ diff --git a/.claude/hooks/user_prompt.sh b/.claude/hooks/user_prompt.sh index 2a07e33..fea8ede 100755 --- a/.claude/hooks/user_prompt.sh +++ b/.claude/hooks/user_prompt.sh @@ -27,10 +27,13 @@ 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}" + curl -X POST \ -H "Content-Type: application/json" \ -d "$PAYLOAD" \ - http://localhost:8000/api/events \ + "${MONITOR_URL}/api/events" \ --max-time 2 \ --silent \ --show-error \