[PR #6905] feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar #12158

Open
opened 2026-02-16 18:17:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6905

State: open
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6905 **State:** open **Merged:** No --- ## 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
yindo added the pull-request label 2026-02-16 18:17:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12158