Compaction Plugin
Formerly context_summarization: configs naming codumentor.plugins.context_summarization / ContextSummarizationPlugin still load it, with a deprecation warning. The context_summarization model role (models.roles, subagent_profiles) keeps its name.
When a conversation is about to exceed the model's context window, this plugin
shrinks the prompt so the turn can still run, in two stages:
- Clear. Old tool results are replaced by
[tool result removed](plus any sticky tail), oldest first and short-retention_roundsresults first, until the prompt is under the compaction target. The tool calls and every message stay; the results inside the lastkeep_recent_tool_tokensare kept. The cleared ids are stored, so every later prompt rebuild (next turn, resume, restart, subagent) reproduces the same bytes and the prompt cache keeps its prefix. Nothing is cleared below the trigger: tool results no longer age out per turn. - Summarize. Only if clearing was not enough: keep system prompts and the most recent messages, and — by default — ask a model to summarize the middle instead of dropping it silently. If summarization is off or fails, it falls back to truncation.
With forget_tool_result enabled (it advertises owns_tool_result_eviction),
the clearing stage stands aside and compaction goes straight to summarizing.
It also retries after a context-window error from the model, using the same
shrink-and-retry path so a long conversation is more likely to continue than
to fail outright.
Configuration
plugins:
- module: codumentor.plugins.compaction
class: CompactionPlugin
args:
enabled: true
max_context_tokens: 128000
safety_margin: 1000
min_recent_messages: 5
split_ratio: 0.7
enable_summarization: true
clear_tool_results: true
keep_recent_tool_tokens: 20000
Parameters
- enabled (optional): Whether the plugin is active (default:
true) - max_context_tokens (optional): Context limit used when the model has no entry in
model_context_limits(default:128000) - safety_margin (optional): Tokens reserved for the model's reply (default:
1000) - min_recent_messages (optional): Minimum number of recent conversation messages to keep uncompressed (default:
5) - split_ratio (optional): Fraction of the older conversation eligible for summarization / removal, from
0.0to1.0(default:0.7) - enable_summarization (optional): Summarize the dropped middle with an LLM instead of only deleting it (default:
true) - summarization_prompt_template (optional): Prompt template used for that summary (default:
"context_summarization.jinja2") - min_messages_for_summary (optional): Do not bother summarizing unless at least this many messages would be condensed (default:
3) - clear_tool_results (optional): Run the clearing stage before summarizing (default:
true). Off, compaction always summarizes or truncates. There is no option for the old per-turn stripping. - keep_recent_tool_tokens (optional): Tool results within this many tokens of the end of the prompt are never cleared, so the model keeps what it just read (default:
20000) - model_context_limits (optional): Per-model context limits. Omitted by default (empty). Example:
args:
model_context_limits:
"Qwen3-235B-A22B-Instruct-2507": 262144
Aggressive truncation for small models
plugins:
- module: codumentor.plugins.compaction
class: CompactionPlugin
args:
enabled: true
max_context_tokens: 16385
safety_margin: 500
min_recent_messages: 3
split_ratio: 0.8
What you see
When a turn is summarized or truncated, a line across the transcript reports
how many messages were condensed, how many were kept, and roughly how many
tokens were saved; opening it shows the summary. A compaction that cleared
tool results says so ("Cleared 140 tool results, 380K → 120K tokens; no
summary needed" when clearing alone was enough) and draws the same line. A pending line appears while
summarization is running. Lines stay visible in focus mode.
Each user can hide those cards in Settings → Extensions →
Compaction (Show Summarization Cards, on by default; a choice saved under
the old name still applies). This is a web-UI
setting; the TUI does not read it yet
(doc/core-dev/improvements/plugin-settings.md).
/compact
Type /compact at the start of the composer (or pick it from the / list)
to create or refresh the compacted context without sending a model turn.
The transcript stays the source of truth; compaction is derived state used by
later prompt assembly.
The command reuses this plugin's summarization, cache, token estimates, and
event card. If the conversation is too short, or summarization is disabled,
it returns a notice and does nothing. Disabled plugins do not advertise the
command.
Notes
- System messages are always kept. Recent messages are kept up to
min_recent_messages; older content is summarized (or removed). - Summaries from earlier turns are reused when the older history has not changed, so you are not charged a fresh summarization call every turn.
- For a proactive, every-turn compression scheme with topic-shift detection, see Context Management.