Skip to content

Add Claude Pro Usage Monitor (Dev) — OAuth endpoint, pure Python#2180

Open
shabalingv-rgb wants to merge 1 commit into
matryer:mainfrom
shabalingv-rgb:add-claude-pro-usage
Open

Add Claude Pro Usage Monitor (Dev) — OAuth endpoint, pure Python#2180
shabalingv-rgb wants to merge 1 commit into
matryer:mainfrom
shabalingv-rgb:add-claude-pro-usage

Conversation

@shabalingv-rgb

Copy link
Copy Markdown

What this plugin does

Monitors Claude Pro 5h session and 7-day weekly usage in the menu bar — exact data from Anthropic's OAuth endpoint (same numbers as claude.ai dashboard).

screenshot

Why it's different from the existing claude-usage.1m.py

Existing (aggel008) This plugin
Data source Browser via AppleScript XHR Anthropic OAuth API directly
Browser required Yes (Safari/Chrome must be open) No
Accuracy Depends on page DOM Exact (same as claude.ai)
Weekly limit Basic 7-day utilization + resets_at timestamp
Model breakdown No Yes (Opus/Sonnet/Haiku from JSONL)
Burn rate forecast No Yes (last-hour rate → ETA to limit)
Session history No Last 6h sessions
Dependencies python3 python3, Claude Code CLI

How it works

  1. Reads OAuth token from macOS Keychain (Claude Code-credentials — placed there by Claude Code CLI)
  2. Calls GET https://api.anthropic.com/api/oauth/usage with anthropic-beta: oauth-2025-04-20
  3. In parallel, scans ~/.claude/projects/*/*.jsonl for model-level cost breakdown
  4. Displays exact five_hour.utilization % and resets_at countdown

Requirements

  • Python 3 (pre-installed on macOS)
  • Claude Code CLI — must be installed and logged in (provides OAuth token)
  • Claude Pro or Max account

Source repository

https://github.com/shabalingv-rgb/swiftbar-claude-usage

Checklist

  • Plugin is executable (chmod +x)
  • Uses #!/usr/bin/env shebang (via /bin/bash)
  • Has both xbar.* and swiftbar.* metadata headers
  • No hardcoded personal paths
  • Tested on macOS 15 Sequoia, SwiftBar 2.x

Monitors Claude Pro 5h session and 7-day weekly limits directly via
Anthropic's OAuth endpoint — the same source as claude.ai dashboard.

- Exact utilization % from api.anthropic.com/api/oauth/usage
- No external dependencies: pure Python + stdlib
- Parallel fetch: OAuth HTTP + JSONL scan via threading (~1s total)
- Model breakdown (Opus/Sonnet/Haiku) from local JSONL logs
- Burn rate forecast, weekly limit with reset countdown
- Graceful fallback to local JSONL if OAuth unreachable
- Compatible with both xbar and SwiftBar

Requires: Python 3, Claude Code CLI (provides OAuth token in Keychain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant