claude-code-usage
Check Claude Code OAuth usage limits (session & weekly quotas). Use when user asks about Claude Code usage, remaining limits, rate limits, or how much Claude usage they have left. Includes automated session refresh reminders and reset detection monitoring.
What this skill does
# Claude Code Usage
Check your Claude Code OAuth API usage limits for both session (5-hour) and weekly (7-day) windows.
## Quick Start
```bash
cd {baseDir}
./scripts/claude-usage.sh
```
## Usage
```bash
# Default: show cached usage (if fresh)
./scripts/claude-usage.sh
# Force refresh from API
./scripts/claude-usage.sh --fresh
# JSON output
./scripts/claude-usage.sh --json
# Custom cache TTL
./scripts/claude-usage.sh --cache-ttl 300
```
## Output
**Text format** (default):
```
๐ฆ Claude Code Usage
โฑ๏ธ Session (5h): ๐ข โโโโโโโโโโ 40%
Resets in: 2h 15m
๐
Weekly (7d): ๐ก โโโโโโโโโโ 60%
Resets in: 3d 8h
```
**JSON format** (`--json`):
```json
{
"session": {
"utilization": 40,
"resets_in": "2h 15m",
"resets_at": "2026-01-19T22:15:00Z"
},
"weekly": {
"utilization": 60,
"resets_in": "3d 8h",
"resets_at": "2026-01-22T04:00:00Z"
},
"cached_at": "2026-01-19T20:00:00Z"
}
```
## Features
- ๐ **Session limit** (5-hour window) - Short-term rate limit
- ๐
**Weekly limit** (7-day window) - Long-term rate limit
- โก **Smart caching** - 60-second cache to avoid API spam
- ๐จ **Beautiful output** - Progress bars, emojis, color-coded status
- ๐ **Force refresh** - `--fresh` flag to bypass cache
- ๐ค **JSON output** - Machine-readable format
- ๐ **Automated monitoring** - Get notified when quotas reset
## Status Indicators
- ๐ข **Green** - 0-50% usage (healthy)
- ๐ก **Yellow** - 51-80% usage (moderate)
- ๐ด **Red** - 81-100% usage (high/critical)
## Requirements
- **macOS**: Uses Keychain to access Claude Code credentials
- **Linux**: Uses `secret-tool` for credential storage
- **Credentials**: Must have Claude Code CLI authenticated
## How It Works
1. Retrieves OAuth token from system keychain
2. Queries `api.anthropic.com/api/oauth/usage` with OAuth bearer token
3. Parses `five_hour` and `seven_day` utilization metrics
4. Calculates time remaining until reset
5. Formats output with progress bars and status indicators
6. Caches result for 60 seconds (configurable)
## Cache
Default cache: `/tmp/claude-usage-cache` (60s TTL)
Override:
```bash
CACHE_FILE=/tmp/my-cache CACHE_TTL=300 ./scripts/claude-usage.sh
```
## Examples
**Check usage before starting work:**
```bash
./scripts/claude-usage.sh --fresh
```
**Integrate with statusline:**
```bash
usage=$(./scripts/claude-usage.sh | grep "Session" | awk '{print $NF}')
echo "Session: $usage"
```
**Get JSON for monitoring:**
```bash
./scripts/claude-usage.sh --json | jq '.session.utilization'
```
## Automated Monitoring
### Session Refresh Reminders (Recommended)
Get notified exactly when your 5-hour session quota refreshes!
**Quick Setup:**
```bash
./scripts/session-reminder.sh
```
This creates a **self-scheduling chain** of cron jobs that:
1. Checks your current session expiry time
2. Schedules the next reminder for when your session refreshes
3. Notifies you with current usage stats
4. Auto-removes itself (the new cron takes over)
**What You'll Get:**
```
๐ Claude Code Session Status
โฑ๏ธ Current usage: 44%
โฐ Next refresh: 2h 15m
Your 5-hour quota will reset soon! ๐ฆ
โ
Next reminder scheduled for: Jan 22 at 01:22 AM
```
**How It Works:**
- Each reminder runs `claude-usage.sh` to find the exact session reset time
- Schedules a one-time cron for that exact moment
- Repeats every 5 hours automatically
- Self-correcting if session times ever drift
**Benefits:**
- โ
Accurate to the minute
- โ
No manual scheduling needed
- โ
Adapts to your actual usage patterns
- โ
Minimal API calls (only when needed)
### Reset Detection Monitor (Alternative)
Get automatic notifications when your Claude Code quotas reset by polling usage.
**Quick Setup:**
```bash
# Test once
./scripts/monitor-usage.sh
# Setup automated monitoring (runs every 30 minutes)
./scripts/setup-monitoring.sh
```
Or add via Clawdbot directly:
```bash
# Check every 30 minutes
clawdbot cron add --cron "*/30 * * * *" \
--message "cd /Users/ali/clawd/skills/claude-code-usage && ./scripts/monitor-usage.sh" \
--name "Claude Code Usage Monitor" \
--session isolated --deliver --channel telegram
```
**What You'll Get:**
```
๐ Claude Code Session Reset!
โฑ๏ธ Your 5-hour quota has reset
๐ Usage: 2%
โฐ Next reset: 4h 58m
Fresh usage available! ๐ฆ
```
**How It Works:**
1. **Monitors usage** every 30 minutes (configurable)
2. **Detects resets** when usage drops significantly (>10% or <5%)
3. **Sends notifications** via Telegram when resets occur
4. **Tracks state** in `/tmp/claude-usage-state.json`
**Customization:**
```bash
# Change check interval
clawdbot cron add --cron "*/15 * * * *" ... # Every 15 minutes
clawdbot cron add --cron "0 * * * *" ... # Every hour
# Custom state file location
STATE_FILE=/path/to/state.json ./scripts/monitor-usage.sh
```
### Which Monitoring Method?
| Feature | Session Reminder | Reset Detection |
|---------|-----------------|-----------------|
| Accuracy | โ
Exact minute | ~30min window |
| API calls | Minimal | Every check |
| Notification timing | Right on reset | Up to 30min delay |
| Setup | One command | One command |
| Maintenance | Self-scheduling | Cron runs forever |
**Recommendation:** Use **Session Reminder** for precise, real-time notifications.
## Troubleshooting
**No credentials found:**
- Ensure Claude Code CLI is installed and authenticated
- Run `claude` once to trigger OAuth flow
**API request failed:**
- Check internet connection
- Verify OAuth token hasn't expired
- Try `--fresh` to force new request
**Linux users:**
Install `libsecret` for credential storage:
```bash
# Debian/Ubuntu
sudo apt install libsecret-tools
# Fedora/RHEL
sudo dnf install libsecret
```
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts โ single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score โฅ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.