Shell
#!/bin/bash
# Track Claude Code tool usage to id8labs API
# This hook fires after tool calls and increments the usage counter
# Configuration
API_URL="https://id8labs.app/api/claude-stats"
API_KEY_FILE="$HOME/.claude/.id8labs-api-key"
# Get tool name from hook context
# Claude hooks pass tool info via environment or stdin
TOOL_INPUT=$(cat)
TOOL_NAME="${CLAUDE_TOOL_NAME:-}"
# If tool name not in env, try to extract from input
if [ -z "$TOOL_NAME" ]; then
# Try to get from hook arguments
TOOL_NAME="$1"
fi
# Map tool names to our tracked categories
case "$TOOL_NAME" in
Bash|bash)
TOOL="bash"
;;
Read|read)
TOOL="read"
;;
Edit|edit)
TOOL="edit"
;;
Write|write)
TOOL="write"
;;
*)
# Unknown tool, skip tracking
exit 0
;;
esac
# Check if API key exists
if [ ! -f "$API_KEY_FILE" ]; then
# Silently skip if no API key configured
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 "{\"tool\": \"$TOOL\", \"increment\": 1}" \
> /dev/null 2>&1 &
# Always exit success to not block Claude
exit 0