Skip to content

Conversation

@improdead
Copy link

@improdead improdead commented Jan 18, 2026

Summary

This PR adds the ability for users to view their AI provider quota usage directly within OpenCode. Users can now easily monitor how much of their rate limits they've consumed across different providers like OpenAI, Anthropic, GitHub Copilot, and Google/Antigravity.

With more and more people using plugins like GitHub Copilot and Antigravity (Google), having visibility into rate limits has become increasingly important. This feature helps users avoid hitting quota limits unexpectedly during their coding sessions.

What's New

/usage Command
A new dialog that shows detailed usage information for your current AI provider:

  • Visual progress bars showing quota consumption
  • Reset time countdowns (e.g., "Resets in 2h 30m")
  • Toggle between "used" and "remaining" views with the Tab key
  • Special handling for GitHub Copilot with built-in device flow authentication
  • Shows "Unlimited" for pay-per-use providers like OpenCode Zen

Sidebar Usage Section
A compact usage display in the sidebar that:

  • Shows the current provider's quota at a glance
  • Automatically refreshes after each assistant turn completes
  • Refreshes when you switch to a different model/provider
  • Can be hidden by clicking the ✕ button
  • Can be restored by clicking "Show usage" in the Context section
  • Only displays when usage data is available (no errors shown if provider doesn't support it)

Sidebar Documentation
Added documentation for the TUI sidebar feature with screenshot showing how to toggle it with ctrl+x b.

Supported Providers

Provider API Endpoint Notes
OpenAI chatgpt.com/backend-api/wham/usage ChatGPT Plus/Pro quotas
Anthropic api.anthropic.com/api/oauth/usage Claude rate limits
GitHub Copilot api.github.com/copilot_internal/user Uses separate device flow auth
Google/Antigravity Google cloudcode API Vertex AI quotas

GitHub Copilot

GitHub Copilot requires a separate authentication flow since usage data isn't accessible through the regular Copilot tokens. When you first try to view Copilot usage, you'll be prompted to authenticate with a device code flow using a Copilot-specific client ID. The token is stored separately at ~/.local/share/opencode/usage-copilot.json so it doesn't interfere with your regular Copilot authentication.

Antigravity (Google)

This support was added because so many people use https://github.com/NoeFabris/opencode-antigravity-auth to connect to Antigravity

With Antigravity becoming a popular choice for accessing Google's models through OpenCode, this PR adds support for fetching usage data from Google's cloudcode API. This gives Antigravity users the same visibility into their quota consumption as other providers.

Screenshots

/usage
Usage dialog showing provider quota

Sidebar Usage
Sidebar with usage section

Sidebar Usage (Copilot)
Sidebar showing Copilot usage

Usage Remaining View
Usage dialog showing remaining quota

Copilot Auth Flow
Copilot device flow authentication

Sidebar Toggle
OpenCode TUI Sidebar

Implementation Details

  • Created a new @/usage module with provider-specific implementations
  • Each provider gracefully handles 401/403 errors without crashing
  • Copilot uses its own client ID (Iv1.b507a08c87ecfe98) and stores tokens separately
  • Sidebar usage can be dismissed and restored via KV store preference
  • Sidebar usage refreshes when switching models/providers

Closes #9281
Closes #768

@github-actions
Copy link
Contributor

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

Found potential related PRs:

  1. PR feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar #6905 - feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar

  2. PR feat: add usage tracking API and /usage dialog #7837 - feat: add usage tracking API and /usage dialog

  3. PR feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements #9069 - feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements

Why they're related: PRs #6905 and #7837 appear to address the same core feature set - displaying AI provider usage information through both a /usage command dialog and sidebar integration. You may want to review these older PRs to understand if they were closed/abandoned, superseded, or if this PR is building upon them.

@improdead improdead force-pushed the feature/usage-command branch from f952e83 to 3c7cb89 Compare January 18, 2026 22:19
@improdead
Copy link
Author

@thdxr
hey Dax added /usage like in claude code for all major connectors please check it out man

@stevoland
Copy link
Contributor

tested github-copilot. banger

@improdead
Copy link
Author

can someone test claude I dont have it lol

@CasualDeveloper
Copy link
Contributor

@improdead lol i created my issue in preparation of my own pr which i'm currently testing, because the previous prs didn't have linked issues. i'll check out your implementation

@improdead
Copy link
Author

@improdead lol i created my issue in preparation of my own pr which i'm currently testing, because the previous prs didn't have linked issues. i'll check out your implementation

oh lol

@improdead improdead force-pushed the feature/usage-command branch 2 times, most recently from bb80dea to 491dfdd Compare January 18, 2026 23:38
- Add DialogUsage component with progress bars for usage tracking
- Support OpenAI, Anthropic, GitHub Copilot, and Antigravity providers
- Add Tab toggle to switch between 'used' and 'remaining' view
- Implement Copilot device flow auth for usage API access
- Store Copilot usage token separately (different OAuth client ID)
- Add graceful 401/403 error handling for all providers
- Show 'Unlimited' for pay-per-use providers like OpenCode Zen

Closes anomalyco#9281
@improdead improdead force-pushed the feature/usage-command branch from 491dfdd to e0dcbfe Compare January 18, 2026 23:38
@Mirrowel
Copy link

Duplicate of #7837 . May need to be combined.

@improdead
Copy link
Author

Duplicate of #7837 . May need to be combined.
thanks for mentioning I took at look it shows the quota of all models at once all together while I show quota of the model user is currently using I think it is more convenient that way

@madebyshaurya
Copy link

madebyshaurya commented Jan 19, 2026

Tried this on codex mode. Works great! Good job

CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 20, 2026
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude.

Core:
- New usage module with fetchers for each provider's usage endpoint
- GET /usage endpoint with provider filter and refresh options
- Claude token auto-refresh on 401 via console.anthropic.com
- usage.updated bus event for real-time sidebar sync

Auth:
- Second device-flow during Copilot login for copilot_internal/user token
- Optional usage field in OAuth schema for provider-specific tokens
- Service token exchange attempt via copilot_internal/v2/token

TUI:
- /usage command with --current and --all flags (always fetches fresh)
- Usage dialog with progress bars, reset times, credits/quota display
- Sidebar Usage panel refreshes on events and assistant turn completion
- tui.show_usage_scope config setting for default scope

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 20, 2026
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude.

Core:
- New usage module with fetchers for each provider's usage endpoint
- GET /usage endpoint with provider filter and refresh options
- Claude token auto-refresh on 401 via console.anthropic.com
- usage.updated bus event for real-time sidebar sync

Auth:
- Second device-flow during Copilot login for copilot_internal/user token
- Optional usage field in OAuth schema for provider-specific tokens
- Service token exchange attempt via copilot_internal/v2/token

TUI:
- /usage command with --current and --all flags (always fetches fresh)
- Usage dialog with progress bars, reset times, credits/quota display
- Sidebar Usage panel refreshes on events and assistant turn completion
- tui.show_usage_scope config setting for default scope

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
@CasualDeveloper
Copy link
Contributor

CasualDeveloper commented Jan 20, 2026

Hey @improdead — I took a whack at my own implementation to close #9281 via an alternate approach in #9545.

Key differences:

  • /usage is server-side SSOT (GET /usage) vs client-driven fetchers
  • Config option tui.show_usage_scope for sidebar scope control
  • /usage --current|--all flags to override config
  • Claude token auto-refresh on expiry (mirrors anthropic plugin behavior)
  • Copilot usage token stored in auth.json under usage field

Thanks for the initial exploration!

@rekram1-node Happy to accept and close if either PR covers the use case.

CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 20, 2026
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude.

Core:
- New usage module with fetchers for each provider's usage endpoint
- GET /usage endpoint with provider filter and refresh options
- Claude token auto-refresh on 401 via console.anthropic.com
- usage.updated bus event for real-time sidebar sync

Auth:
- Second device-flow during Copilot login for copilot_internal/user token
- Optional usage field in OAuth schema for provider-specific tokens
- Service token exchange attempt via copilot_internal/v2/token

TUI:
- /usage command with --current and --all flags (always fetches fresh)
- Usage dialog with progress bars, reset times, credits/quota display
- Sidebar Usage panel refreshes on events and assistant turn completion
- tui.show_usage_scope config setting for default scope

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 22, 2026
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude.

Core:
- New usage module with fetchers for each provider's usage endpoint
- GET /usage endpoint with provider filter and refresh options
- Claude token auto-refresh on 401 via console.anthropic.com
- usage.updated bus event for real-time sidebar sync

Auth:
- Second device-flow during Copilot login for copilot_internal/user token
- Optional usage field in OAuth schema for provider-specific tokens
- Service token exchange attempt via copilot_internal/v2/token

TUI:
- /usage command with --current and --all flags (always fetches fresh)
- Usage dialog with progress bars, reset times, credits/quota display
- Sidebar Usage panel refreshes on events and assistant turn completion
- tui.show_usage_scope config setting for default scope

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 23, 2026
Add /usage as the single source of truth for provider usage data with
TUI integration and shared provider registry metadata.

Core:
- Usage registry shared by server + TUI (auth-key-based providers)
- GET /usage endpoint with provider filter and refresh options
- Usage cache updates respect explicit nulls and error responses
- Claude token auto-refresh on 401 via console.anthropic.com

Auth:
- Copilot OAuth flow includes optional usage device login (shared for all clients)
- Optional usage field in OAuth schema for provider-specific tokens

TUI:
- /usage command with --current and --all flags (always fetches fresh)
- Usage dialog + sidebar with shared formatting helpers
- Provider-scoped error lines shown below usage entries
- Extra Usage labeling for Claude, quota labeling for Copilot
- tui.show_usage_scope config setting for default scope

Quality:
- Fix shell/command double-submit and restore extmarks after external editor
- Expanded usage tests for cache fallback and Claude extra usage
- Usage response returns per-provider errors

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 23, 2026
Add /usage as the single source of truth for provider usage data with
TUI integration and shared provider registry metadata.

Core:
- Usage registry shared by server + TUI (auth-key-based providers)
- GET /usage endpoint with provider filter and refresh options
- Parallel provider fetches with error-aware caching
- Claude token auto-refresh on 401 via console.anthropic.com

Auth:
- Copilot OAuth flow includes optional usage device login (shared for all clients)
- Optional usage field in OAuth schema for provider-specific tokens

TUI:
- /usage command with --current and --all flags (always fetches fresh)
- Shared usage client for dialog + sidebar fetches
- Provider-scoped error lines shown below usage entries
- Extra Usage labeling for Claude, quota labeling for Copilot
- tui.show_usage_scope config setting for default scope

Quality:
- Fix shell/command double-submit and restore extmarks after external editor
- Usage cache overwrite respects explicit nulls
- Expanded usage + Copilot auth tests

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
CasualDeveloper added a commit to CasualDeveloper/opencode that referenced this pull request Jan 23, 2026
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures.

- Add usage provider registry mapping auth keys to display names
- Support two-call OAuth flow for Copilot usage token acquisition
- Automatic token refresh on 401/expired Claude responses
- TUI: shared usage client, dialog and sidebar components with live event-driven updates
- Return structured `errors[]` alongside `entries[]` for granular UI feedback
- Tests for usage endpoint and new Copilot-specific auth device flow
- Regenerate SDK/OpenAPI with new Usage class and types

Closes anomalyco#9281, anomalyco#728
Supersedes anomalyco#6905, anomalyco#7837
Alternate to anomalyco#9301
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.

[FEATURE] Add unified usage tracking via /usage (#9545) Github Copilot: Tracking Premium Requests

5 participants