openclaw - 💡(How to fix) Fix Context usage % display bug: cumulative cacheRead/cacheWrite divided by context window size instead of current conversation tokens [2 comments, 2 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#72321Fetched 2026-04-27 05:31:36
View on GitHub
Comments
2
Participants
2
Timeline
3
Reactions
0
Timeline (top)
commented ×2closed ×1

The session status card shows context usage as 999%+ (e.g. 📚 Context: 2.1m/200k (999%)), which is impossible and misleading.

Root Cause

The status card is computing context usage as:

(cacheRead + cacheWrite) / contextWindowSize
  • cacheRead (2,081,874) + cacheWrite (19,107) = 2,100,981 — cumulative cached tokens served across all API calls in the session lifetime
  • contextTokens (200,000) = the model's context window size (a constant), not current usage

The result is 2.1M / 200k = ~999%, which is meaningless.

Code Example

(cacheRead + cacheWrite) / contextWindowSize
RAW_BUFFERClick to expand / collapse

Summary

The session status card shows context usage as 999%+ (e.g. 📚 Context: 2.1m/200k (999%)), which is impossible and misleading.

Root Cause

The status card is computing context usage as:

(cacheRead + cacheWrite) / contextWindowSize
  • cacheRead (2,081,874) + cacheWrite (19,107) = 2,100,981 — cumulative cached tokens served across all API calls in the session lifetime
  • contextTokens (200,000) = the model's context window size (a constant), not current usage

The result is 2.1M / 200k = ~999%, which is meaningless.

Expected Behaviour

Context usage % should reflect the current conversation's token count relative to the context window — not cumulative cache reads.

Actual Behaviour

After a long-running session with many API calls (all highly cached), the status card shows e.g. Context: 2.1m/200k (999%), causing users to believe conversations are hitting context limits when they are not. The actual system prompt in this session was ~46,508 chars (~11k tokens).

Environment

  • OpenClaw: 2026.4.24 (cbcfdf6)
  • Model: claude-cli/claude-sonnet-4-6 (Sonnet 4.6, 200k window)
  • sessions.json keys affected: cacheRead, cacheWrite, contextTokens
  • Relevant file: internal-Difqhfo-.js (status card rendering)

extent analysis

TL;DR

Update the status card computation to reflect the current conversation's token count relative to the context window size.

Guidance

  • Review the internal-Difqhfo-.js file to identify where the context usage is calculated and update the formula to use the current conversation's token count instead of cumulative cache reads.
  • Consider adding a new variable to track the current conversation's token count and use this value in the context usage calculation.
  • Verify that the contextTokens value is being used correctly and not being overwritten or modified elsewhere in the code.
  • Test the updated calculation with various session scenarios to ensure accuracy.

Example

// Pseudo-code example, actual implementation may vary
const currentConversationTokenCount = getConversationTokenCount(); // implement this function to get the current conversation's token count
const contextWindowSize = 200000; // model's context window size
const contextUsage = (currentConversationTokenCount / contextWindowSize) * 100;

Notes

The provided information suggests that the issue is specific to the status card rendering in the internal-Difqhfo-.js file, and updating the calculation should resolve the issue. However, further testing and verification are necessary to ensure the fix works as expected.

Recommendation

Apply workaround: update the status card computation to reflect the current conversation's token count relative to the context window size, as this directly addresses the root cause of the issue.

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 Context usage % display bug: cumulative cacheRead/cacheWrite divided by context window size instead of current conversation tokens [2 comments, 2 participants]