Skip to content

OpenCode usage double-counts turns that OpenCode runs through Claude Code (claude-agent) #46303

Backlog

Description

@scoizzle

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. In OpenCode, use a model from its claude-agent provider (it runs the Claude Code CLI on your Claude subscription), e.g. claude-agent/sonnet.
  2. Allow both OpenCode and Claude Code in T3 Code's Usage access.
  3. Open Usage and compare the OpenCode and Claude Code totals for the same period.

Expected behavior

Each turn is counted once. These turns run the real Claude Code CLI on the Claude subscription, so they belong under Claude Code.

Actual behavior

Each turn is counted twice: once by the OpenCode reader from opencode.db (rows with providerID: "claude-agent") and once by the Claude Code reader from Claude Code's own transcript in ~/.claude/projects, where the lines are tagged "entrypoint":"opencode".

On my machine, from Nov 29 to now there were 59 claude-agent assistant messages in opencode.db and 59 distinct Claude Code assistant messages tagged entrypoint: "opencode", a one-for-one match. Over all history there are ~53k claude-agent messages in opencode.db.

Impact

Token and cost totals for anyone routing Claude Code through OpenCode are inflated by the full size of that usage, and the same work appears under two providers.

Version or commit

v0.1.13 (stable)

Environment

macOS 27.2.1, desktop app. OpenCode with claude-agent, opencode-go, opencode and xai providers.

Logs or stack traces

Counts above came from read-only queries:

-- opencode.db
SELECT count(*) FROM session_message
WHERE json_extract(data,'$.model.providerID')='claude-agent' AND time_created >= <since>;

and counting distinct message.id on "type":"assistant" lines containing "entrypoint":"opencode" in ~/.claude/projects/**/*.jsonl over the same window.

Workaround

None in the UI; mentally subtract the claude-agent rows from OpenCode.

Activity

  1. scoizzle commented on Nov 30, 2026

    @scoizzle
    Author

    Note

    🤖 Claude Opus 5.5 responding on behalf of @scoizzle

    A fix is ready on my fork: scoizzle#2 (one commit on top of current main).

    The OpenCode usage reader skips claude-agent messages, because Claude Code's own transcript already records those turns. The usage scan cache is bumped so OpenCode records that were cached earlier get re-read. The new reader test fails without the change. I can open it here as a PR if you'd like.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions