Skip to main content

Compaction reference

Parameters

The effective parameters appear in extension events and successful results: preserve_recent counts context-visible messages without aligning to a user turn. An assistant message or tool result may begin the kept tail. A value of 0 protects no messages and makes the entire active transcript compactable. Atomic carries the recent tail with the compaction boundary rather than replaying it as separate assistant and tool-result messages. Tail text, tool calls, and tool results remain lossless; images remain image blocks. If query is absent, Atomic uses the last visible user message. The policy-refusal summary fallback instead keeps a token-based recent tail, replayed as separate messages. Its checkpoint is lossy rather than a verbatim transcript. Compaction resets Claude’s signed reasoning chain: thinking and redacted_thinking blocks do not survive the boundary. See Preserved thinking and model switches for behavior between boundaries. The query is never truncated. An oversized planner request reports overflow rather than silently dropping part of it. Use keepContext tags, not a longer query, to guarantee protection. Configure defaults in ~/.atomic/agent/settings.json or .atomic/settings.json:
reserveTokens controls the automatic threshold that decides when compaction runs; it is not converted into a classifier line ratio. Manual calls can pass parameter overrides through the SDK.

Per-model budgets

Use compaction.modelOverrides to set reserveTokens and/or preserve_recent for an exact "provider/modelId" key. For example:
Each field falls back independently to the ordinary setting, then its built-in default. Keys are case-sensitive and do not support wildcards or reasoning suffixes. Both fields require non-negative safe integers. The active session model selects the budgets for manual, automatic, overflow, and post-tool compaction; switching models changes the next resolution, while borrowing a fallback planner does not. Explicit manual parameters take precedence over resolved defaults. preserve_recent counts messages, not tokens. compression_ratio, query, and enabled remain ordinary settings, not per-model overrides. See Settings for merge and validation rules.

Persistence and resume

A successful run appends the existing pi-style type:"compaction" entry shape:
The entry’s tokensBefore is the provider-aware whole-context count used for budgeting and the Compacted from display. details.stats.tokensBefore, tokensAfter, and percentReduction are heuristic estimates of the compactable region plus the kept tail. Those stats can differ from the entry count, and percentReduction is negative when the reconstructed estimate is larger. The display count is not stored again under details.tokensBefore. details.rung is "planned" for successful model compaction, "extension" for a session_before_compact override, or "fresh" when older context was discarded. details.backend and details.model identify the successful compactor. A policy-refusal fallback records backend: "summary", the same model that refused, and file lists in details.summary. Its card says summary (pi fallback). details.plannerModel identifies a borrowed chat planner:
A "fresh" boundary that drops the recent tail records firstKeptEntryId: null. Only entries with details.strategy === "verbatim-lines" affect active context. Resume uses the saved compacted text without rerunning planning. The TUI shows a collapsible compaction card; new messages after it remain ordinary messages. Old inactive formats do not reapply their historical omissions, so content they once hid can return on resume.

Extension hooks

session_before_compact

Extensions may cancel or provide a complete replacement for the prepared region:
preparation is a deep-frozen clone. An override changes only the compacted region text; Atomic retains the prepared boundary and persists the supplied text verbatim. Empty/whitespace text is rejected. The override path does not require provider credentials.

session_compact

After persistence, Atomic emits an observe-only event:
Observer errors are isolated and cannot roll back the already-persisted boundary.

session_compact_failed

A failed or cancelled manual, threshold, or overflow compaction emits an observe-only failure event:
errorMessage is absent for cancellation. fromExtension identifies failures after a session_before_compact handler supplied replacement text; no compaction boundary is persisted.

Branch Summary Format

Branch summarization uses a structured format:

Message Serialization for Branch Summaries

Branch-summary input uses role-labelled text:
This prevents the model from treating it as a conversation to continue. Thinking blocks are omitted. Tool results are truncated to 2000 characters during serialization. Content beyond that limit is replaced with a marker indicating how many characters were truncated.

Extension Hooks for Branch Summarization

session_before_tree

Fired before /tree navigation. Always fires regardless of whether user chose to summarize. Can cancel navigation or provide custom summary.
See SessionBeforeTreeEvent and TreePreparation in the types file.

Settings

Configure compaction in ~/.atomic/agent/settings.json or <project-dir>/.atomic/settings.json (legacy .pi paths are also supported):
The top-level compactionModel setting defaults to "auto", using the session model. An exact registered chat-model, classifier, or compactor ID selects a separate compactor. See Compaction model. Fallback borrowing reuses settings.fallbackModels, the same ordered provider/model[:thinkingLevel] list used for chat fallback. It skips entries equal to the selected compaction model. A policy refusal from any chat compaction model, including auto, explicit chat-model IDs, and borrowed fallback entries, first tries pi’s summary compaction on the same model. Classifier and Morph refusals skip summary fallback and advance directly to the next configured model. Other failures and failed summaries also advance to the next configured model. Only load-bearing recovery may clear older context after all attempts fail. Disable auto-compaction with "enabled": false. You can still compact manually with /compact.

Historical formats

Two old formats remain parseable but inactive:
  • type:"context_compaction" records store logical entry/content-block deletion targets from older versions. Those records are inert, so content they once hid can re-enter context when an old session resumes.
  • type:"compaction" without details.strategy: "verbatim-lines" stored generated summary prose. Those records also remain inert.