coderClaw

Session Pruning

Session pruning trims old tool results from the in-memory context right before each LLM call. It does not rewrite the on-disk session history (*.jsonl).

When it runs

Smart defaults (Anthropic)

What this improves (cost + cache behavior)

What can be pruned

Context window estimation

Pruning uses an estimated context window (chars ≈ tokens × 4). The base window is resolved in this order:

  1. models.providers.*.models[].contextWindow override.
  2. Model definition contextWindow (from the model registry).
  3. Default 200000 tokens.

If agents.defaults.contextTokens is set, it is treated as a cap (min) on the resolved window.

Mode

cache-ttl

Soft vs hard pruning

Tool selection

Interaction with other limits

Defaults (when enabled)

Examples

Default (off):

{
  agent: {
    contextPruning: { mode: "off" },
  },
}

Enable TTL-aware pruning:

{
  agent: {
    contextPruning: { mode: "cache-ttl", ttl: "5m" },
  },
}

Restrict pruning to specific tools:

{
  agent: {
    contextPruning: {
      mode: "cache-ttl",
      tools: { allow: ["exec", "read"], deny: ["*image*"] },
    },
  },
}

See config reference: Gateway Configuration