Skip to content

DRU-1147 -- Count an opencode or pi call's cached input and reasoning tokens in its token totals - #1170

Open
p-r-a-v-i-n wants to merge 1 commit into
czpython:mainfrom
p-r-a-v-i-n:dru-1147-opencode-pi-token-counts
Open

p-r-a-v-i-n wants to merge 1 commit into
czpython:mainfrom
p-r-a-v-i-n:dru-1147-opencode-pi-token-counts

Conversation

@p-r-a-v-i-n

Copy link
Copy Markdown
Collaborator

An opencode or pi call now counts its cached input tokens in its input and total token counts, and an opencode call counts its reasoning tokens in its output. Before, both calls fell through to the generic branch of normalize_token_usage, which treats input_tokens as already including cache tokens. So the readers of those counts, such as the Usage page and the MCP gateway, showed only the uncached input, and a total that left out the cache tokens.

  • normalize_token_usage gets an opencode and pi branch. Input is input_tokens + cached_input_tokens + cache_creation_tokens. opencode reports output without its reasoning tokens, so its output adds reasoning_tokens. pi's output already includes them.
  • The harnesses keep writing the CLI's own figures, the same way the Claude harness does. The fix is on the read side, so calls that are already stored show the corrected counts too.
  • Cost does not change. Each CLI reports its own cost.

@p-r-a-v-i-n
p-r-a-v-i-n marked this pull request as draft November 10, 2026 14:35
@p-r-a-v-i-n p-r-a-v-i-n changed the title DRU-1147 -- Count an opencode or pi call's cached input and reasoning… DRU-1147 -- Count an opencode or pi call's cached input and reasoning tokens in its token totals Nov 10, 2026
@p-r-a-v-i-n
p-r-a-v-i-n marked this pull request as ready for review November 10, 2026 15:31

This branch has not been deployed

No deployments
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