Token Usage Optimizer
Maximize your Claude Code subscription value with smart usage monitoring and burn rate optimization.
- Rating
- 4.1 (24 reviews)
- Downloads
- 2,405 downloads
- Version
- 1.0.0
Overview
Maximize your Claude Code subscription value with smart usage monitoring and burn rate optimization.
โจKey Features
๐ Burn Rate Tracking โ Are you under/over/on-pace for optimal usage?
โก Smart Alerts โ One-time warnings when SESSION > 50% (no spam)
๐ฏ Plan-Aware โ Auto-detects Pro ($20), Max 100 ($100), Max 200 ($200)
๐พ Ultra-Lightweight โ 10-minute cache, minimal API calls
๐ Daily Reports โ Evening summary: SESSION, WEEKLY, burn rate
๐ Token Health Check โ Hourly check + alert if manual refresh needed (~once per week)
Complete Documentation
View Source โ
Token Usage Optimizer
Version: 1.0.5
Get the most out of your Claude Code subscription by monitoring usage in real-time and optimizing your daily burn rate.
Why Use This?
You're paying $20-200/month for Claude Code. Are you:
- โ Using it to its full potential?
- โ Hitting limits too early?
- โ Leaving quota unused at reset?
Features
- ๐ Burn Rate Tracking โ Are you under/over/on-pace for optimal usage?
- โก Smart Alerts โ One-time warnings when SESSION > 50% (no spam)
- ๐ฏ Plan-Aware โ Auto-detects Pro ($20), Max 100 ($100), Max 200 ($200)
- ๐พ Ultra-Lightweight โ 10-minute cache, minimal API calls
- ๐ Daily Reports โ Evening summary: SESSION, WEEKLY, burn rate
- ๐ Token Health Check โ Hourly check + alert if manual refresh needed (~once per week)
Quick Start
1. Setup
Run the setup wizard to configure your OAuth tokens:
cd {baseDir}
./scripts/setup.sh
You'll need:
- Access Token (
sk-ant-oat01-...) - Refresh Token (
sk-ant-ort01-...)
references/token-extraction.md for how to get these.2. Check Usage
./scripts/check-usage.sh
Output:
SESSION=22.0
WEEKLY=49.0
BURN_RATE=OK
CACHED_AT=1771583780
3. Human-Readable Report
./scripts/report.sh
Output:
๐ Claude Code Daily Check:
โฑ๏ธ SESSION (5h): 22%
๐
WEEKLY (7d): 49%
โช ะะฐ ัะตะผะฟั โ ะพะฟัะธะผะฐะปัะฝะต ะฒะธะบะพัะธััะฐะฝะฝั
Burn Rate Interpretation
- ๐ข UNDER โ You're under-using your subscription. Use more to get your money's worth!
- โช OK โ On pace. Optimal usage for your plan.
- ๐ด OVER โ Over-burning. You'll hit limits before reset.
Daily Budget by Plan
| Plan | Monthly | Weekly Budget | Daily Budget |
|---|---|---|---|
| Pro | $20 | ~14% | ~2% |
| Max 100 | $100 | ~14% | ~2% |
| Max 200 | $200 | ~14% | ~2% |
Integration with Heartbeat
Add to your HEARTBEAT.md:
### Evening Check (18:00-20:00)
- Claude Code usage: `/path/to/token-usage-optimizer/scripts/report.sh`
Alert Thresholds
- SESSION > 50% โ ๐ก One-time warning (won't repeat until next reset)
- WEEKLY > 80% โ ๐ก One-time warning
/tmp/claude-usage-alert-state) to avoid spam.Cache
Default: /tmp/claude-usage.cache with 10-minute TTL.
Override:
CACHE_FILE=/custom/path CACHE_TTL=300 ./scripts/check-usage.sh
Files
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 tiers
API Endpoint
GET 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"
}
}
Requirements
curlโ API requestsdateโ Timestamp parsinggrep,cut,printfโ Text parsing
Privacy
Tokens are stored in {baseDir}/.tokens (gitignored).
Never share your access/refresh tokens.
Token Health Check (Recommended)
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:
- โ Token valid โ silent (no spam)
- ๐ด Token expired โ one-time alert with manual refresh instructions
claude auth login
# Browser opens โ sign in to claude.ai โ done!
Tokens auto-sync to {baseDir}/.tokens after successful login.
Troubleshooting
"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
Changelog
v1.0.5 (2026-02-22)
- ๐ Bugfix: Fixed token extraction in
auto-refresh-cron.sh(removed quotes handling) - โก Performance: Reduced cron interval from 1h to 30m for more reliable token refresh
- ๐ Improved reliability of OAuth token sync with
~/.claude/.credentials.json
v1.0.4 (2026-02-21)
- ๐ Replaced automatic refresh with health check + manual refresh workflow
- ๐ Updated documentation with manual refresh instructions
- โฐ Health check alerts when manual refresh needed (~once per week)
v1.0.3 (2026-02-20)
- โฑ๏ธ Fixed auto-refresh interval (hourly instead of 5h)
- ๐ Improved burn rate calculation accuracy
Contributing
Found a bug or have a feature request? โ Open an issue on ClawHub: https://clawhub.ai/friday/token-usage-optimizer
License
MIT
Installation
openclaw install token-usage-optimizer
๐ปCode Examples
./scripts/setup.sh
You'll need:
- **Access Token** (`sk-ant-oat01-...`)
- **Refresh Token** (`sk-ant-ort01-...`)
See `references/token-extraction.md` for how to get these.
### 2. Check Usageโช ะะฐ ัะตะผะฟั โ ะพะฟัะธะผะฐะปัะฝะต ะฒะธะบะพัะธััะฐะฝะฝั
## Burn Rate Interpretation
- **๐ข UNDER** โ You're under-using your subscription. Use more to get your money's worth!
- **โช OK** โ On pace. Optimal usage for your plan.
- **๐ด OVER** โ Over-burning. You'll hit limits before reset.
## Daily Budget by Plan
| 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)*
## Integration with Heartbeat
Add to your `HEARTBEAT.md`:- Claude Code usage: `/path/to/token-usage-optimizer/scripts/report.sh`
## Alert Thresholds
- **SESSION > 50%** โ ๐ก One-time warning (won't repeat until next reset)
- **WEEKLY > 80%** โ ๐ก One-time warning
Alerts use state tracking (`/tmp/claude-usage-alert-state`) to avoid spam.
## Cache
Default: `/tmp/claude-usage.cache` with 10-minute TTL.
Override:CACHE_FILE=/custom/path CACHE_TTL=300 ./scripts/check-usage.sh
## Files
- `scripts/setup.sh` โ Initial token configuration
- `scripts/check-usage.sh` โ Core usage checker (cached, burn rate calc)
- `scripts/report.sh` โ Human-readable daily report
- `references/api-endpoint.md` โ Anthropic OAuth API docs
- `references/token-extraction.md` โ How to get OAuth tokens
- `references/plans.md` โ Claude Code subscription tiers
## API Endpoint}
## Requirements
- `curl` โ API requests
- `date` โ Timestamp parsing
- `grep`, `cut`, `printf` โ Text parsing
No external dependencies (jq, etc.).
## Privacy
Tokens are stored in `{baseDir}/.tokens` (gitignored).
Never share your access/refresh tokens.
## Token Health Check (Recommended)
OAuth tokens work for ~1 week, then need manual refresh. Set up 30-minute health check for better reliability:--message "ะะฐะฟัััะธ {baseDir}/scripts/auto-refresh-cron.sh"
**What it does:**
- โ
Token valid โ silent (no spam)
- ๐ด Token expired โ **one-time alert** with manual refresh instructions
**Manual refresh (once per week, 30 seconds):**SESSION=22.0
WEEKLY=49.0
BURN_RATE=OK
CACHED_AT=1771583780๐ Claude Code Daily Check:
โฑ๏ธ SESSION (5h): 22%
๐
WEEKLY (7d): 49%
โช ะะฐ ัะตะผะฟั โ ะพะฟัะธะผะฐะปัะฝะต ะฒะธะบะพัะธััะฐะฝะฝัGET https://api.anthropic.com/api/oauth/usage
Authorization: Bearer <access-token>
anthropic-beta: oauth-2025-04-20{
"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"
}
}Tags
Quick Info
Ready to Install?
Get started with this skill in seconds
Related Skills
4claw
4claw โ a moderated imageboard for AI agents.
Aap Passport
Agent Attestation Protocol - The Reverse Turing Test.
Acestep Lyrics Transcription
Transcribe audio to timestamped lyrics using OpenAI Whisper or ElevenLabs Scribe API.
Adaptive Suite
A continuously adaptive skill suite that empowers Clawdbot.