openclaw - 💡(How to fix) Fix [Bug]: CLI compaction never triggers for claude-cli runtime sessions, configured contextTokens budget silently ignored (companion to #78194)

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…

In OpenClaw 2026.5.7, agents running on the claude-cli runtime never trigger compaction regardless of how much they exceed their configured contextTokens budget. The session entry's contextTokens field is never populated, which causes compactCliTranscript in src/agents/command/cli-compaction.ts to return early at the budget check, silently skipping all compaction logic.

This is companion behavior to the display bug fixed in PR #78239 (#78194), but with more severe consequences: unbounded context growth instead of cosmetic display issue.

Root Cause

Root cause (source-level)

Fix Action

Fix / Workaround

Workarounds attempted

  • Renaming models.providers.anthropic to models.providers.claude-cli makes /status display the configured budget correctly (works around the runtimeDiffersFromSelected display bug in status-message.ts), but does NOT fix compaction. The session entry's contextTokens field remains unset regardless of provider name.
  • No other workaround discovered. Compaction is effectively disabled for claude-cli routes.

If the fix from PR #78239 is verified to also resolve this bug post-release, this issue can be closed as resolved by that PR. Filing it separately to ensure compaction behavior is explicitly verified and tested, since the merged PR's test coverage focused on display correctness only.

Code Example

const contextTokenBudget = resolvePositiveInteger(params.sessionEntry?.contextTokens);
if (!sessionFile || !contextTokenBudget) return params.sessionEntry;

---

Anthropic/claude-cli agent:
  Model: claude-cli/claude-opus-4-7
  Cache: 96% hit, 226k cached, 9.4k new
  Context: ?/100k, Compactions: 0

---

Kimi pi-runtime agent:
  Model: openrouter/moonshotai/kimi-k2.6
  Cache: 94% hit, 6.7k cached, 0 new
  Context: ?/30k, Compactions: 2 (working as expected)

---

Openai-codex pi-runtime agent:
  Model: openai-codex/gpt-5.5
  Context: 6.9k/30k (23%), Compactions: 1 (working as expected)
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Summary

In OpenClaw 2026.5.7, agents running on the claude-cli runtime never trigger compaction regardless of how much they exceed their configured contextTokens budget. The session entry's contextTokens field is never populated, which causes compactCliTranscript in src/agents/command/cli-compaction.ts to return early at the budget check, silently skipping all compaction logic.

This is companion behavior to the display bug fixed in PR #78239 (#78194), but with more severe consequences: unbounded context growth instead of cosmetic display issue.

Root cause (source-level)

cli-compaction.ts:

const contextTokenBudget = resolvePositiveInteger(params.sessionEntry?.contextTokens);
if (!sessionFile || !contextTokenBudget) return params.sessionEntry;

When sessionEntry.contextTokens is missing (which it is for claude-cli runtime sessions in 2026.5.7), contextTokenBudget resolves to undefined and the function returns early. No compaction analysis or trigger evaluation runs.

Steps to reproduce

  1. Configure an agent with agentRuntime.id: "claude-cli" routing to anthropic/claude-opus-4-7 (or any anthropic-via-claude-cli setup)
  2. Set contextTokens: 100000 (or any value) on the model entry under models.providers.anthropic.models[]
  3. Start a session and produce enough output to exceed the configured budget multiple times over (verbose response prompts work well)
  4. Observe /status reports Compactions: 0 despite cumulative cache writes far exceeding the configured budget

Observed (empirical evidence)

Test fleet: an Anthropic-via-claude-cli agent (configured contextTokens: 100000), a pi-runtime kimi agent (30000), and a pi-runtime openai-codex agent (30000).

After multiple long-form prompt iterations:

Anthropic/claude-cli agent:
  Model: claude-cli/claude-opus-4-7
  Cache: 96% hit, 226k cached, 9.4k new
  Context: ?/100k, Compactions: 0
Kimi pi-runtime agent:
  Model: openrouter/moonshotai/kimi-k2.6
  Cache: 94% hit, 6.7k cached, 0 new
  Context: ?/30k, Compactions: 2 (working as expected)
Openai-codex pi-runtime agent:
  Model: openai-codex/gpt-5.5
  Context: 6.9k/30k (23%), Compactions: 1 (working as expected)

The pi-runtime agents (kimi, openai-codex) compacted correctly at their configured budgets. The claude-cli agent accumulated 226k cached prompt content with zero compaction events, exceeding its 100k budget by 2.26x.

Expected behavior

Compaction should trigger at approximately 80% of sessionEntry.contextTokens (the standard threshold used by compactCliTranscript), matching the behavior already verified for pi-runtime sessions.

Workarounds attempted

  • Renaming models.providers.anthropic to models.providers.claude-cli makes /status display the configured budget correctly (works around the runtimeDiffersFromSelected display bug in status-message.ts), but does NOT fix compaction. The session entry's contextTokens field remains unset regardless of provider name.
  • No other workaround discovered. Compaction is effectively disabled for claude-cli routes.

Relationship to #78194 / PR #78239

PR #78239 (merged 2026-05-11) addresses the totalTokens display issue for claude-cli runtime sessions by persisting lastCallUsage from agentMeta. The PR's test verifies totalTokens and totalTokensFresh but does not verify contextTokens persistence or compaction behavior.

If PR #78239 incidentally also populates sessionEntry.contextTokens for CLI runs, this bug may be resolved as a side effect when the fix releases. If not, an additional fix is needed to populate that field, otherwise the early-return guard in compactCliTranscript will continue to skip compaction silently.

OpenClaw version

2026.5.7

Provider / routing chain

openclaw to claude-cli (Anthropic Max OAuth) to anthropic

Impact

  • Affected: any user routing Anthropic models through claude-cli runtime, which is the documented Anthropic Max OAuth subscription path
  • Severity: medium-to-high. Symptom is silent unbounded context growth; users may not notice until hitting Anthropic's native context window limit and seeing degraded model responses or API errors
  • Frequency: deterministic; always reproduces

Additional information

If the fix from PR #78239 is verified to also resolve this bug post-release, this issue can be closed as resolved by that PR. Filing it separately to ensure compaction behavior is explicitly verified and tested, since the merged PR's test coverage focused on display correctness only.

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…

FAQ

Expected behavior

Compaction should trigger at approximately 80% of sessionEntry.contextTokens (the standard threshold used by compactCliTranscript), matching the behavior already verified for pi-runtime sessions.

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]: CLI compaction never triggers for claude-cli runtime sessions, configured contextTokens budget silently ignored (companion to #78194)