Hooks now read backend URL from ~/.claude/monitor_url config file, making it easier to configure for remote/VM deployments without relying on environment variables. Priority order: 1. Config file (~/.claude/monitor_url) 2. Environment variable (CLAUDE_MONITOR_URL) 3. Default (http://localhost:8000) This fixes the issue where Claude Code doesn't see environment variables when not started from a configured shell. Usage: echo "http://your-vm:8000" > ~/.claude/monitor_url cp .claude/hooks/*.sh ~/.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>
45 lines
1.2 KiB
Bash
Executable File
45 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Subagent Stop Hook for Claude Code Monitor
|
|
# Captures agent completion events
|
|
|
|
# Read JSON from stdin
|
|
INPUT=$(cat)
|
|
|
|
# Extract fields using jq
|
|
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // "unknown"')
|
|
AGENT_TYPE=$(echo "$INPUT" | jq -r '.agent_type // "unknown"')
|
|
TIMESTAMP=$(echo "$INPUT" | jq -r '.timestamp // (now | tonumber)')
|
|
|
|
# Build payload for backend
|
|
PAYLOAD=$(jq -n \
|
|
--arg session_id "$SESSION_ID" \
|
|
--arg event_type "SubagentStop" \
|
|
--arg agent_type "$AGENT_TYPE" \
|
|
--arg timestamp "$TIMESTAMP" \
|
|
'{
|
|
session_id: $session_id,
|
|
event_type: $event_type,
|
|
description: ("Agent completed: " + $agent_type),
|
|
timestamp: ($timestamp | tonumber)
|
|
}')
|
|
|
|
# Send to backend API (asynchronous, non-blocking)
|
|
# Priority: 1) Config file, 2) Environment variable, 3) Default localhost
|
|
if [ -f ~/.claude/monitor_url ]; then
|
|
MONITOR_URL=$(cat ~/.claude/monitor_url)
|
|
else
|
|
MONITOR_URL="${CLAUDE_MONITOR_URL:-http://localhost:8000}"
|
|
fi
|
|
|
|
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
|