{
  "title": "Context Window & Compaction",
  "content": "Every model has a **context window** (max tokens it can see). Long-running chats accumulate messages and tool results; once the window is tight, OpenClaw **compacts** older history to stay within limits.\n\n## What compaction is\n\nCompaction **summarizes older conversation** into a compact summary entry and keeps recent messages intact. The summary is stored in the session history, so future requests use:\n\n* The compaction summary\n* Recent messages after the compaction point\n\nCompaction **persists** in the session’s JSONL history.\n\nSee [Compaction config & modes](/concepts/compaction) for the `agents.defaults.compaction` settings.\n\n## Auto-compaction (default on)\n\nWhen a session nears or exceeds the model’s context window, OpenClaw triggers auto-compaction and may retry the original request using the compacted context.\n\n* `🧹 Auto-compaction complete` in verbose mode\n* `/status` showing `🧹 Compactions: <count>`\n\nBefore compaction, OpenClaw can run a **silent memory flush** turn to store\ndurable notes to disk. See [Memory](/concepts/memory) for details and config.\n\nUse `/compact` (optionally with instructions) to force a compaction pass:\n\n## Context window source\n\nContext window is model-specific. OpenClaw uses the model definition from the configured provider catalog to determine limits.\n\n## Compaction vs pruning\n\n* **Compaction**: summarises and **persists** in JSONL.\n* **Session pruning**: trims old **tool results** only, **in-memory**, per request.\n\nSee [/concepts/session-pruning](/concepts/session-pruning) for pruning details.\n\n* Use `/compact` when sessions feel stale or context is bloated.\n* Large tool outputs are already truncated; pruning can further reduce tool-result buildup.\n* If you need a fresh slate, `/new` or `/reset` starts a new session id.",
  "code_samples": [
    {
      "code": "/compact Focus on decisions and open questions",
      "language": "unknown"
    }
  ],
  "headings": [
    {
      "level": "h2",
      "text": "What compaction is",
      "id": "what-compaction-is"
    },
    {
      "level": "h2",
      "text": "Configuration",
      "id": "configuration"
    },
    {
      "level": "h2",
      "text": "Auto-compaction (default on)",
      "id": "auto-compaction-(default-on)"
    },
    {
      "level": "h2",
      "text": "Manual compaction",
      "id": "manual-compaction"
    },
    {
      "level": "h2",
      "text": "Context window source",
      "id": "context-window-source"
    },
    {
      "level": "h2",
      "text": "Compaction vs pruning",
      "id": "compaction-vs-pruning"
    },
    {
      "level": "h2",
      "text": "Tips",
      "id": "tips"
    }
  ],
  "url": "llms-txt#context-window-&-compaction",
  "links": []
}