Skip to content

[Bug] TUI / status-message Context % shows cumulative session usage as numerator (>100%, e.g. 228%) #83526

@darconadalabarga

Description

@darconadalabarga

Summary

The "Context" line in the TUI and /status output reports cumulative
session token usage divided by the model's context window, producing
nonsensical percentages like 2.3m/1.0m (228%) even with Compactions: 0
and no actual context overflow. This is the same root cause as #55217
(closed for Web UI) but the fix did not propagate to the
status-message-*.js path used by TUI and channel status cards.

Example status output

🦞 OpenClaw 2026.5.12 (f066dd2)
🧠 Model: claude-cli/claude-opus-4-6 · 🔑 oauth (anthropic:claude-cli)
🧮 Tokens: 16 in / 5.1k out
🗄️ Cache: 100% hit · 2.3m cached, 11k new
📚 Context: 2.3m/1.0m (228%) · 🧹 Compactions: 0

Current turn is 16 input + 5.1k output. The 2.3m number is cumulative
cache reads across the session, not the prompt size of the current
request. Compactions: 0 confirms the actual context never overflowed
(Anthropic would have rejected the request otherwise).

Root cause (dist code reference)

In dist/status-message-BEh5HV7d.js around lines 280–286:

let totalTokens = freshTotalTokens ?? (... ?? entry?.totalTokens ?? ...);
if (args.includeTranscriptUsage) {
  const logUsage = readRecentSessionUsageFromTranscript(...);
  if (logUsage) {
    const candidate = logUsage.promptTokens || logUsage.total;
    if (allowTranscriptContextUsage && (!totalTokens || candidate > totalTokens))
      totalTokens = candidate;

When entry.totalTokensFresh is not true, totalTokens falls back to
logUsage.total, which readRecentSessionUsageFromTranscript computes by
summing cacheRead across multiple turns. The percentage is then computed
as total / contextWindow in formatTokens (around line 84), yielding

100% for long sessions with heavy cache reuse.

Expected behaviour

📚 Context should reflect the current request's prompt size
(inputTokens + cacheRead + cacheWrite of the latest turn), not
cumulative-across-turns usage. Cumulative usage is fine to surface, but
on a separate line / with a different label, not divided by the context
window.

Repro

  1. Start a Claude Code (or claude-cli) session with claude-opus-4-6
    (or any Anthropic model with 1M context configured).
  2. Run a long session with many turns using prompt caching.
  3. Observe /status — the Context line eventually exceeds 100% even
    though Compactions remains 0 and the model never errors with a
    context overflow.

Related

Environment

  • OpenClaw 2026.5.12 (f066dd2)
  • Runtime: Claude CLI
  • Model: claude-cli/claude-opus-4-6 via OAuth
  • Surface: TUI status card

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions