Revision: 9 Last modified: 2026-12-04T14:04:04Z
§11.4.141 M7 implementation. Prunes stale tool-results and old thinking from long sessions. NEVER touches the governance prefix.
| Function | Purpose | Example |
|---|---|---|
cc_should_compact |
Check if context exceeds threshold | cc_should_compact 50 |
cc_prune_stale_results |
Mark old results as prunable | cc_prune_stale_results 20 |
cc_summarize_old_thinking |
Compress old thinking blocks | cc_summarize_old_thinking |
cc_preserve_governance |
Documented invariant (no-op) | cc_preserve_governance |
cc_get_context_stats |
Return context statistics | cc_get_context_stats |
source constitution/scripts/token_efficiency/context_compactor.sh
# Check if compaction needed (after 50 turns)
if cc_should_compact 50; then
cc_prune_stale_results 20
cc_summarize_old_thinking
fi
# Governance preservation is automatic (invariant)The governance prefix (CLAUDE.md, Constitution.md) is NEVER touched by compaction. It is the cache breakpoint and must remain byte-stable for prompt caching.
- Constitution §11.4.141 M7
token_efficiency_lib.sh— for status and cachingscoped_read.sh— for targeted reads