Context Compaction
Compaction lets a long conversation continue within a model's context window. It summarizes older context and keeps a recent portion of the selected branch. Original conversation entries remain stored; a summary changes the context used by later requests rather than erasing the transcript.
Compaction is conversation context management. It does not write facts into USER.md or MEMORY.md, finish a task for you, or guarantee that every detail survives summarization. Keep important source material in files and use context references when exact text matters.
Automatic compaction
Automatic compaction is enabled by default. Anyy checks usage against the selected model's context window, reserving room for the next response. The default settings reserve 16,384 tokens and retain about 20,000 recent tokens; a model's session configuration can override the reserve and retained amount.
Anyy can also compact after a context-overflow error or a recoverable response-length limit. When recovery is possible, it makes one compact-and-retry attempt within the same run. If the next attempt still overflows or is truncated, reduce the context or select a model with a larger context window. Automatic compaction is not an unbounded retry loop.
Summary generation uses the current model route and can incur provider usage. The conversation can pause while Anyy creates the summary. A summary failure is reported without applying an incomplete summary; some auxiliary virtual-model summary failures allow the original response preparation to continue with its existing history.
Manual compaction API
Connected RPC clients can request:
{"method":"session.compress","params":{"session_id":"SESSION_ID","focus":"Preserve decisions and unresolved constraints"}}
focus is optional. This method stops captured active work, waits for it to settle, and creates one summary. It does not automatically resume the interrupted turn. A session that is too small or already compacted can report that there is nothing to compact.
The shell CLI has no anyy compact subcommand. Dashboard Chat and the TUI have no manual compaction button or /compact//compress command. Their ordinary conversations still receive automatic compaction.
Browse and change branches
Use TUI /tree while the session is idle:
- Use Up/Down to choose an existing entry.
- Press s if you want a summary of the branch being left; the picker shows whether summary is on or off.
- Press Enter to navigate, or Esc to cancel the picker.
Selecting a user message moves the active context to the point before that message. Its text returns to the composer only when the composer is empty. Earlier and sibling branches remain available. The next submitted message continues from the newly selected point; navigation itself starts no reply.
The optional branch summary carries useful context from the branch you leave. It is a separate summary entry, not a new conversation or a memory update. Model and tool restoration follows the selected branch. Connected clients can use session.tree and session.tree.navigate; creating a separate conversation is the distinct session.fork API.
Retry and cancel
Compaction and branch summaries share the Profile's Session retry policy, separate from provider transport retries. An operation retains its retry budget. Canceling summary work waits for the model call to settle, leaves existing history intact and does not apply an incomplete or truncated summary.
TUI Esc during an agent retry wait cancels only that wait. It is not a summary-cancel shortcut. See Sessions and TUI for stop and return-to-editor controls.
Troubleshooting
| Symptom | Action |
|---|---|
| Context still overflows after recovery | Reduce referenced material, select a larger-context model, or start a new session |
| Summary generation fails | Check the selected model and credentials, then retry through the supported API if needed |
| An exact detail is missing after compaction | Reattach the original file or bounded reference |
/tree is unavailable while busy | Finish or stop the response before navigating |
| A branch's user text did not return | The composer had a draft; preserve it before navigation |
Database compaction is a different operation: it reduces database storage, not model context.