#!/usr/bin/env bash # compliance-pull.sh · telemetry/compliance-pull.sh # QRefAI AI Coding Field Guide, Part 2 (Q2.9) # # PIPELINE 2 of 2. The Compliance API covers the Claude PLATFORM activity feed — # identity, configuration, chat activity — via GET /v1/compliance/activities, with # 180-day retention on Anthropic's side. Schedule this DAILY pull into your own # warehouse for long-term retention. # # ⚠ GOTCHA: this API does NOT cover Claude Code prompt/tool-use content. That's # what the OpenTelemetry pipeline (telemetry/otel.env) is for. You need BOTH. # # This is a STUB — wire auth, pagination, and your warehouse load to your stack. # Run from cron / a scheduled job once per day. set -euo pipefail : "${ANTHROPIC_ADMIN_KEY:?set ANTHROPIC_ADMIN_KEY in the environment}" WAREHOUSE_DIR="${WAREHOUSE_DIR:-/var/acme/compliance}" API="https://api.anthropic.com/v1/compliance/activities" # Pull yesterday's window (adjust to your retention/cron cadence). since="$(date -u -d 'yesterday 00:00' +%Y-%m-%dT%H:%M:%SZ)" until_="$(date -u -d 'today 00:00' +%Y-%m-%dT%H:%M:%SZ)" outfile="${WAREHOUSE_DIR}/activities-$(date -u +%Y-%m-%d).jsonl" mkdir -p "$WAREHOUSE_DIR" # NOTE: real implementation must paginate through all pages (cursor/next_page). # This stub fetches the first page only to show the shape. curl -sS -X GET "${API}?start_time=${since}&end_time=${until_}" \ -H "x-api-key: ${ANTHROPIC_ADMIN_KEY}" \ -H "anthropic-version: 2023-06-01" \ | tee "$outfile" >/dev/null echo "Wrote $(wc -l < "$outfile") activity records to $outfile" echo "TODO: paginate, then load $outfile into your warehouse and correlate with" echo " OTel logs on user identity (user_id / agent_session_id)."