Claude Code Analytics Burn Statusline
Claude Code statusline that reads Anthropic Claude Code Analytics Admin API data and shows daily estimated cost, hourly pace, sessions, and budget pressure.
Open the source and read safety notes before installing.
Safety notes
- Claude Code Analytics data is daily aggregated and can lag recent activity, so the burn-rate display is a pacing signal rather than real-time billing control.
- Keep the refresh interval moderate because the statusline calls an authenticated Admin API endpoint.
- Treat budget thresholds as operational prompts; reconcile invoices and Console reports before making spending decisions.
Privacy notes
- The script sends an Admin API request to Anthropic and receives organization-level Claude Code analytics.
- It prints aggregate cost, session, and budget numbers, not email addresses, model names, prompts, file paths, or code.
- Admin API keys can expose organization analytics; store them in a scoped local secret manager or shell environment with restricted access.
- The script feeds the API key to curl through a config file descriptor instead of command-line arguments and unsets the exported key before launching curl, reducing process-list exposure on shared machines.
Prerequisites
- Anthropic Admin API access for an organization with Claude Code Analytics enabled.
- ANTHROPIC_ADMIN_API_KEY set in the statusline environment; prefer a narrowly scoped/read-only credential if Anthropic offers one for analytics access.
- curl and jq available on the machine running the Claude Code statusline command.
- Optional CLAUDE_CODE_ANALYTICS_EMAIL to limit the display to one user and CLAUDE_CODE_DAILY_BUDGET_USD to set the budget denominator.
Schema details
- Install type
- config
- Troubleshooting
- No
- Script language
- bash
Script body
#!/usr/bin/env bash
set -u
main() {
if [ -z "${ANTHROPIC_ADMIN_API_KEY:-}" ]; then
echo "cc analytics: admin key missing"
exit 0
fi
if ! command -v curl >/dev/null 2>&1; then
echo "cc analytics: curl missing"
exit 0
fi
if ! command -v jq >/dev/null 2>&1; then
echo "cc analytics: jq missing"
exit 0
fi
day="${CLAUDE_CODE_ANALYTICS_DAY:-$(date -u +%F)}"
limit="${CLAUDE_CODE_ANALYTICS_LIMIT:-1000}"
email="${CLAUDE_CODE_ANALYTICS_EMAIL:-}"
budget="${CLAUDE_CODE_DAILY_BUDGET_USD:-50}"
url="https://api.anthropic.com/v1/organizations/usage_report/claude_code?starting_at=${day}&limit=${limit}"
api_key="$ANTHROPIC_ADMIN_API_KEY"
unset ANTHROPIC_ADMIN_API_KEY
json=$(ANTHROPIC_ADMIN_API_KEY= curl -fsS \
--config <(printf '%s\n' \
'header = "anthropic-version: 2023-06-01"' \
"header = \"x-api-key: ${api_key}\"" \
'header = "User-Agent: heyclaude-statusline/1.0"') \
"$url" 2>/dev/null || true)
unset api_key
if [ -z "$json" ]; then
echo "cc analytics: unavailable"
exit 0
fi
if [ -n "$email" ]; then
cents=$(printf '%s' "$json" | jq --arg email "$email" '[.data[]? | select(.actor.email_address == $email) | .model_breakdown[]?.estimated_cost.amount // 0] | add // 0' 2>/dev/null || echo 0)
sessions=$(printf '%s' "$json" | jq --arg email "$email" '[.data[]? | select(.actor.email_address == $email) | .core_metrics.num_sessions // 0] | add // 0' 2>/dev/null || echo 0)
scope="user"
else
cents=$(printf '%s' "$json" | jq '[.data[]? | .model_breakdown[]?.estimated_cost.amount // 0] | add // 0' 2>/dev/null || echo 0)
sessions=$(printf '%s' "$json" | jq '[.data[]? | .core_metrics.num_sessions // 0] | add // 0' 2>/dev/null || echo 0)
scope="org"
fi
cost=$(awk -v cents="$cents" 'BEGIN { printf "%.2f", cents / 100 }')
hour=$(date -u +%H)
minute=$(date -u +%M)
elapsed_minutes=$((10#$hour * 60 + 10#$minute + 1))
burn=$(awk -v cost="$cost" -v minutes="$elapsed_minutes" 'BEGIN { printf "%.2f", cost * 60 / minutes }')
pct=$(awk -v cost="$cost" -v budget="$budget" 'BEGIN { if (budget > 0) printf "%.0f", cost * 100 / budget; else print 0 }')
if [ "$pct" -ge 90 ]; then
state="limit"
elif [ "$pct" -ge 70 ]; then
state="watch"
else
state="ok"
fi
printf 'cc analytics: %s | $%s today | burn $%s/h | sessions %s | budget %s%% | %s\n' "$scope" "$cost" "$burn" "$sessions" "$pct" "$state"
}
case $- in
*n*) ;;
*) main "$@" ;;
esacFull copyable content
{
"statusLine": {
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/statuslines/claude-code-analytics-burn-statusline.sh"
}
}About this resource
Source notes
- Anthropic documents the Claude Code Analytics Admin API for daily aggregated Claude Code usage, productivity metrics, token data, and estimated cost by model.
- The API is explicitly daily aggregated rather than real time, so this statusline reports budget pace from the latest available daily analytics instead of claiming live billing precision.
Duplicate check
Checked existing statuslines, live HeyClaude statuslines, open pull requests, and repository content for claude-code-analytics-burn-statusline, Claude Code Analytics, Claude cost, burn rate, real-time-cost-tracker, and burn-rate-monitor. Existing cost entries use local statusline JSON estimates; this entry uses Anthropic's Claude Code Analytics Admin API with an organization/user reporting scope and a different canonical source.
Disclosure
Editorial statusline recipe. No paid placement or affiliate link is used.
Source citations
Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.