Files
claude-code-monitor/.claude/hooks/pre_tool_use.sh
felix.zoesch 8b35d95e9b Make hooks configurable for remote/VM deployments
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 <noreply@anthropic.com>
2025-12-15 16:16:43 +01:00

44 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Pre Tool Use Hook for Claude Code Monitor
# Captures tool preparation events before execution
# Read JSON from stdin
INPUT=$(cat)
# Extract fields using jq
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // "unknown"')
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // null')
TOOL_INPUT=$(echo "$INPUT" | jq -c '.tool_input // {}')
TIMESTAMP=$(echo "$INPUT" | jq -r '.timestamp // (now | tonumber)')
# Build payload for backend
PAYLOAD=$(jq -n \
--arg session_id "$SESSION_ID" \
--arg event_type "PreToolUse" \
--arg tool_name "$TOOL_NAME" \
--argjson tool_input "$TOOL_INPUT" \
--arg timestamp "$TIMESTAMP" \
'{
session_id: $session_id,
event_type: $event_type,
tool_name: $tool_name,
tool_input: $tool_input,
timestamp: ($timestamp | tonumber)
}')
# 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" \
"${MONITOR_URL}/api/events" \
--max-time 2 \
--silent \
--show-error \
> /dev/null 2>&1 &
# Exit immediately (don't wait for curl)
exit 0