openclaw - 💡(How to fix) Fix [Bug]: Trajectory files fed back as context cause unbounded token consumption and unexpected API billing

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…

OpenClaw feeds trajectory.jsonl files back as context on every session startup, causing token consumption to compound rapidly. A single day of minimal usage (short messages like "ready?") consumed ~20M input tokens and exhausted $25 in Gemini API credits.

Root Cause

OpenClaw feeds trajectory.jsonl files back as context on every session startup, causing token consumption to compound rapidly. A single day of minimal usage (short messages like "ready?") consumed ~20M input tokens and exhausted $25 in Gemini API credits.

RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Summary

OpenClaw feeds trajectory.jsonl files back as context on every session startup, causing token consumption to compound rapidly. A single day of minimal usage (short messages like "ready?") consumed ~20M input tokens and exhausted $25 in Gemini API credits.

Environment

  • OS: Windows 11
  • OpenClaw version: 2026.5.18 (50a2481)
  • Node.js: 24.15.0
  • Model: google/gemini-3.1-pro-preview

What happened

Trajectory files in agents/main/sessions/ grew to 139KB–289KB. These were being loaded as context on every new session, even when opened with --session <new-uuid>. The startup token count was ~12k before the user typed anything.

Evidence

  • Gemini API dashboard shows ~20M input tokens and ~400 requests on May 21
  • Sessions contained only 1-2 short user messages
  • Largest trajectory file: 289KB from a session with minimal interaction

Expected behavior

New sessions opened with --session <uuid> should not load previous trajectory files as context. Token consumption should reflect actual user input, not internal file loading.

Impact

Unexpected API billing. $25 in credits consumed in one day.

Steps to reproduce

  1. Install OpenClaw 2026.5.18/20 on Windows 11
  2. Configure google/gemini-3.1-pro-preview as the model
  3. Start a new session: openclaw chat --session <new-uuid>
  4. Send one short message (e.g. "ready?")
  5. Exit
  6. Repeat steps 3-5 two or three times
  7. Check agents/main/sessions/ — trajectory.jsonl files will be 100KB+ per session despite minimal user input
  8. Check your Gemini API dashboard — input token count will be disproportionately large relative to actual messages sent
  9. On subsequent sessions, startup token count shown in TUI status bar will be ~12k before any user message is typed

Expected behavior

Token usage proportional to user input. New --session flag should isolate from previous trajectory data.

Actual behavior

Each new session loads previous trajectory files as context, compounding token usage. Startup already consumes ~12k tokens before user types anything.

OpenClaw version

  • OpenClaw version: 2026.5.18 (50a2481)

Operating system

Win 11

Install method

No response

Model

google/gemini-3.1-pro-preview

Provider / routing chain

openclaw -> google-gemini-api

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

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

Token usage proportional to user input. New --session flag should isolate from previous trajectory data.

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]: Trajectory files fed back as context cause unbounded token consumption and unexpected API billing