Add diagnostic tools for hook debugging
Added two helper scripts: - debug_hook.sh: Logs hook calls and connectivity tests - diagnose.sh: Comprehensive diagnostic tool for troubleshooting The diagnose script checks: - Config file existence and content - Backend connectivity - Hook installation and permissions - Manual hook testing - settings.json configuration - Debug logs Usage: bash .claude/hooks/diagnose.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:
31
.claude/hooks/debug_hook.sh
Executable file
31
.claude/hooks/debug_hook.sh
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Debug hook to verify hooks are being called
|
||||||
|
|
||||||
|
LOG_FILE="/tmp/claude_monitor_debug.log"
|
||||||
|
|
||||||
|
# Log timestamp and hook name
|
||||||
|
echo "=== $(date) ===" >> "$LOG_FILE"
|
||||||
|
echo "Hook called from: ${BASH_SOURCE[0]}" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Read input
|
||||||
|
INPUT=$(cat)
|
||||||
|
echo "Input received: $INPUT" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Check config file
|
||||||
|
if [ -f ~/.claude/monitor_url ]; then
|
||||||
|
MONITOR_URL=$(cat ~/.claude/monitor_url)
|
||||||
|
echo "Config file found: $MONITOR_URL" >> "$LOG_FILE"
|
||||||
|
else
|
||||||
|
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
||||||
|
echo "Using env/default: $MONITOR_URL" >> "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test backend connectivity
|
||||||
|
echo "Testing connectivity to: $MONITOR_URL/health" >> "$LOG_FILE"
|
||||||
|
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" --connect-timeout 2 "$MONITOR_URL/health" 2>&1)
|
||||||
|
echo "Response: $RESPONSE" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
echo "" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Pass through to actual hook if this is being tested
|
||||||
|
exit 0
|
||||||
112
.claude/hooks/diagnose.sh
Executable file
112
.claude/hooks/diagnose.sh
Executable file
@@ -0,0 +1,112 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Diagnostic script for Claude Code Monitor hooks
|
||||||
|
|
||||||
|
echo "=== Claude Code Monitor - Diagnostics ==="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 1. Check config file
|
||||||
|
echo "1. Checking config file..."
|
||||||
|
if [ -f ~/.claude/monitor_url ]; then
|
||||||
|
MONITOR_URL=$(cat ~/.claude/monitor_url)
|
||||||
|
echo " ✓ Config file exists: ~/.claude/monitor_url"
|
||||||
|
echo " URL: $MONITOR_URL"
|
||||||
|
else
|
||||||
|
echo " ✗ Config file not found: ~/.claude/monitor_url"
|
||||||
|
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
||||||
|
echo " Using: $MONITOR_URL (env/default)"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 2. Check backend connectivity
|
||||||
|
echo "2. Testing backend connectivity..."
|
||||||
|
if curl -s --connect-timeout 3 "$MONITOR_URL/health" > /dev/null 2>&1; then
|
||||||
|
echo " ✓ Backend is reachable at $MONITOR_URL"
|
||||||
|
HEALTH=$(curl -s "$MONITOR_URL/health")
|
||||||
|
echo " Response: $HEALTH"
|
||||||
|
else
|
||||||
|
echo " ✗ Backend is NOT reachable at $MONITOR_URL"
|
||||||
|
echo " Make sure Docker is running and backend is accessible"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 3. Check hooks installation
|
||||||
|
echo "3. Checking hooks installation..."
|
||||||
|
HOOKS_DIR="$HOME/.claude/hooks"
|
||||||
|
if [ -d "$HOOKS_DIR" ]; then
|
||||||
|
echo " ✓ Hooks directory exists: $HOOKS_DIR"
|
||||||
|
echo " Installed hooks:"
|
||||||
|
ls -lh "$HOOKS_DIR"/*.sh 2>/dev/null | awk '{print " " $9 " (" $1 ")"}'
|
||||||
|
else
|
||||||
|
echo " ✗ Hooks directory not found: $HOOKS_DIR"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 4. Check hooks are executable
|
||||||
|
echo "4. Checking hook permissions..."
|
||||||
|
for hook in "$HOOKS_DIR"/*.sh; do
|
||||||
|
if [ -f "$hook" ]; then
|
||||||
|
if [ -x "$hook" ]; then
|
||||||
|
echo " ✓ $(basename $hook) is executable"
|
||||||
|
else
|
||||||
|
echo " ✗ $(basename $hook) is NOT executable"
|
||||||
|
echo " Run: chmod +x $hook"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 5. Test a hook manually
|
||||||
|
echo "5. Testing session_start hook manually..."
|
||||||
|
if [ -f "$HOOKS_DIR/session_start.sh" ]; then
|
||||||
|
TEST_INPUT='{"session_id":"diagnostic-test","timestamp":1234567890}'
|
||||||
|
echo " Sending test event: $TEST_INPUT"
|
||||||
|
echo "$TEST_INPUT" | "$HOOKS_DIR/session_start.sh"
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# Check if event was received
|
||||||
|
echo " Checking if event was received by backend..."
|
||||||
|
EVENTS=$(curl -s "$MONITOR_URL/api/events?page=1&page_size=5" 2>/dev/null)
|
||||||
|
if echo "$EVENTS" | grep -q "diagnostic-test"; then
|
||||||
|
echo " ✓ Test event received by backend!"
|
||||||
|
else
|
||||||
|
echo " ✗ Test event NOT found in backend"
|
||||||
|
echo " Recent events:"
|
||||||
|
echo "$EVENTS" | jq '.events[0:2]' 2>/dev/null || echo "$EVENTS"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " ✗ session_start.sh not found"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 6. Check settings.json
|
||||||
|
echo "6. Checking Claude Code settings.json..."
|
||||||
|
if [ -f ~/.claude/settings.json ]; then
|
||||||
|
echo " ✓ settings.json exists"
|
||||||
|
echo " Configured hooks:"
|
||||||
|
cat ~/.claude/settings.json | jq -r '.hooks | keys[]' 2>/dev/null | sed 's/^/ /'
|
||||||
|
else
|
||||||
|
echo " ✗ settings.json not found"
|
||||||
|
echo " You need to configure hooks in ~/.claude/settings.json"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 7. Check debug log
|
||||||
|
echo "7. Checking debug log..."
|
||||||
|
if [ -f /tmp/claude_monitor_debug.log ]; then
|
||||||
|
echo " ✓ Debug log exists: /tmp/claude_monitor_debug.log"
|
||||||
|
echo " Last 10 lines:"
|
||||||
|
tail -10 /tmp/claude_monitor_debug.log | sed 's/^/ /'
|
||||||
|
else
|
||||||
|
echo " ✗ No debug log found (this is normal if debug hook wasn't used)"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== Diagnostics Complete ==="
|
||||||
|
echo ""
|
||||||
|
echo "Next steps:"
|
||||||
|
echo "1. If backend is not reachable, check Docker: docker-compose ps"
|
||||||
|
echo "2. If hooks are not executable, run: chmod +x ~/.claude/hooks/*.sh"
|
||||||
|
echo "3. If manual test works but Claude Code doesn't send events:"
|
||||||
|
echo " - Make sure Claude Code is using the correct settings.json"
|
||||||
|
echo " - Try restarting Claude Code"
|
||||||
|
echo " - Check if hooks are being called by adding debug output"
|
||||||
Reference in New Issue
Block a user