Shell
#!/bin/bash
# Track Claude Code agent usage to id8labs API
# Fires after Task tool calls to track which agents are spawned
# Configuration
API_URL="https://id8labs.app/api/claude-stats"
API_KEY_FILE="$HOME/.claude/.id8labs-api-key"
# Get hook input
HOOK_INPUT=$(cat)
# Extract agent type from Task tool parameters
# Task tool passes subagent_type in the parameters
AGENT_TYPE=$(echo "$HOOK_INPUT" | jq -r '.tool_input.subagent_type // empty' 2>/dev/null)
# Skip if no agent type found
if [ -z "$AGENT_TYPE" ]; then
exit 0
fi
# Normalize agent name (lowercase, replace colons with dashes)
AGENT_NAME=$(echo "$AGENT_TYPE" | tr '[:upper:]' '[:lower:]' | tr ':' '-')
# Check if API key exists
if [ ! -f "$API_KEY_FILE" ]; then
exit 0
fi
API_KEY=$(cat "$API_KEY_FILE")
# Send increment request to API (background, non-blocking)
curl -s -X POST "$API_URL" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d "{\"type\": \"agent\", \"name\": \"$AGENT_NAME\", \"increment\": 1}" \
> /dev/null 2>&1 &
exit 0