Compaction reference
Parameters
The effective parameters appear in extension events and successful results:preserve_recent counts context-visible messages without aligning the boundary to a user turn. An assistant message or tool result may therefore begin the kept tail. Because such a tail can start or end mid-turn, the kept messages are not replayed as structured message blocks: they are serialized with the same transcript grammar as the compacted region and appended to the end of the boundary string, so the whole boundary reaches the provider as one message. Serialization of the kept tail is lossless — tool results keep their full text instead of being truncated at 16k characters, and images stay attached as image blocks rather than becoming [image] markers — so protected content is preserved, not merely summarized. A value of 0 protects no messages and makes the entire active transcript compactable. If query is absent, Atomic derives it from the last visible user message.
One consequence is worth stating for Claude models that sign their reasoning. Because the kept tail is serialized into the boundary string rather than replayed as structured assistant messages, no thinking or redacted_thinking block survives a compaction boundary. Compaction therefore intentionally resets the signed reasoning chain: reasoning produced before a boundary is not carried across it. This is deliberate, and it is the first of the two remedies Anthropic documents for keep-tail compaction — carry the text and tool calls across, leave the thinking blocks behind — reached structurally rather than by a stripping pass. The tail’s own content is unaffected: text, tool calls, and tool results cross the boundary losslessly. See Preserved thinking and model switches for how Atomic handles prefix changes between boundaries, which is a separate mechanism.
The query is used whole and is never truncated. This matters for structured prompts: a truncated query would make section order the retention policy, because only the leading section could influence what the planner kept, and a constraint stated later in the prompt could not. Long queries are safe — an oversized planner request surfaces as an explicit provider-overflow failure rather than silent truncation — but keepContext tags, not query length, are the way to guarantee a span survives.
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
Usecompaction.modelOverrides to set reserveTokens and/or preserve_recent for an exact "provider/modelId" key. For example:
preserve_recent), not a token budget (keepRecentTokens). Verbatim line reconstruction, compression_ratio, and query are unchanged; the latter two and enabled remain ordinary settings. See Settings for merge and validation details.
Persistence and resume
A successful run appends the existing pi-styletype:"compaction" entry shape:
details.rung is one of "planned" (a model ranked the lines — the session model or a borrowed fallback, including silent partial recovery), "extension" (a session_before_compact override), or "fresh" (the compactable conversation was discarded and a new context window started). details.plannerModel is present only when a borrowed fallback model ranked the lines:
"fresh" and plannerModel are additive: they are absent on every existing entry and on any compaction that used the session model, so old readers are unaffected. A "fresh" boundary that had to drop the preserve_recent tail persists firstKeptEntryId: null.
A compaction entry is active only when details.strategy === "verbatim-lines". On rebuild, Atomic emits one visible custom-role boundary message: the durable summary with the kept tail—the entries from firstKeptEntryId up to the boundary—serialized and concatenated onto its end. The tail is never restored as separate assistant/tool-result blocks, so a tail that starts or ends mid-turn cannot produce out-of-order provider blocks; images inside the tail ride along as image blocks on that same boundary message. When no pre-boundary context-visible message is retained—such as with preserve_recent: 0—firstKeptEntryId is null and the boundary carries the summary alone. Messages appended after the boundary are always replayed as real messages. The boundary is converted to a user-role provider message and shown in the TUI as a collapsible compaction card.
Resume does not rerun planning or re-derive deletions: the exact compacted string and nullable tail boundary are already in JSONL. Existing records with a string firstKeptEntryId keep their original resume behavior. Legacy context_compaction logical-deletion records and old compaction summary records without the discriminator are inert archival data. Their historical omissions are not reapplied when an old session resumes.
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:
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
Before branch summarization, messages are serialized to text viaserializeConversation():
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.
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):
Compaction has no configuration key of its own for fallback borrowing: it reuses
settings.fallbackModels, the same ordered provider/model[:thinkingLevel] list that main-chat model fallback walks. With no fallbackModels configured, compaction behaves as before: one planner model, then either an honest failure (recoverable) or a fresh context window (load-bearing).
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"withoutdetails.strategy: "verbatim-lines"stored generated summary prose. Those records also remain inert.
details on the shared CompactionEntry shape; the session format version is the same for all of them.