opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add /usage usage tracking (codex/copilot/claude)

Open CasualDeveloper opened this issue 1 day ago • 3 comments

Problem

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

Reproduction

  1. Authenticate at least one provider (e.g. opencode auth add codex / opencode auth add github-copilot / opencode auth add anthropic).
  2. Open the TUI.
  3. There is no sidebar panel or /usage command to show remaining provider usage limits.

Analysis

Each provider exposes usage via a dedicated endpoint, but the UI currently has no unified surface for it. A single /usage API keeps sidebar + dialog consistent and avoids duplicating provider-specific logic in the UI.

Provider sources:

  • codex: https://chatgpt.com/backend-api/wham/usage (include ChatGPT-Account-Id when present)
  • claude: https://api.anthropic.com/api/oauth/usage (requires anthropic-beta: oauth-2025-04-20)
  • copilot: https://api.github.com/copilot_internal/user (best-effort; enterprise via /api/v3/copilot_internal/user)

Proposed Fix

  • Add GET /usage (operationId: usage.get) returning usage snapshots for authenticated providers only.
  • TUI:
    • /usage command opens a dialog (supports provider filter + --refresh / -r)
    • Sidebar "Usage" section shows provider limits and refreshes after assistant turn completion.

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
  • [ ] OpenAPI + JS SDK regenerated/in sync
  • [ ] Typecheck + tests pass

Related

  • Closes #768
  • Supersedes #6905
  • Supersedes #7837

AI Assistance

  • OpenCode + openai/gpt-5.2-codex; human reviewed.

CasualDeveloper avatar Jan 18 '26 20:01 CasualDeveloper