Skip to content

Conversation

@IgorWarzocha
Copy link

@IgorWarzocha IgorWarzocha commented Jan 11, 2026

What does this PR do?

Adds a usage tracking API + TUI dialog for authenticated providers, including Codex and Copilot (rewritten for native Copilot plugin).

  • Adds /usage server route plus shared Usage module for fetching, caching, and normalizing usage snapshots
  • Captures Codex rate-limit headers and 429s to update usage state
  • Adds /usage autocomplete handling and a unified usage dialog (plan/quota parsing, scaling, reset display)
  • Regenerates SDK/OpenAPI artifacts for the new endpoint

How did you verify your code works?

  • Manual testing: verified with Copilot OAuth on free tier; GPT account on Plus plan; further provider/plan tests needed
  • bun run typecheck (fails in packages/opencode/src/server/server.ts:202 due to existing deep type instantiation error; unchanged from upstream)
screenrecording-2026-01-11_18-37-51.mp4

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

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

Based on my search results, I found 2 highly related PRs that appear to address similar or overlapping functionality:

Potential Duplicates:

  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

    • Related because it also implements usage tracking and display for authenticated providers (Anthropic and OpenAI) in a dialog/sidebar context
  2. PR feat: Add (z.ai) plan usage tracking in the sidebar #6298: feat: Add (z.ai) plan usage tracking in the sidebar

    • Related because it implements usage/plan tracking display functionality for another provider

These PRs implement similar functionality (usage display for providers), though PR #7837 appears to be a more comprehensive solution with a dedicated /usage API endpoint and unified dialog supporting multiple providers (Codex and Copilot).

Evoke4350 pushed a commit to Evoke4350/opencode that referenced this pull request Jan 13, 2026
Evoke4350 pushed a commit to Evoke4350/opencode that referenced this pull request Jan 13, 2026
This update aligns Copilot usage tracking with the native OpenCode Copilot plugin by utilizing real-time rate-limit headers and token metadata rather than flaky internal API calls.
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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant