Skip to content

feat(opencode): add CLI command to view Go usage limits - #32913

Closed
Nigmat-future wants to merge 1 commit into
anomalyco:devfrom
Nigmat-future:usage-cli
Closed

Nigmat-future wants to merge 1 commit into
anomalyco:devfrom
Nigmat-future:usage-cli

Conversation

@Nigmat-future

@Nigmat-future Nigmat-future commented Jun 18, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #9281

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Go subscribers currently only see their usage limits when they hit a 429 GoUsageLimitError — there's no way to check proactively. This adds an opencode usage CLI command so users can see how much of their 5-hour, weekly, and monthly quota is used at any time.

Server side — new GET /zen/go/v1/usage endpoint (packages/console/app/src/routes/zen/go/v1/usage.ts). It authenticates via the same Authorization: Bearer <key> header used by the chat completions endpoint, queries LiteTable / SubscriptionTable / BillingTable, and runs the existing Subscription.analyzeRollingUsage / analyzeWeeklyUsage / analyzeMonthlyUsage functions to compute usage percent and reset time for each window. Returns JSON with plan, windows[] (name, status, usagePercent, resetInSec, used, limit), and useBalance. Handles lite (Go), black, and free tiers.

CLI side — new opencode usage command (packages/opencode/src/cli/cmd/usage.ts). It resolves the opencode provider's API key and base URL from the loaded provider config, calls the usage endpoint, and prints a formatted summary with progress bars and reset countdowns. Registered in packages/opencode/src/index.ts alongside stats.

How did you verify your code works?

  • Verified the endpoint follows the same auth pattern (KeyTable join) and reuses the same Subscription.analyze* functions as the existing billing validation in handler.ts.
  • Confirmed the CLI command resolves the provider key and API URL the same way models.ts does via Provider.Service.
  • Checked that UI.Style constants (TEXT_DIM, TEXT_WARNING, TEXT_SUCCESS, etc.) used in the output formatter exist in packages/opencode/src/cli/ui.ts.
  • Verified the branch name (usage-cli), commit format (feat(opencode): …), and target branch (dev) conform to AGENTS.md.

Screenshots / recordings

Example output:

┌──────────────────────────────────────────────────────────┐
│                      GO USAGE                            │
├──────────────────────────────────────────────────────────┤
│  Plan                    Go (Lite)                       │
│  Use Balance             Off                             │
├──────────────────────────────────────────────────────────┤
│  ● 5-hour limit  $8.42 / $12.00  70%  ███████░░░         │
│  Resets in               2h 15m                          │
├──────────────────────────────────────────────────────────┤
│  ● Weekly limit  $18.30 / $30.00  61%  ██████░░░░        │
│  Resets in               3d 4h                           │
├──────────────────────────────────────────────────────────┤
│  ● Monthly limit  $22.10 / $60.00  37%  ███░░░░░░░       │
│  Resets in               12d                             │
└──────────────────────────────────────────────────────────┘

  Manage your plan at https://opencode.ai/go

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add a new `opencode usage` command that lets users proactively check
their OpenCode Go subscription usage (5-hour, weekly, and monthly
limits) without having to hit a rate limit first.

Server-side: new GET /zen/go/v1/usage endpoint that authenticates
via the API key and returns current usage data with percentages and
reset times for each limit window.

CLI-side: new `opencode usage` command that calls the endpoint and
displays a formatted usage summary with progress bars.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
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)

2 participants