Skip to content

Add OpenCode Zen usage to the agents panel - #7765

Closed
itissdr wants to merge 6 commits into
omacom:quattrofrom
itissdr:feature/zen-agent-usage
Closed

itissdr wants to merge 6 commits into
omacom:quattrofrom
itissdr:feature/zen-agent-usage

Conversation

@itissdr

@itissdr itissdr commented Aug 22, 2026

Copy link
Copy Markdown

Summary

Add an opencode-zen collector to the agents panel for local OpenCode Zen token usage.

The collector reads Zen activity from OpenCode's SQLite database and from Pi/OMP sessions using the opencode provider. It aggregates usage by local day and model, while keeping Pi and OMP models identifiable in the panel.

The panel presents this as OpenCode with the tier Zen · Pay as you go.

Why a separate Zen collector?

Zen and Go have different billing models and provider identifiers:

Zen Go
Billing Pay as you go Subscription
Provider ID opencode opencode-go
Collector ID opencode-zen opencode-go

Exact provider matching keeps this compatible with a dedicated Go collector without double counting.

OpenCode does not currently expose a supported API-key-authenticated Zen balance endpoint, so this collector intentionally reports local token statistics only. It does not read credentials or call private endpoints.

This overlaps with the Zen portion of #6526, but is intentionally narrower now that Go has an official limits endpoint and dedicated work in #6779. This PR contains no Go collection or limits code.

Collection behavior

  • Reads classic OpenCode messages from ~/.local/share/opencode/opencode.db where providerID == "opencode".
  • Reads current session_message rows, where the provider is stored as model.providerID.
  • Reads assistant messages from ~/.pi/agent/sessions and ~/.omp/agent/sessions using the exact opencode provider.
  • Prefixes externally collected model names with Pi- or Omp- so the consuming harness remains visible.
  • Preserves input, output, cache-read, and cache-write splits, folding separately stored reasoning tokens into generated output.
  • Excludes Go, OpenAI, Anthropic, user, malformed, and zero-token records.
  • Opens SQLite read-only with PRAGMA query_only = ON, supports WAL databases, and never caches an interrupted scan.

Screenshots

Light theme

OpenCode Zen usage in the Omarchy agents panel using a light theme

Dark theme

OpenCode Zen usage in the Omarchy agents panel using a dark theme

Verification

  • bash test/shell.d/agent-usage-opencode-zen-scanner-test.sh — 22 assertions passed
  • bash test/shell.d/agent-usage-update-test.sh — passed
  • bash test/shell.d/agents-panel-test.sh — passed
  • ./test/cli — passed
  • ./test/all — passed on a live-linked Omarchy test machine
  • python3 -m py_compile bin/omarchy-agent-usage-opencode-zen — passed
  • git diff --check — passed
  • Live collector verification against a WAL database containing both message and session_message
  • Visual verification in light and dark themes

All automated fixtures are synthetic. No API keys, prompt content, account identifiers, or raw user messages are included in the tests or screenshots.

@itissdr
itissdr marked this pull request as ready for review August 22, 2026 11:47
Copilot AI balanced review requested due to automatic review settings August 22, 2026 11:47

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 local OpenCode Zen token usage to the agents panel, including OpenCode, Pi, and OMP sessions.

Changes:

  • Adds the Zen SQLite/JSONL collector and comprehensive scanner tests.
  • Enables OpenCode Zen by default with light/dark icons.
  • Documents Zen support in plugin and user documentation.

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 4 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
bin/omarchy-agent-usage-opencode-zen Collects and aggregates local Zen usage.
test/shell.d/agent-usage-opencode-zen-scanner-test.sh Tests scanning, filtering, caching, and discovery.
shell/plugins/agents/manifest.json Enables and describes the provider.
shell/plugins/agents/README.md Documents the collector and configuration.
shell/plugins/agents/assets/opencode-zen.svg Adds the dark-surface icon.
shell/plugins/agents/assets/opencode-zen-light.svg Adds the light-surface icon.
manual/17-ai.md Documents OpenCode Zen panel support.

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

@Rattlyy

Rattlyy commented Aug 24, 2026

Copy link
Copy Markdown

Opencode go subscription is supported?

@itissdr

itissdr commented Aug 24, 2026

Copy link
Copy Markdown
Author

Opencode go subscription is supported?
Not in this implementation, I chose a more narrow Zen only implementation that Tries to capture zen usage when using it as the provider for OpenCode or Pi/OMP. Check out #6779 for Go

@dhh

dhh commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thanks! OpenCode Zen usage is covered by the OpenCode collector in #14040. 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.

5 participants