Skip to content

Agents widget ignores Anthropic usage from opencode v2 (only reads legacy message table) #13893

Closed

Description

@brsnippe

System details

Intel i7-1260P, Intel Iris Xe (Alder Lake-P), Omarchy 4.0.4-1, opencode v2.0.20

What's wrong?

omarchy-agent-usage-claude is meant to count Claude usage from opencode sessions on the anthropic provider (scan_opencode_usage). With opencode v2 none of it gets counted: the Claude record shows no opencode tokens, even after omarchy agent usage update --force.

Cause

scan_opencode_usage only reads the legacy v1 table and expects the v1 row shape (data.role == "assistant", top-level data.providerID / data.modelID):

conn.execute("SELECT session_id, data FROM message")

opencode v2 writes messages to session_message instead, and the shape is different:

  • The role is in the type column ('assistant'), not in data.role.
  • Provider and model are nested: data.model.providerID and data.model.id (plus variant).
  • data.tokens has the same shape as before (input, output, reasoning, cache.read, cache.write), and data.time.created is still in ms.

Example session_message.data for an assistant row (with content removed):

{
  "model": { "id": "claude-opus-5-5", "providerID": "anthropic", "variant": "xhigh" },
  "tokens": { "input": 4, "output": 96, "reasoning": 775, "cache": { "read": 0, "write": 50180 } },
  "time": { "created": 1790787150779, "streamed": 1790787167692, "completed": 1790787171768 }
}

In ~/.local/share/opencode/opencode.db on this machine:

  • message (legacy): 67 rows, none of them on anthropic, so the scan finds nothing.
  • session_message (v2): 20 assistant rows on anthropic / claude-opus-5-5 (~1.14M cache-read, ~72K cache-write, ~5.4K output and ~3.2K reasoning tokens). None of these show up in the panel.

session_v2 also has per-session totals (tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, tokens_cache_write) and a model JSON column, if those are easier to use.

Steps to reproduce

  1. Use opencode v2 with the Anthropic provider (Claude subscription login) for a few prompts.
  2. Run omarchy agent usage update --force.
  3. Open the Agents panel, or look at ~/.local/state/omarchy/agents/usage/claude.json. None of the opencode tokens appear under "Tokens by day" or "Tokens by model", and they aren't included in totalPrompts.

Expected

opencode v2 Anthropic messages are counted the same way v1 messages are.

Side effect: if opencode v2 is the only Claude client in use and Claude Code's own sign-in has lapsed (so there are no limits), the Claude record has no data at all and the Agents icon disappears from the bar completely.

Possible fix

Also read session_message when it exists (WHERE type = 'assistant', provider from data.model.providerID, model from data.model.id). Keep the message scan for v1 databases.

Checked against master: bin/omarchy-agent-usage-claude still only queries FROM message (line 476).

Activity

  1. jandrusk commented on Oct 1, 2026

    @jandrusk

    Clear diagnosis. Fix PR already open: #13894 (“Count Claude usage from opencode v2 sessions”) — reads session_message, normalises the v2 shape, and keys v2 sessions as opencode-v2:<id>. Suggest linking / closing this issue when #13894 merges.

  2. omarchybot commented on Oct 4, 2026

    @omarchybot
    Collaborator

    The opencode v2 Claude-usage fix from #13894 was incorporated into #14049, now merged into quattro. The collector reads session_message rows and their nested provider/model fields, so the reported Anthropic usage is counted again. This report is already closed; this records the landed replacement for the original fix PR.

    Closure scope checked by GPT-6 in Codex and Codex Medium against the reports and landed source. The second opinion agreed; independence is not guaranteed. No runtime tests were rerun for this reconciliation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions