Repository navigation
fix(unified): count OpenCode Claude Agent turns once - #2005
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Co-authored-by: igorovh <[email protected]>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ccusage-guide | ccfaff6 | Commit Preview URL Branch Preview URL |
Nov 01 2026, 12:24 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the accepted fix for #2004: unified reports count OpenCode
claude-agentturns once, on the Claude side.What changed:
rust/adapters/opencode/src/parser.rs:OpenCodeV2Messagenow parsescontent[].native.sessionID, gated on theclaude-agentprovider;session_message_value_to_entryreturns the linked ids alongside the entry so the loader filters without a second parse.rust/adapters/opencode/src/loader.rs: newload_entries_for_unifiedskips v2 rows whose native session has a Claude transcript on disk. Skipped sessions still count as covered, within the same database and across data directories, so the cumulativesession_v2aggregate cannot bring the usage back. Without a transcript the rows stay. Focusedccusage opencodekeeps every row via the unchangedload_entries.rust/adapters/claude/src/paths.rs: new publictranscript_session_idsreporting modern<project>/<session>.jsonlstems, failing open (legacyagent-*.jsonlcopies, nested paths, non-UTF-8 paths, and unreadable config dirs are left out so usage is kept, never dropped on a guess).rust/crates/ccusage-adapter-all/src/loader.rs: unified OpenCode spec loads throughload_entries_for_unified, honoring the sameclaude_projectfilter as the Claude side.Scope notes: the legacy
messagetable andstorage/message/*.jsonfallback are untouched (they predate the v2-onlyclaude-agentprovider); the reportedopusalias overpricing and the unrelated session-window/Windows issues from the thread are out of scope.Tests:
transcript_session_idstests, and an end-to-end unifieddailytest (Claude 100 in + OpenCode 50 in counted, 100-token duplicate and its cost skipped).cargo fmt --checkclean,cargo clippy --all-targetsclean (CI gates on-D warnings), fullcargo test --workspace: 63 suites, all passing.CCUSAGE_PRICING_JSON_PATHpointed at the flake-lock-pinned LiteLLM snapshot downloaded once to/tmp.Changes are left uncommitted in the working tree as instructed.
Closes #2004
Summary by cubic
Fixes unified reports double-counting OpenCode
claude-agentturns. The provider runs Claude Code under the hood, so each turn was stored twice: in OpenCode's database and in Claude Code's own transcript. Unified reports now skip the OpenCode copy when the transcript is on disk, counting the turn once, on the Claude side — which also carries the resolved model id that OpenCode'sopusalias lacks.session_v2aggregate cannot bring the usage back.ccusage opencodekeeps every row, and when a transcript is gone the OpenCode rows are counted instead, so no usage disappears.claude-agentrows with acontent[].native.sessionID; legacymessage-table rows and other providers are unaffected.Written for commit ccfaff6. Summary will update on new commits.