Learn-skills.dev context-compactor
Automatic context summarization for long-running sessions. Use when context is approaching limits, summarizing completed work, preserving critical information, or managing token budgets.
install
source · Clone the upstream repo
git clone https://github.com/NeverSight/learn-skills.dev
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/NeverSight/learn-skills.dev "$T" && mkdir -p ~/.claude/skills && cp -r "$T/data/skills-md/adaptationio/skrillz/context-compactor" ~/.claude/skills/neversight-learn-skills-dev-context-compactor && rm -rf "$T"
manifest:
data/skills-md/adaptationio/skrillz/context-compactor/SKILL.mdsource content
Context Compactor
Automatically summarizes and compacts context when approaching token limits while preserving critical information.
Quick Start
Check if Compaction Needed
from scripts.compactor import ContextCompactor compactor = ContextCompactor() if compactor.should_compact(context, limit=100000): compacted = compactor.compact(context)
Compact Context
compacted = compactor.compact(context) # Preserves: architectural decisions, bugs, current state # Discards: stale tool outputs, redundant messages
Preservation Strategy
┌─────────────────────────────────────────────────────────────┐ │ PRESERVATION PRIORITY │ ├─────────────────────────────────────────────────────────────┤ │ │ │ MUST PRESERVE (Never remove) │ │ ├─ Architectural decisions │ │ ├─ Unresolved bugs and blockers │ │ ├─ Current feature state │ │ ├─ Recent file changes (last 5) │ │ └─ Error patterns and solutions │ │ │ │ CAN SUMMARIZE (Compress to summary) │ │ ├─ Completed features (list of IDs) │ │ ├─ Resolved errors (brief mention) │ │ └─ Historical decisions (key points) │ │ │ │ CAN DISCARD (Remove entirely) │ │ ├─ Redundant tool outputs │ │ ├─ Stale search results │ │ ├─ Superseded messages │ │ └─ Verbose logging │ │ │ └─────────────────────────────────────────────────────────────┘
Compaction Process
- Score Importance: Assign score to each message/content
- Identify Critical: Mark must-preserve content
- Summarize Middle: Compress can-summarize content
- Discard Stale: Remove can-discard content
- Validate: Ensure compacted context is coherent
Token Budgets
| Context Type | Limit | Action |
|---|---|---|
| < 50% | Normal | No action |
| 50-75% | Warning | Prepare for compaction |
| 75-90% | Compact | Trigger compaction |
| > 90% | Critical | Aggressive compaction |
Integration Points
- autonomous-session-manager: Triggers compaction check
- memory-manager: Stores compacted summaries
- handoff-coordinator: Uses compacted state for handoffs
References
- Detailed strategyreferences/COMPACTION-STRATEGY.md
- Budget managementreferences/TOKEN-BUDGETS.md
Scripts
- Core ContextCompactorscripts/compactor.py
- Message scoringscripts/importance_scorer.py
- Content summarizationscripts/summarizer.py
- Token countingscripts/token_estimator.py