Skip to content
Shell
1014 B
Raw Blame
#!/bin/bash
# Track Claude Code skill/command usage to id8labs API
# Fires after Skill tool calls to track which slash commands are invoked

# Configuration
API_URL="https://id8labs.app/api/claude-stats"
API_KEY_FILE="$HOME/.claude/.id8labs-api-key"

# Get hook input
HOOK_INPUT=$(cat)

# Extract skill name from Skill tool parameters
SKILL_NAME=$(echo "$HOOK_INPUT" | jq -r '.tool_input.skill // empty' 2>/dev/null)

# Skip if no skill name found
if [ -z "$SKILL_NAME" ]; then
  exit 0
fi

# Normalize skill name (lowercase, remove prefixes like plugin:)
SKILL_NAME=$(echo "$SKILL_NAME" | sed 's/^.*://' | tr '[:upper:]' '[:lower:]')

# 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\": \"skill\", \"name\": \"$SKILL_NAME\", \"increment\": 1}" \
  > /dev/null 2>&1 &

exit 0