OpenClaw

OpenClaw silently compresses context and loses work

When history exceeds the context window, OpenClaw silently compresses older messages into a summary, which can drop active task state so the agent starts hallucinating or repeating itself. Keep critical rules in AGENTS.md and list those sections in agents.defaults.compaction.postCompactionSections so they come back after compaction, raise keepRecentTokens to keep more recent work verbatim, or set compaction.enabled to false and use /new yourself.

Likely cause

When history exceeds the context window, OpenClaw silently compresses older messages into a summary, destroying active task state so the agent starts to hallucinate or repeat itself.

The fix

  1. 1 Keep critical instructions in AGENTS.md, not in chat. Then list those H2/H3 section names under agents.defaults.compaction.postCompactionSections so OpenClaw re-injects them after every compaction.
  2. 2 Raise agents.defaults.compaction.keepRecentTokens (default 20000) or recentTurnsPreserve so more recent work stays verbatim instead of being summarized.
  3. 3 If you would rather manage it yourself, set agents.defaults.compaction.enabled to false and start fresh sessions with /new before the window fills. Mount a persistent volume so MEMORY.md survives restarts.
openclaw config set agents.defaults.compaction.keepRecentTokens 40000
Full guideOpenClaw Memory Compaction Explained

Hit a different error?

Paste any agent error and get the cause and fix in seconds.

Open the decoder

Frequently asked questions

My agent suddenly forgets the task and repeats steps. What happened?

It likely hit the context window and OpenClaw compacted older messages into a summary, dropping the active task state. Keep the goal and constraints in AGENTS.md and re-inject them with compaction.postCompactionSections, and raise keepRecentTokens so live work stays verbatim.

How do I keep critical instructions from being summarized away?

Put them in AGENTS.md under a clear H2 or H3 heading and add that heading to agents.defaults.compaction.postCompactionSections. OpenClaw injects those sections again after each compaction. There is no [PINNED] tag in OpenClaw.

Can I just turn auto-compaction off?

Yes. Set agents.defaults.compaction.enabled to false (compactMessageCount is not an OpenClaw setting). Then you must keep sessions under the context limit yourself, for example with /new. Pair it with a persistent volume so long-term memory lives outside the window.

Stop firefighting agent errors

Decoding errors one at a time is the manual version of what BetterClaw automates. Run your agents on a no-code AI agent platform with managed models, retries and config validation built in.

Free plan available · Pro $49/mo · BYOK · 7-day free trial