From f7053eb990edc3ff73d1eea5a88489aee116ae15 Mon Sep 17 00:00:00 2001 From: "felix.zoesch" Date: Tue, 16 Dec 2025 08:21:08 +0100 Subject: [PATCH] Add debug version of user_prompt hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .claude/hooks/user_prompt_debug.sh | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 .claude/hooks/user_prompt_debug.sh diff --git a/.claude/hooks/user_prompt_debug.sh b/.claude/hooks/user_prompt_debug.sh new file mode 100755 index 0000000..13a82c3 --- /dev/null +++ b/.claude/hooks/user_prompt_debug.sh @@ -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