Skip to content

fix(claude-code): show model thinking and cache reads, price cache reads in agent configs - #162

Closed
Siddhesh2377 wants to merge 1 commit into
mainfrom
fix/translator-thinking-cache
Closed

Siddhesh2377 wants to merge 1 commit into
mainfrom
fix/translator-thinking-cache

Conversation

@Siddhesh2377

@Siddhesh2377 Siddhesh2377 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #99.

Claude Code now shows the model's thinking and reports cache reads in its usage. OpenCode, OpenClaw and Prime Agent now get the cache-read price, so a cached prompt costs what it should in their cost display.

Tested manually on prod: Claude Code over two turns (thinking shown, cache reads reported), and OpenCode's cost display.


Summary by cubic

Fixes Claude Code translation so model reasoning surfaces as thinking blocks and cache reads are reported, priced, and not double-counted.

  • Streams reasoning as an unsigned thinking block; text closes it and vice versa.
  • Cache reads move from input_tokens to cache_read_input_tokens, keeping the total unchanged.
  • OpenCode, OpenClaw, and Prime Agent configs now use the catalog's cached-input price.

Written for commit eda5afe. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Reasoning content now appears as thinking blocks in Anthropic responses, including streamed responses.
    • OpenCode, OpenClaw, and Prime Agent cost displays now include catalog-provided cache-read pricing when available.
  • Bug Fixes
    • Anthropic usage reporting now accounts for cached input tokens without double-counting them as regular input.
    • Claude Code documentation clarifies unsigned thinking blocks and cache-token reporting.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: a3f65352-0eab-4772-93ea-d04569c50861

📥 Commits

Reviewing files that changed from the base of the PR and between 6e349cb and eda5afe.

📒 Files selected for processing (10)
  • docs/EDITORS.md
  • src/account/console.rs
  • src/anthropic/translate.rs
  • src/harness/agents.rs
  • src/harness/catalog_models.rs
  • src/harness/opencode.rs
  • tests/cpp_case_exceptions.txt
  • tests/test_wally_harness.rs
  • tests/test_wally_opencode.rs
  • tests/test_wally_unit/shim.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The changes add Anthropic thinking blocks for reasoning content and translate cached-token usage without double-counting it as input. They also carry cached-input prices from the model catalog into OpenClaw, Prime Agent, and OpenCode cost configurations.

Changes

Reasoning and cached-token support

Layer / File(s) Summary
Anthropic reasoning and usage translation
src/anthropic/translate.rs, tests/test_wally_unit/shim.rs, tests/cpp_case_exceptions.txt
Streaming and non-streaming responses emit nonempty reasoning content as thinking blocks. Usage translation subtracts reported cached tokens from input tokens and reports them as cache-read usage. Tests cover block ordering and closure, output-token estimation, and cached-token cases.
Catalog pricing and harness configurations
src/harness/catalog_models.rs, src/account/console.rs, src/harness/agents.rs, src/harness/opencode.rs, tests/test_wally_harness.rs, tests/test_wally_opencode.rs, docs/EDITORS.md
Catalog models carry cached-input prices into OpenClaw, Prime Agent, and OpenCode cost configurations. Tests check the resulting prices and omission of zero-priced cache-read fields. The editor documentation describes the reasoning and cache-reporting behavior.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: sanchitmonga22

Merge Risk: ⚪ Minimal · up to eda5a

This change shows model thinking and cache reads in Claude Code and adds cache-read pricing to OpenCode, OpenClaw, and Prime Agent cost displays. No concrete merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to eda5a

The reviewed changes do not show expanded access or privileges. Remaining uncertainty concerns client handling of unsigned reasoning content and interrupted responses.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly evidenced exposure is additional reasoning content within each translated response and changed cost metadata across three client configurations. The traced paths do not connect the new fields to cross-request state, credential selection or increased tool authority.

Trust Boundaries and Controls

  • observed — The catalog fetch retains token validation, the existing console-origin calculation, a fixed catalog endpoint and response-contract parsing. Its PR change copies an additional numeric price field without changing those controls.

Resilience and Maintainability Implications

  • observed — Terminal stream errors do not emit content-block stop events. This predates the PR for text blocks; the new thinking blocks inherit that behavior. Subsequent translation is suppressed, but downstream requirements for error-time block closure remain unspecified.

Hardening Proposals

  • proposed — Document that translated thinking content is unsigned, untrusted output, and confirm supported clients neither treat it as verified provenance nor derive execution authority from it.
🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 8 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The implementation maps non-empty reasoning_content to Anthropic thinking blocks, closes thinking/text blocks during streaming, and separates cached_tokens from input_tokens with clamping. The r… Provide reviewable evidence for the #99 streaming and non-streaming reasoning and cache fixtures, including absent fields, fragmented deltas, and zero counts. Confirm the documented unsupported fields and backend billing independence agains…
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: Claude Code thinking and cache-read display, plus cache-read pricing in agent configurations.
Out of Scope Changes check ✅ Passed The changes stay within #99. Translator changes implement reasoning and cache-read translation. Catalog and harness changes apply cache-read pricing to OpenCode, OpenClaw, and Prime Agent. Documentati…
Full details: Linked Issues check

Explanation

The implementation maps non-empty reasoning_content to Anthropic thinking blocks, closes thinking/text blocks during streaming, and separates cached_tokens from input_tokens with clamping. The reviewed tests cover streamed reasoning and cached-token present, absent, and zero values. The available evidence does not establish the full #99 fixture matrix for both streaming and non-streaming responses, including fragmented deltas. The documentation states that cache writes are unsupported, and no backend billing change is shown, but complete acceptance coverage cannot be confirmed.

Resolution

Provide reviewable evidence for the #99 streaming and non-streaming reasoning and cache fixtures, including absent fields, fragmented deltas, and zero counts. Confirm the documented unsupported fields and backend billing independence against the complete test and implementation changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 8 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Siddhesh2377

Copy link
Copy Markdown
Collaborator Author

Merged into #160.

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.

Define reasoning and cached-token translation for cloud harness adapters

1 participant