Add debug version of user_prompt hook
This version logs all activity to /tmp/claude_hooks_debug.log to help diagnose why hooks aren't being called by Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
62
.claude/hooks/user_prompt_debug.sh
Executable file
62
.claude/hooks/user_prompt_debug.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# Debug version of user_prompt.sh with extensive logging
|
||||
|
||||
LOG_FILE="/tmp/claude_hooks_debug.log"
|
||||
exec >> "$LOG_FILE" 2>&1
|
||||
|
||||
echo "=== $(date) - UserPromptSubmit Hook Called ==="
|
||||
|
||||
# Read JSON from stdin
|
||||
INPUT=$(cat)
|
||||
echo "Raw Input: $INPUT"
|
||||
|
||||
# Extract fields using jq
|
||||
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // "unknown"')
|
||||
PROMPT=$(echo "$INPUT" | jq -r '.prompt // .text // ""')
|
||||
PROMPT_LENGTH=${#PROMPT}
|
||||
TIMESTAMP=$(echo "$INPUT" | jq -r '.timestamp // (now | tonumber)')
|
||||
|
||||
echo "Parsed - Session: $SESSION_ID, Prompt Length: $PROMPT_LENGTH"
|
||||
|
||||
# Check config file
|
||||
if [ -f ~/.claude/monitor_url ]; then
|
||||
MONITOR_URL=$(cat ~/.claude/monitor_url)
|
||||
echo "Using config file URL: $MONITOR_URL"
|
||||
else
|
||||
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
||||
echo "Using env/default URL: $MONITOR_URL"
|
||||
fi
|
||||
|
||||
# Build payload
|
||||
PAYLOAD=$(jq -n \
|
||||
--arg session_id "$SESSION_ID" \
|
||||
--arg event_type "UserPromptSubmit" \
|
||||
--arg prompt "$PROMPT" \
|
||||
--arg prompt_length "$PROMPT_LENGTH" \
|
||||
--arg timestamp "$TIMESTAMP" \
|
||||
'{
|
||||
session_id: $session_id,
|
||||
event_type: $event_type,
|
||||
tool_input: $prompt,
|
||||
description: ("User submitted prompt (" + $prompt_length + " chars)"),
|
||||
timestamp: ($timestamp | tonumber)
|
||||
}')
|
||||
|
||||
echo "Payload: $PAYLOAD"
|
||||
echo "Sending to: ${MONITOR_URL}/api/events"
|
||||
|
||||
# Send to backend
|
||||
RESPONSE=$(curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$PAYLOAD" \
|
||||
"${MONITOR_URL}/api/events" \
|
||||
--max-time 2 \
|
||||
--write-out "\nHTTP_CODE:%{http_code}" \
|
||||
--silent \
|
||||
--show-error 2>&1)
|
||||
|
||||
echo "Response: $RESPONSE"
|
||||
echo "=== End ==="
|
||||
echo ""
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user