Skip to main content
Every turn resends the whole conversation. Long sessions therefore grow until they hit the model’s context window — at which point, without intervention, every subsequent request fails. 9p handles this by compacting: summarising older history into one message and keeping recent turns verbatim.

Automatic

When estimated usage passes 70% of the model’s context window, 9p compacts before the next request:
The window comes from the model catalog, so a 1M-context model compacts far later than a 128k one. Compaction happens between turns, never mid-exchange. At the top of a turn, every tool call from the previous turn already has its result, so history is in a state that can be cut safely.

Manual

Compact now, regardless of the threshold. Useful before a long task, or after finishing one whose details no longer matter. /usage shows the current estimate:

What survives

The summary is written by a real model call — cheap and toolless — and asked to keep, in order:
  1. What you’re trying to achieve, in your words
  2. Decisions and constraints, especially anything you corrected or rejected
  3. Files changed, with paths and what changed
  4. Commands run and what they revealed
  5. What’s in progress and the next step
  6. Anything broken, blocked, or deferred
Superseded intermediate steps and tool-call mechanics are dropped.
A mechanical truncation would be cheaper, but it discards exactly the decisions and constraints that make the rest of the session coherent. Paying for one small summarisation call is worth not re-explaining your project.

/compact vs /clear

/clear is cheaper and gives a genuinely clean slate — but it also resets the provider’s prompt cache, so don’t reach for it mid-task. See Credits.

Keeping sessions cheap

  • Use /clear between unrelated tasks so unrelated history never accumulates
  • Prefer sub-agents for wide searches — they return findings, not file dumps, so the main context stays small
  • Keep 9P.md tight; it’s re-sent every turn

Limits

  • Token counts are estimates (~4 chars per token), not a real tokenizer. They drive a threshold, so erring high just compacts slightly early.
  • If no safe cut point exists, 9p leaves history untouched rather than risk a malformed request.
  • A failed or empty summary aborts compaction — history is never destroyed on a bad response.