ai-usage

TotalClaw 作者 totalclaw

检查 Anthropic 和其他提供商的 AI 使用情况。 使用时: 1. 用户询问AI使用情况、代币使用情况或配额 2. 用户说“我的人工智能使用情况是多少”或“我使用了多少” 3. 用户询问 Anthropic/Claude 的使用或限制 4. 用户询问人工智能的成本或支出 5. 心跳期间监控使用情况(每日检查)

安装 / 下载方式

TotalClaw CLI推荐
totalclaw skills install shop:totalclaw:totalclaw~bshandley-ai-usage
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~bshandley-ai-usage/file -o bshandley-ai-usage.md
## 概述(中文)

检查 Anthropic 和其他提供商的 AI 使用情况。
使用时:
1. 用户询问AI使用情况、代币使用情况或配额
2. 用户说“我的人工智能使用情况是多少”或“我使用了多少”
3. 用户询问 Anthropic/Claude 的使用或限制
4. 用户询问人工智能的成本或支出
5. 心跳期间监控使用情况(每日检查)

## 原文

# AI Usage Check

## Quick Start

```bash
python3 scripts/usage_check.py           # Pretty report with gauges
python3 scripts/usage_check.py --json    # JSON output for scripting
```

## Requirements

- **Python 3.10+** (no pip dependencies — stdlib only)
- **Claude Code** installed and authenticated (`claude` CLI in PATH) — for Anthropic quota
- **OpenClaw** installed — for session log token/cost stats

## What It Shows

**Anthropic (real quota from OAuth API):**
- Weekly utilization % with reset countdown
- 5-hour rolling window %
- Model-specific weekly (Sonnet, Opus) when available
- Extra usage spend vs monthly limit

**Other Providers (from OpenClaw session logs):**
- Token counts and call counts per model
- Auto-detects any provider OpenClaw routes through (Ollama, OpenAI, etc.)

**OpenClaw Anthropic breakdown:**
- Per-model token counts and equivalent API cost

## How It Works

- **Anthropic quota:** `GET https://api.anthropic.com/api/oauth/usage` using Claude Code's OAuth token from `~/.claude/.credentials.json` (requires `user:profile` scope)
- **Token auto-refresh:** If the token is expired, the script automatically refreshes it by invoking `claude --print -p "ok"` (Claude Code refreshes its own OAuth token on any invocation), then re-reads the updated credentials file. If Claude Code isn't installed, Anthropic quota is skipped gracefully.
- **Session stats:** Parses `~/.openclaw/agents/main/sessions/*.jsonl` for per-provider/model token and cost data

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `OPENCLAW_SESSIONS_DIR` | `~/.openclaw/agents/main/sessions` | OpenClaw session log directory |
| `CLAUDE_CREDENTIALS_PATH` | `~/.claude/.credentials.json` | Claude Code credentials file |

## Tips

- Run via **Haiku** or a lightweight model for heartbeat/background checks — the script just needs to execute, no reasoning required
- Use `--json` for programmatic consumption (cron jobs, dashboards, alerts)
- Works with any Anthropic subscription tier (Pro, Max, Team, etc.)