[FEATURE] Add unified usage tracking via /usage (#9545) #6717

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

Originally created by @CasualDeveloper on GitHub (Jan 18, 2026).

Originally assigned to: @thdxr on GitHub.

show_usage_provider_scope## Problem
No way to view remaining plan usage/limits for authenticated providers (Codex, Copilot, Claude) inside the TUI.

Current State

  • /usage API is the single source of truth (UsageRoutes factory), endpoint-only fetching (not via header parsing).
  • /usage command opens a dialog and fetches latest data; sidebar shows usage and refreshes after assistant turns.
  • /usage always fetches latest data for either current provider or all providers; pass --current and --all to override config of fetch scope.
  • Config: tui.show_usage_provider_scope defaults to current and controls sidebar + /usage default scope.
  • Sidebar refreshes on usage.updated events from the server.
  • Fetchers return { snapshot, error } and surface status details in the dialog.
  • Copilot usage auth: opencode auth login prompts for a second device flow (VS Code client id) and stores usage token in auth.json; copilot_internal/user uses that token.
  • SDK/OpenAPI regenerated.

Open Threads

  • Decide Claude 401 handling (reauth hint vs refresh flow).
  • Decide whether to surface provider errors when another provider succeeds.
  • Re-run bun turbo typecheck and bun run --cwd packages/opencode test test/server/usage.test.ts after latest UI/config changes.

Acceptance Criteria

  • GET /usage returns entries only for authenticated providers (codex/copilot/claude)
  • /usage dialog renders all returned windows (Codex: hourly/weekly; Claude: 5h/7d/Opus 7d; Copilot: quota + reset date)
  • Sidebar renders the same data (SSoT via /usage) and refreshes after assistant turn completion
  • Config tui.show_usage_provider_scope controls default scope; /usage --current|--all overrides
  • Typecheck + tests pass

Related

AI Assistance

  • OpenCode + openai/gpt-5.2-codex; human reviewed.
Originally created by @CasualDeveloper on GitHub (Jan 18, 2026). Originally assigned to: @thdxr on GitHub. show_usage_provider_scope## Problem No way to view remaining plan usage/limits for authenticated providers (Codex, Copilot, Claude) inside the TUI. ## Current State - /usage API is the single source of truth (UsageRoutes factory), endpoint-only fetching (not via header parsing). - /usage command opens a dialog and fetches latest data; sidebar shows usage and refreshes after assistant turns. - /usage always fetches latest data for either current provider or all providers; pass `--current` and `--all` to override config of fetch scope. - Config: `tui.show_usage_provider_scope` defaults to `current` and controls sidebar + /usage default scope. - Sidebar refreshes on `usage.updated` events from the server. - Fetchers return `{ snapshot, error }` and surface status details in the dialog. - Copilot usage auth: `opencode auth login` prompts for a second device flow (VS Code client id) and stores `usage` token in `auth.json`; `copilot_internal/user` uses that token. - SDK/OpenAPI regenerated. ## Open Threads - Decide Claude 401 handling (reauth hint vs refresh flow). - Decide whether to surface provider errors when another provider succeeds. - Re-run `bun turbo typecheck` and `bun run --cwd packages/opencode test test/server/usage.test.ts` after latest UI/config changes. ## Acceptance Criteria - [x] GET /usage returns entries only for authenticated providers (codex/copilot/claude) - [x] /usage dialog renders all returned windows (Codex: hourly/weekly; Claude: 5h/7d/Opus 7d; Copilot: quota + reset date) - [x] Sidebar renders the same data (SSoT via /usage) and refreshes after assistant turn completion - [x] Config `tui.show_usage_provider_scope` controls default scope; `/usage --current|--all` overrides - [x] Typecheck + tests pass ## Related - Closes #768 - Supersedes #6905 - Supersedes #7837 ## AI Assistance - OpenCode + openai/gpt-5.2-codex; human reviewed.
Author
Owner

@github-actions[bot] commented on GitHub (Jan 18, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #768: Github Copilot: Tracking Premium Requests - requests tracking for Copilot provider usage quota

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 18, 2026): This issue might be a duplicate of existing issues. Please check: - #768: Github Copilot: Tracking Premium Requests - requests tracking for Copilot provider usage quota Feel free to ignore if none of these address your specific case.
Author
Owner

@CasualDeveloper commented on GitHub (Jan 18, 2026):

Thanks for the pointer. Related to #768 for Copilot quota visibility, but this issue is broader: adds a unified /usage API + TUI surfaces for codex/copilot/claude (including 5h/7d/Opus 7d windows) and is not limited to Copilot premium requests. I'll keep #768 referenced here.

AI Assistance: OpenCode + openai/gpt-5.2-codex; human reviewed.

@CasualDeveloper commented on GitHub (Jan 18, 2026): Thanks for the pointer. Related to #768 for Copilot quota visibility, but this issue is broader: adds a unified /usage API + TUI surfaces for codex/copilot/claude (including 5h/7d/Opus 7d windows) and is not limited to Copilot premium requests. I'll keep #768 referenced here. AI Assistance: OpenCode + openai/gpt-5.2-codex; human reviewed.
Author
Owner

@improdead commented on GitHub (Jan 18, 2026):

Hey made an pr about this with images check it out :)
so copilot we need a separate authentication flow since uage data is is not accessible through the one in auth.json and also added antigravity for the plugin Antigravity + Gemini CLI OAuth Plugin for Opencode due to large popularity

@improdead commented on GitHub (Jan 18, 2026): Hey made an pr about this with images check it out :) so copilot we need a separate authentication flow since uage data is is not accessible through the one in auth.json and also added antigravity for the plugin Antigravity + Gemini CLI OAuth Plugin for Opencode due to large popularity
Author
Owner

@nxtkofi commented on GitHub (Feb 10, 2026):

would love to see it get reviewed and merged

@nxtkofi commented on GitHub (Feb 10, 2026): would love to see it get reviewed and merged
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6717