opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar

Open phj1081 opened this issue 1 week ago • 1 comments

Summary

Adds real-time usage display for Anthropic and OpenAI OAuth accounts in both the status dialog (/status) and the sidebar.

Features

  • Anthropic Usage: Shows 5-hour and 7-day rate limit windows with utilization % and reset times
  • OpenAI Usage: Shows primary/secondary rate limit windows, plan type (Free/Plus/Pro/etc), and credits balance
  • Visual Progress Bars: Color-coded bars (green → yellow → red) based on utilization level
  • Reset Time Display: Human-readable countdown (e.g., "2h 15m", "5d 3h")

Screenshots

Status Dialog (/status or Ctrl+X S)

Anthropic Usage
5h:  ██░░░░░░░░░░░░░░░░░░ 9%   (reset: 2h 15m)
7d:  ████░░░░░░░░░░░░░░░░ 21%  (reset: 5d 3h)

OpenAI Usage (Pro)
5h:  ░░░░░░░░░░░░░░░░░░░░ 0%   (reset: 4h 59m)
7d:  ██████░░░░░░░░░░░░░░ 30%  (reset: 4d 2h)
Credits: $1000.00

Sidebar (collapsible Usage section)

▼ Usage
Anthropic
5h █░░░░░░░░░ 9% (2h 15m)
7d ██░░░░░░░░ 21% (5d 3h)
OpenAI (Pro)
5h ░░░░░░░░░░ 0% (4h 59m)
7d ███░░░░░░░ 30% (4d 2h)

Implementation

New Files

  • src/usage/anthropic.ts: Fetches from api.anthropic.com/api/oauth/usage
  • src/usage/openai.ts: Fetches from chatgpt.com/backend-api/wham/usage

Modified Files

  • dialog-status.tsx: Added usage sections with progress bars
  • sidebar.tsx: Added collapsible Usage section

API Details

Provider Endpoint Auth
Anthropic GET api.anthropic.com/api/oauth/usage OAuth token + anthropic-beta: oauth-2025-04-20
OpenAI GET chatgpt.com/backend-api/wham/usage OAuth Bearer token

Related

  • #6298 - Plan usage tracking (z.ai) - Similar feature for different provider. Could potentially be integrated with their registry pattern in the future.

Notes

  • Only shows usage when OAuth is configured (falls back gracefully if not)
  • Uses Zod for runtime validation of API responses
  • Sidebar uses compact 10-char progress bar; status dialog uses 20-char bar

phj1081 avatar Jan 05 '26 04:01 phj1081