Skip to content

feat: Add option to fold reasoning tokens into output - #142

Merged
dialupdisaster merged 1 commit into
mainfrom
feat/combine-reasoning-tokens
Nov 10, 2026
Merged

dialupdisaster merged 1 commit into
mainfrom
feat/combine-reasoning-tokens

Conversation

@dialupdisaster

Copy link
Copy Markdown
Contributor

Description

OpenCode V2 reports tokens.output with reasoning subtracted (Usage.visibleOutputTokens = outputTokens - reasoningTokens), whereas Claude Code reports thinking tokens inside output. Dashboards and cost pipelines built for Claude Code telemetry therefore undercount OpenCode output, and anything summing every token type sees an unfamiliar reasoning type.

This adds an opt-in combineReasoningTokens option / OPENCODE_COMBINE_REASONING_TOKENS env var. When enabled:

  • token.usage emits type=output as output + reasoning and no longer emits type=reasoning (so sums never double-count)
  • api_request log output_tokens includes reasoning; reasoning_tokens is omitted
  • LLM span llm.token_count.completion includes reasoning; llm.token_count.completion_details.reasoning still carries the subset, per OpenInference semantics
  • Session totals and llm.token_count.total are unchanged (they already include reasoning once)

Default behaviour is unchanged.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Chore (dependency updates, etc.)

Checklist

  • I have read the CONTRIBUTING.md document
  • My code follows the style guidelines of this project
  • bun run lint passes with no errors
  • bun run check:jsdoc-coverage passes with no errors
  • bun run typecheck passes with no errors
  • bun test passes with no errors
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • My commits follow the Conventional Commits specification

Related issues

None.

Additional context

Found while comparing OpenCode and Claude Code usage of the same Bedrock model in Datadog: OpenCode users had a reasoning token type and lower output counts than Claude Code users.

OpenCode V2 reports output with reasoning subtracted, while Claude Code
includes thinking in output. OPENCODE_COMBINE_REASONING_TOKENS (or the
combineReasoningTokens option) restores Claude Code semantics for the
token.usage metric, api_request log, and LLM span completion count.
@dialupdisaster dialupdisaster changed the title Add option to fold reasoning tokens into output feat: Add option to fold reasoning tokens into output Nov 10, 2026
@dialupdisaster
dialupdisaster merged commit cb97f31 into main Nov 10, 2026
9 of 12 checks passed
dialupdisaster pushed a commit that referenced this pull request Nov 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.1.0](v2.0.1...v2.1.0)
(2026-11-10)


### Features

* Add option to fold reasoning tokens into output
([#142](#142))
([cb97f31](cb97f31))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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