Compaction
Crystal does not reduce context. Crystal Code does, in two steps.
Microcompaction
Section titled “Microcompaction”Before each model call, old successful tool results can be replaced with Tool result omitted after compaction. This is off unless microCompaction is set. It does not call a model, and it does not change the screen or the saved archive.
| Field | Keeps |
|---|---|
protectTurns |
The latest user turns |
protectTokens |
The newest older successful results, after those turns |
minimumTokens |
Older results are replaced only when the removed text is larger than this |
/compact micro toggles it, or sets on or off. It writes config.json and does not summarize. It is refused while a turn or compaction is running. /status shows a Microcompaction row only while it is on.
Full compaction
Section titled “Full compaction”Reserved output is reservedOutputTokens when set. Otherwise it is the smallest of 20000, the model maxTokens, and a quarter of the context budget, so a small budget keeps most of itself for input. The compact ceiling is the lesser of compactionThreshold of the budget and the budget minus that reservation. Raising the reservation changes that ceiling, and the reply cap, only when it is already tighter than the threshold. A request asks for at most min(maxTokens, budget - ceiling), so the prompt and the reply fit the budget together. A model without maxTokens sends no cap, except on the anthropic protocol, which always sends 8192 when none is declared. /context rebuilds the session client and drops cached plugin, review, and image-description clients whose output cap depends on that budget.
The size checked against the ceiling is the last model round’s reported input plus output, plus an estimate of the tool results added after it. A rewrite of the history (microcompaction or compaction), or an endpoint that reports no usage, makes the host estimate the whole list until the next round reports. A reasoning block counts once, not as text plus provider state. The host compacts when that size crosses the ceiling.
- Clears old tool results outside a protected recent band, when that frees enough tokens.
- Asks for a structured summary of older turns, folding any previous summary, and keeps a recent tail verbatim.
- Stops if the summary cannot be produced and nothing else can be reduced. Compaction does not loop.
A summary that stops because it hit its output limit is not stored. The summary call sends a reply cap of a quarter of the ceiling, at most 16384 tokens or the writing model’s maxTokens when that is smaller, and never more than half the summary window. The writer is the session model, or the compaction model when that switch is on. A writer without maxTokens still sends that cap. The verbatim tail is at most 32000 tokens.
CTX percent is the last model round, not the sum of rounds in a turn. After a tool batch, and until the next round reports, a local estimate is shown with ~. That estimate does not replace saved provider usage. The transcript prints compacting context... and the progress row shows Compacting. The frame keeps painting.
Resource trimming
Section titled “Resource trimming”Resource trimming changes only the outbound request, not the transcript. A resource omitted from a request is represented to the model by its marker, such as [Image #N]; the session, saved history, fork, and export keep it. By default, only resources returned by tools are trimmed. Set includeUserResources to include operator-attached images.
resourceTrim defaults to enabled, keepRecent: 16, slack: 8, and maxBytes: 134217728 (128 MiB); maxBytes: 0 means no byte budget. Automatic trimming starts when trimmable resources exceed keepRecent + slack, then keeps the newest keepRecent. A byte budget drops the oldest trimmable resources until the inline images fit, always keeping the newest. Trimming is one-way for that session trimmer: an omitted resource does not return when newer resources arrive.
A provider entry in providers.json can override keepRecent, slack, maxBytes, and includeUserResources for that provider’s models; enabled remains global. /trim with no argument applies the configured count now. /trim 3 keeps the newest three, /trim all keeps none, and /trim on or /trim off switches automatic trimming and writes config.json. The command is refused during a turn or compaction. /clear and resume reset the in-memory omissions.
Commands
Section titled “Commands”/compact (alias /summarize) runs now and does not wait for the threshold. If the retained tail already holds every turn, it still summarizes everything before the latest user turn. A session with nothing before that turn prints Nothing earlier to compact. It is refused while a turn is running.
| Command | Effect |
|---|---|
/compact full |
Folds the whole conversation, including the latest turn, into the summary |
/compact model |
Shows Compaction model Off or On <provider> <model>. Turns the switch on or off, or selects <model> or <provider> <model> and turns it on |
/compact thinking |
Cycles or sets that model’s gear |
/compact summary |
Toggles showCompactionSummary. Prints Compaction summary On or Off. on or off sets it |
/compact auto |
Same for showAutomaticCompactionSummary. Prints Automatic compaction summary. automatic is the same command |
/compact micro |
Toggles removal of old tool results |
model and thinking are refused during a turn or compaction. The display commands write config.json and do not summarize. Any other argument is rejected. Tab completes full, model, thinking, summary, auto, and micro, then on and off.
Which model writes the summary
Section titled “Which model writes the summary”When the switch is off, or compactionModel is omitted, summaries use the session model and omit reasoning. The summary does not reuse the session client, because that client keeps the turn output cap. The host opens a summary client with the summary reply cap, and opens it again when the model, tier, speed, or cap changes. When the switch is on, summary requests use a separate client, including /compact and a summary a side question may take before it answers. The side answer still uses the session model. Changing the session model does not retarget an open compaction client.
The trigger, retained tail, and CTX percent stay on the session window. The summary must fit the smaller of the session window and the compaction model’s declared window. If it does not, the host keeps the existing path that writes no summary. /status adds a Compaction model row only while the switch is on.
A successful compact is written to the session file. The screen keeps the earlier lines. When showCompactionSummary is on (the default), a manual /compact prints the summary in a rounded panel titled Earlier context. Automatic compaction prints Compacted context and, when showAutomaticCompactionSummary is on, the same panel. That switch defaults off. /resume restores the full conversation. The model continues from the summary and tail, and only the live system prompt is refreshed.