📊

精准监控Claude配额,重置零等待

Claude Code Usage · v1.2.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
专业技能 安全 A 级 作者 azaidi94 公开目录收录
5.4k 下载 16 安装 23.5k 收藏 30 浏览

简介

实时监控Claude Code OAuth配额的双窗口限制(5小时会话+7天周期),智能缓存、精准重置提醒,避免API调用中断。

原始描述

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.

通过你的 Agent 添加

安装目录:claude-code-usage/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/claude-code-usage/
Codex CLI~/.codex/skills/claude-code-usage/
DeepSeek Harness~/.agents/skills/claude-code-usage/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Claude Code Usage 是一款轻量级命令行工具,用于实时监控 Claude Code 的 OAuth API 使用配额。执行 ./scripts/claude-usage.sh 即可获取可视化进度条展示:

  • 5小时会话配额:短期速率限制,适合密集编程 session
  • 7天周度配额:长期使用量控制

支持 --fresh 强制刷新、--json 机器可读输出、--cache-ttl 自定义缓存时长,灵活适配脚本集成与人工查看场景。

显著优点

  1. 零配置即用:自动从系统密钥链读取 Claude Code 凭证(macOS Keychain / Linux secret-tool),无需手动管理 API Key
  2. 双模式监控:Session Reminder(精确到分钟)与 Reset Detection(30分钟轮询)两种自动化方案,适配不同精度需求
  3. 视觉友好:Emoji 状态指示器 + 进度条 + 颜色编码(🟢绿/🟡黄/🔴红),一眼掌握配额健康度
  4. 纯 Bash 零依赖:不依赖 npm/pip,仅使用系统自带的 curl,部署极简
  5. 智能自调度:Session Reminder 采用"链式 cron"设计,每次提醒后自动计算下一次配额重置时间并创建新定时任务,精准无冗余

潜在局限

  1. 正则解析 JSON:使用 grep/sed 而非 jq 解析 API 响应,若 Anthropic 返回格式变化可能失效(已识别为低风险)
  2. 个人维护项目:开发者 RZA 为个人身份,非知名组织,长期维护稳定性存不确定性
  3. 平台限制:仅支持 macOS 和 Linux,Windows 需 WSL 环境
  4. API 依赖单点:完全依赖 Anthropic 官方 API 可用性,无降级方案

适合人群

  • 高频使用 Claude Code 的开发者,需要避免编程中途因配额耗尽中断
  • 团队管理员,需监控成员配额使用趋势
  • 自动化爱好者,希望将配额状态集成到 tmux 状态栏、Waybar 等系统监控组件
  • 多设备切换用户,通过 Telegram 通知跨设备同步配额重置状态

常规风险

风险项 等级 说明
凭证安全 低 仅读取系统密钥链,不落盘存储
网络传输 低 HTTPS/TLS 1.2+ 加密访问官方 API
临时文件 低 /tmp 缓存仅含使用率百分比,无敏感信息
注入攻击 极低 无 eval/exec,参数解析简单可控
隐私合规 低 符合 GDPR 数据最小化原则

建议操作:首次使用建议运行 ./scripts/claude-usage.sh --fresh 验证凭证读取正常;若需生产环境自动化,建议改用 Session Reminder 方案以减少 API 调用频率。

技能正文


name: claude-code-usage description: 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. metadata: clawdbot: emoji: "📊" os: - darwin - linux requires: bins: - curl

Claude Code Usage

Check your Claude Code OAuth API usage limits for both session (5-hour) and weekly (7-day) windows.

Quick Start

cd {baseDir}
./scripts/claude-usage.sh

Usage

# 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):

{
  "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:

CACHE_FILE=/tmp/my-cache CACHE_TTL=300 ./scripts/claude-usage.sh

Examples

Check usage before starting work:

./scripts/claude-usage.sh --fresh

Integrate with statusline:

usage=$(./scripts/claude-usage.sh | grep "Session" | awk '{print $NF}')
echo "Session: $usage"

Get JSON for monitoring:

./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:

./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:

# Test once
./scripts/monitor-usage.sh

# Setup automated monitoring (runs every 30 minutes)
./scripts/setup-monitoring.sh

Or add via Clawdbot directly:

# 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:

# 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:

# Debian/Ubuntu
sudo apt install libsecret-tools

# Fedora/RHEL
sudo dnf install libsecret

正文来自原始仓库, 版权归作者所有,许可:MIT。 权利人认为有不妥,可申请下架。

原始仓库

作者的项目地址:https://github.com/ComeOnOliver/skillshub

标签

claudeanthropicoauthapi-monitoringrate-limitcli-toolcron-automationmacoslinuxdeveloper-productivity

同类 Skill