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 month 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

The following comment was made by an LLM, it may be inaccurate:

Summary

I found 1 related PR that may be worth considering:

Related PR:

  • #6298 - Add (z.ai) plan usage tracking in the sidebar
    • Why related: This PR implements plan usage tracking for a different provider (z.ai). The PR description already mentions this as a related item (#6298), noting that both could potentially be integrated with a shared registry pattern in the future. Both PRs add usage display to the sidebar and handle real-time usage metrics.

No Direct Duplicates Found:

The main PR (#6905) appears to be the only one actively addressing OAuth usage display for Anthropic and OpenAI specifically. The searches did not reveal any other open PRs duplicating this exact feature.

Recommendation: The PR is likely ready to proceed, but keep PR #6298 in mind for potential future refactoring to unify the usage tracking patterns across different providers.

github-actions[bot] avatar Jan 05 '26 04:01 github-actions[bot]