Install
openclaw skills install token-usage-optimizerMaximize your Claude Code subscription value with smart usage monitoring and burn rate optimization. Track 5-hour session and 7-day weekly quotas, get one-ti...
openclaw skills install token-usage-optimizerVersion: 1.0.5
Get the most out of your Claude Code subscription by monitoring usage in real-time and optimizing your daily burn rate.
You're paying $20-200/month for Claude Code. Are you:
This skill tracks your 5-hour session and 7-day weekly quotas, calculates your daily burn rate, and tells you if you should use more or throttle back.
Run the setup wizard to configure your OAuth tokens:
cd {baseDir}
./scripts/setup.sh
You'll need:
sk-ant-oat01-...)sk-ant-ort01-...)See references/token-extraction.md for how to get these.
./scripts/check-usage.sh
Output:
SESSION=22.0
WEEKLY=49.0
BURN_RATE=OK
CACHED_AT=1771583780
./scripts/report.sh
Output:
📊 Claude Code Daily Check:
⏱️ SESSION (5h): 22%
📅 WEEKLY (7d): 49%
⚪ На темпі — оптимальне використання
| Plan | Monthly | Weekly Budget | Daily Budget |
|---|---|---|---|
| Pro | $20 | ~14% | ~2% |
| Max 100 | $100 | ~14% | ~2% |
| Max 200 | $200 | ~14% | ~2% |
(7-day window resets weekly, so ~14% per day = 100% per week)
Add to your HEARTBEAT.md:
### Evening Check (18:00-20:00)
- Claude Code usage: `/path/to/token-usage-optimizer/scripts/report.sh`
Alerts use state tracking (/tmp/claude-usage-alert-state) to avoid spam.
Default: /tmp/claude-usage.cache with 10-minute TTL.
Override:
CACHE_FILE=/custom/path CACHE_TTL=300 ./scripts/check-usage.sh
scripts/setup.sh — Initial token configurationscripts/check-usage.sh — Core usage checker (cached, burn rate calc)scripts/report.sh — Human-readable daily reportreferences/api-endpoint.md — Anthropic OAuth API docsreferences/token-extraction.md — How to get OAuth tokensreferences/plans.md — Claude Code subscription tiersGET https://api.anthropic.com/api/oauth/usage
Authorization: Bearer <access-token>
anthropic-beta: oauth-2025-04-20
Response:
{
"five_hour": {
"utilization": 22.0,
"resets_at": "2026-02-20T14:00:00.364238+00:00"
},
"seven_day": {
"utilization": 49.0,
"resets_at": "2026-02-24T10:00:01.364256+00:00"
}
}
curl — API requestsdate — Timestamp parsinggrep, cut, printf — Text parsingNo external dependencies (jq, etc.).
Tokens are stored in {baseDir}/.tokens (gitignored).
Never share your access/refresh tokens.
OAuth tokens work for ~1 week, then need manual refresh. Set up 30-minute health check for better reliability:
# Add cron job to check token health every 30 minutes
openclaw cron add \
--name "claude-token-refresh" \
--every 30m \
--announce \
--message "Запусти {baseDir}/scripts/auto-refresh-cron.sh"
What it does:
Manual refresh (once per week, 30 seconds):
claude auth login
# Browser opens → sign in to claude.ai → done!
Tokens auto-sync to {baseDir}/.tokens after successful login.
"No token configured"
→ Run ./scripts/setup.sh
"Token expired" / "API request failed"
→ OAuth tokens expire after ~1 week
→ Manual refresh: claude auth login (browser opens → sign in → done)
→ Set up hourly health check to get alerts before expiry (see above)
Burn rate shows empty
→ API response missing resets_at — try again in a few minutes
Auto-refresh failed
→ OAuth refresh endpoint may have changed
→ Manual refresh: claude auth login → copy new tokens → run ./scripts/setup.sh
auto-refresh-cron.sh (removed quotes handling)~/.claude/.credentials.jsonFound a bug or have a feature request? → Open an issue on ClawHub: https://clawhub.ai/friday/token-usage-optimizer
MIT