Skip to content

Add OpenCode Go usage collector for the agents panel - #8065

Closed
rechedev9 wants to merge 1 commit into
omacom:quattrofrom
rechedev9:agents/opencode-go-usage
Closed

rechedev9 wants to merge 1 commit into
omacom:quattrofrom
rechedev9:agents/opencode-go-usage

Conversation

@rechedev9

Copy link
Copy Markdown

Summary

Adds omarchy-agent-usage-opencode-go, a new agent-usage collector for the OpenCode Go subscription, so the built-in Agents bar panel can show it alongside Claude Code, Codex and Fireworks.

No widget code changes are needed: the updater globs omarchy-agent-usage-* and the panel displays any record that lands in the usage directory, per the plugin's own contract.

What it does

  • Local stats — scans ~/.local/share/opencode/opencode.db for assistant messages routed through the opencode-go provider (same json_extract acceleration + exact-match filter used by the codex collector), counting input / output / reasoning / cache tokens per model and per day.
  • Limits — queries OpenCode's public Zen API GET https://opencode.ai/zen/go/v1/usage (rolling 5h, weekly, monthly windows, percent used + reset time) using the key opencode stores in ~/.local/share/opencode/auth.json (opencode-go entry) or OPENCODE_API_KEY.
  • Follows the existing collector conventions: omarchy:* headers, versioned cache envelope with scanDate, --force / --limits-only, graceful fallback to local stats when unsigned or the endpoint is unreachable.

Tests

Adds test/shell.d/agent-usage-opencode-go-scanner-test.sh covering:

  • token accounting (reasoning included) from opencode sessions filtered to opencode-go
  • ignoring prefix-colliding providers, user messages, and malformed rows
  • empty limits list when unsigned (offline)
  • cache write, readability, versioned envelope, and corrupt-cache recovery

Verified locally against a real opencode DB + live API.

Docs

Adds a row to the Agents plugin README collector table plus a note on where OpenCode Go reads its credentials.

Ships omarchy-agent-usage-opencode-go, a new agent-usage collector that
appears automatically in the agents widget (the update command globs
omarchy-agent-usage-* and the panel picks up any record that lands in the
usage directory).

Local stats come from the opencode session database, filtered to the
opencode-go provider; usage windows (rolling 5h, weekly, monthly) come from
OpenCode's public Zen API using the key stored in opencode's auth store.
Copilot AI balanced review requested due to automatic review settings August 24, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds OpenCode Go usage and subscription-limit collection to the Agents panel.

Changes:

  • Adds local SQLite usage scanning and Zen API limit collection.
  • Adds scanner and cache-recovery tests.
  • Documents the new provider and credentials.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
bin/omarchy-agent-usage-opencode-go Implements the collector, caching, authentication, and API integration.
test/shell.d/agent-usage-opencode-go-scanner-test.sh Tests local scanning and cache recovery.
shell/plugins/agents/README.md Documents OpenCode Go support and configuration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

kczimm added a commit to kczimm/omarchy that referenced this pull request Aug 28, 2026
Adds native support for OpenCode Go subscriptions in the agents panel.
Queries OpenCode's official /zen/go/v1/usage API for rolling (5h),
weekly, and monthly limit usage with reset timers.

Unique features compared to other PRs (omacom#7157, omacom#8065, omacom#6526, omacom#6779, omacom#6464):
- Pi session scanning for local token stats
- Harness-agnostic key discovery (Pi, OpenCode CLI, env var)
- Account-scoped metadata (scope, hasPromptStats)

Key design decisions:
- Uses curl instead of urllib to bypass Cloudflare TLS fingerprinting
- Includes light/dark icon variants matching OpenCode brand colors
- Adds test coverage for auth lookup, API parsing, and error handling
@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@dhh

dhh commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thanks! OpenCode Go usage is coming in through #14040, which builds on #13548 and #12651. Closing in favor of that.

@dhh dhh closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants