Skip to content

fix(opencode): Claude Code turns run through OpenCode count once - #2

Open
scoizzle wants to merge 1 commit into
mainfrom
fix/opencode-claude-code-double-count
Open

scoizzle wants to merge 1 commit into
mainfrom
fix/opencode-claude-code-double-count

Conversation

@scoizzle

@scoizzle scoizzle commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Problem

OpenCode's claude-agent provider runs the Claude Code CLI on the user's Claude subscription. Claude Code writes its own transcript for each of those turns, tagged "entrypoint":"opencode", and T3's Claude Code usage reader counts it. The OpenCode reader also counted the same turn from opencode.db, so every one of those turns appeared twice in Usage: once under Claude Code and once under OpenCode.

Change

  • The OpenCode usage reader skips messages whose providerID is claude-agent, so these turns count once, under Claude Code.
  • The usage scan cache moves to v19, and OpenCode entries cached by v18 are treated as legacy, so records that were already cached for claude-agent are re-read and dropped.
  • docs/user/usage.md gets one line saying these turns count under Claude Code.

Nothing else changes in how OpenCode records are keyed or priced.

Scope

Bug fix for pingdotgg#46303.

Verification

How I found it: on my machine (v0.1.13, macOS), I compared the two sources from Nov 29 onward. 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.

Checks:

  • packages/provider-opencode/src/server/usage.test.ts: a database holding a claude-agent message and an anthropic message now yields only the anthropic record. With the reader change reverted, this test fails.
  • apps/server/src/usage/usageScanCache.test.ts: a v18 OpenCode cache entry decodes as legacy and is re-read; a v19 entry round-trips unchanged.
  • vp run typecheck passes, and vp run check:changed passes format, lint, knip and typecheck.
  • Three apps/server/src/usage/UsageService.test.ts tests fail on macOS (Muse home discovery, Pi default home, Codex reconciliation). They fail the same way on main without this change.

Created with DeepSeek V4.1 Flash in OpenCode (implementation and verification), directed by Claude Opus 5.5 in Claude Code via T3 Code.

OpenCode's claude-agent provider runs the real Claude Code executable,
which writes its own transcript for the turn and is already counted by the
Claude usage reader. Parsing the matching OpenCode row as well counted the
same turn twice, so skip claude-agent messages there and bump the scan
cache to v19 so entries saved with those rows are re-read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant