openclaw - 💡(How to fix) Fix [Bug]: TUI footer context bar shows ~10× actual usage due to cumulative totalTokens

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…

Root Cause

Same shape as the previously-fixed Web UI bug in #76059, but in the TUI footer path which wasn't patched.

dist/tui-LVkXuSWn.js:4393 feeds the footer:

const tokens = formatTokens(sessionInfo.totalTokens ?? null, sessionInfo.contextTokens ?? null);

sessionInfo.totalTokens is populated from entry.totalTokens (tui-cli applySessionInfo, ~L3575), which ultimately traces to dist/session-cost-usage-Dn79gKT8.js:620:

totals.totalTokens += usageTotals.totalTokens;

This totals.totalTokens is the cumulative lifetime billable tokens for cost tracking (input + output + cacheRead + cacheWrite summed across every API call in the session). It is correct for the session-cost dashboard, but wrong as a denominator-against-context-window indicator. Each turn re-bills the full prior context as cacheRead, so the cumulative grows ~linearly with turn count.

formatTokens() at tui-LVkXuSWn.js:955 then computes:

const pct = typeof total === "number" && context > 0 ? Math.min(999, Math.round(total / context * 100)) : null;

producing the inflated percentage.

Fix Action

Fix / Workaround

Same shape as the previously-fixed Web UI bug in #76059, but in the TUI footer path which wasn't patched.

Closed analog: #76059 — same bug shape, Web UI _j() accumulator. Patch landed for Web UI; TUI footer wasn't touched.

Code Example

Session tokens (cached): 53,121 total / ctx=1,048,576

---

const tokens = formatTokens(sessionInfo.totalTokens ?? null, sessionInfo.contextTokens ?? null);

---

totals.totalTokens += usageTotals.totalTokens;

---

const pct = typeof total === "number" && context > 0 ? Math.min(999, Math.round(total / context * 100)) : null;
RAW_BUFFERClick to expand / collapse

Bug Description

The TUI footer context indicator (tokens 534K/1.0M (51%)) displays a value ~10× larger than the real current context size. After ~10 turns on a session whose current context is ~50K tokens, the bar reads ~500K and grows linearly with each turn until it crosses 1M and triggers user-perceived "context exhausted" panic.

/context for the same session reports the correct value:

Session tokens (cached): 53,121 total / ctx=1,048,576

TUI footer at the same moment: tokens 534K/1.0M (51%).

Root Cause

Same shape as the previously-fixed Web UI bug in #76059, but in the TUI footer path which wasn't patched.

dist/tui-LVkXuSWn.js:4393 feeds the footer:

const tokens = formatTokens(sessionInfo.totalTokens ?? null, sessionInfo.contextTokens ?? null);

sessionInfo.totalTokens is populated from entry.totalTokens (tui-cli applySessionInfo, ~L3575), which ultimately traces to dist/session-cost-usage-Dn79gKT8.js:620:

totals.totalTokens += usageTotals.totalTokens;

This totals.totalTokens is the cumulative lifetime billable tokens for cost tracking (input + output + cacheRead + cacheWrite summed across every API call in the session). It is correct for the session-cost dashboard, but wrong as a denominator-against-context-window indicator. Each turn re-bills the full prior context as cacheRead, so the cumulative grows ~linearly with turn count.

formatTokens() at tui-LVkXuSWn.js:955 then computes:

const pct = typeof total === "number" && context > 0 ? Math.min(999, Math.round(total / context * 100)) : null;

producing the inflated percentage.

Impact

  • Users see "51%", "82%", "1.1M/1M" on the footer when real usage is single-digit %, panic, hit /new, and lose healthy sessions
  • Drives a perception that auto-compaction is broken when it's actually working fine — /context and lossless-claw maintenance both confirm low real usage in these cases
  • Disproportionately affects long iMessage / cross-channel sessions where turn count is high

Reproduce

  1. Run a TUI session (openclaw) on a 1M-context model (e.g. claude-opus-4-7)
  2. Take ~10 turns of normal work, each ~50K context
  3. Observe the footer rising past 500K, eventually crossing 1M
  4. Run /context in the same session — confirms real usage is small

Expected Behavior

Footer should show current context window usage (latest turn's input + cacheRead + cacheWrite), matching /context's Session tokens (cached) figure.

Possible fixes:

  • Change tui-cli :4393 to use a per-turn field instead of sessionInfo.totalTokens — e.g. sessionInfo.inputTokens + sessionInfo.cacheReadTokens + sessionInfo.cacheWriteTokens if those represent the latest turn
  • Or expose a separate sessionInfo.currentContextTokens field populated from the most recent assistant turn's usage and feed that to formatTokens()
  • Cost dashboard consumers of totals.totalTokens (control-ui session-cost) should be unaffected

Related

Closed analog: #76059 — same bug shape, Web UI _j() accumulator. Patch landed for Web UI; TUI footer wasn't touched.

Environment

  • OpenClaw version: 2026.5.22
  • Model: claude-opus-4-7 (also observed on openai-codex/gpt-5.4 per prior context-overflow log entries)
  • Surface: openclaw TUI footer

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 [Bug]: TUI footer context bar shows ~10× actual usage due to cumulative totalTokens