Skip to content

feat: add opencode usage tracking plugin#6145

Open
JJDizz1L wants to merge 2 commits into
basecamp:quattrofrom
JJDizz1L:feat/opencode-model-usage
Open

feat: add opencode usage tracking plugin#6145
JJDizz1L wants to merge 2 commits into
basecamp:quattrofrom
JJDizz1L:feat/opencode-model-usage

Conversation

@JJDizz1L

Copy link
Copy Markdown

OpenCode Usage — Omarchy Bar Widget
Tracks OpenCode AI coding assistant usage (sessions, tokens, models) directly in the Omarchy Quickshell Bar.
Queries OpenCode's local SQLite database — no API keys, no data leaves machine.

Features

  • Bar chip — Shows today's token count with the OpenCode icon; click for a full popup.
  • Today — Sessions and token totals for the current day, broken down by model.
  • Last 7 Days — Bar chart of daily token usage.
  • All-Time — Per-model input, output, cache-read, and cache-write token counts.
  • Settings — Configurable refresh interval (30–3600s), matches other built-in models plugin.
  • No external dependencies — Scans ~/.local/share/opencode/opencode.db directly.
  1. omarchy-shell shell rescanPlugins
  2. omarchy config shell bar add omarchy.opencode-model-usage left|center|right
image

Copilot AI review requested due to automatic review settings June 28, 2026 01:59

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 a new first-party Omarchy shell bar widget plugin (omarchy.opencode-model-usage) that reads OpenCode’s local SQLite DB and surfaces token/session usage in the Quickshell bar + popup UI.

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.

Changes:

  • Introduces the opencode-model-usage plugin (manifest + icon) and a full Widget popup UI with settings.
  • Adds a Quickshell provider that runs a Python scanner and maps results into the widget’s expected fields.
  • Adds a Python SQLite scanner that summarizes today / recent 7 days / all-time per-model token usage.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
shell/plugins/opencode-model-usage/Widget.qml Bar chip, popup UI (today/7-day/all-time), settings UX, IPC handlers.
shell/plugins/opencode-model-usage/Main.qml Wires settings + refresh timer and exposes display-provider data to the widget.
shell/plugins/opencode-model-usage/providers/Opencode.qml Provider implementation that watches the DB file and runs the scanner process.
shell/plugins/opencode-model-usage/scripts/opencode_usage_scanner.py Reads OpenCode SQLite session table and emits compact JSON usage summary.
shell/plugins/opencode-model-usage/manifest.json Declares plugin metadata, bar-widget schema, and defaults.
shell/plugins/opencode-model-usage/assets/opencode.svg OpenCode icon asset used by the chip/header.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +330 to +333
spacing: Style.space(8)
UsageChip { visible: !root.vertical }
EmptyUsageChip { visible: !root.vertical && !provider }
}
Comment on lines +339 to +342
spacing: Style.space(2)
UsageChip { visible: root.vertical }
EmptyUsageChip { visible: root.vertical && !provider }
}
spacing: 10

Text {
visible: !root.settingsMode && !root.provider

component WeekCard: SectionCard {
property var provider: null
visible: !!provider && provider.recentDays && provider.recentDays.length > 0
RowLayout {
Layout.fillWidth: true
spacing: 20
StatBlock { value: provider ? String(provider.todayPrompts || 0) : "0"; label: "sessions" }
Comment on lines +9 to +17
BarWidget {
id: root
moduleName: "omarchy.opencode-model-usage"

property bool popupOpen: false
property bool settingsMode: false
property var draftSettings: ({})
property string settingsStatusText: ""
property bool refreshFlash: false
Comment on lines +50 to +56
FileView {
id: dbFile
path: root.resolvePath(root.dbPath)
watchChanges: true
onFileChanged: reload()
onLoaded: root.refresh(false)
}
Comment on lines +99 to +101
} catch (e) {
console.error("model-usage/opencode", "Failed to parse scanner output:", e)
}
return empty_result()

try:
conn = sqlite3.connect(str(db_path))
ORDER BY time_created DESC
""")

for row in cursor.fetchall():
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.

2 participants