openclaw - 💡(How to fix) Fix Control UI: context token counter inflates to >4× window (claude-cli) — cacheRead summed as fresh input [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#68794Fetched 2026-04-19 15:07:22
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
subscribed ×1unsubscribed ×1

The Control UI context/token indicator reports values far exceeding the model's context window (observed: ~800k shown against a 200k Opus 4.7 window) after a handful of cache-hit turns on the claude-cli provider path.

Root Cause

dist/status-D-R7Q_A-.js contains the formula:

totalTokens ?? input + cacheRead + cacheWrite

cacheRead represents tokens the model read from the prompt cache on a given turn — it is already part of the cached prefix, not new context being added on top. Summing input + cacheRead + cacheWrite turn after turn produces a running total rather than the actual window-resident token count.

Code Example

totalTokens ?? input + cacheRead + cacheWrite

---

openclaw agent --json --agent main -m "ping" --timeout 60
RAW_BUFFERClick to expand / collapse

Summary

The Control UI context/token indicator reports values far exceeding the model's context window (observed: ~800k shown against a 200k Opus 4.7 window) after a handful of cache-hit turns on the claude-cli provider path.

Version

  • OpenClaw 2026.4.19-beta.1 (4862d34)
  • Primary model: claude-cli/claude-opus-4-7
  • Host: macOS 15.x, Node 25.4.0

Root cause

dist/status-D-R7Q_A-.js contains the formula:

totalTokens ?? input + cacheRead + cacheWrite

cacheRead represents tokens the model read from the prompt cache on a given turn — it is already part of the cached prefix, not new context being added on top. Summing input + cacheRead + cacheWrite turn after turn produces a running total rather than the actual window-resident token count.

Repro (minimal)

With a heavy system prompt + plugins (e.g. lossless-claw, openclaw-mem, memory-wiki):

openclaw agent --json --agent main -m "ping" --timeout 60

Observed usage for a 6-token user message: input: 6, output: 6, cacheRead: 20566, cacheWrite: 35458.

Four–five such turns and the UI indicator exceeds 200k despite the true live prompt staying well under the window.

Relationship to #64669

Fix #64669 landed in 2026.4.19-beta.1 for the Codex path ("stop cumulative app-server token totals from being treated as fresh context usage"). The same class of bug exists on the claude-cli path and was not addressed.

Suggested fix

Either:

  • Display input + cacheWrite (cacheRead is not additive), or
  • Surface cache_read_input_tokens as a separate read-only metric and exclude it from the contextTokens/percent calculation.

Impact

Operators cannot rely on the UI counter to decide whether to compact / rotate sessions; lossless-claw's contextThreshold is judged against a grossly inflated figure.

extent analysis

TL;DR

The most likely fix is to update the totalTokens calculation to input + cacheWrite, excluding cacheRead to accurately reflect the context window.

Guidance

  • Review the dist/status-D-R7Q_A-.js file and update the totalTokens formula to input + cacheWrite to prevent cumulative addition of cacheRead tokens.
  • Verify the fix by running the repro command and checking the UI indicator values after multiple turns.
  • Consider surfacing cache_read_input_tokens as a separate metric to provide a more accurate representation of context usage.
  • Test the updated calculation with different input scenarios to ensure it accurately reflects the context window.

Example

totalTokens = input + cacheWrite;

This updated formula excludes cacheRead and should provide a more accurate representation of the context window.

Notes

The suggested fix assumes that the cacheRead value is not intended to be additive, as it represents tokens read from the prompt cache. The updated calculation may still have limitations, and further testing is recommended to ensure its accuracy.

Recommendation

Apply the workaround by updating the totalTokens calculation to input + cacheWrite, as this should provide a more accurate representation of the context window and address the issue with the UI indicator.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Control UI: context token counter inflates to >4× window (claude-cli) — cacheRead summed as fresh input [1 participants]