Every message you send, the LLM re-reads the ENTIRE conversation history. A 100K token chat = 100K tokens of INPUT per message. 20 messages = 2M tokens re-read. This skill exists to keep that number LOW without losing information.
text
Message #1: Context 25K → You pay for 25K input tokens
Message #2: Context 30K → You pay for 30K input tokens
Message #10: Context 65K → You pay for 65K input tokens
Message #20: Context 105K → You pay for 105K input tokens
Message #50: Context 200K → You pay for 200K input tokens
Total paid for 50 messages WITHOUT compression: ~5.2M input tokens
Total paid for 50 messages WITH compression at 80K: ~2.8M input tokens
SAVINGS: 46% fewer tokens = 46% less money
The longer you stay in one chat without managing context, the more expensive EVERY SINGLE MESSAGE becomes.
ZoneRangeEmojiWhat to doGREEN0 - 80K🟢Work freelyYELLOW80K - 130K🟡Evaluate: compress or /newRED130K+🔴Act NOW: compress or /new
Every response MUST include at the end:
text
[emoji] Contexto: XXK tokens
In audio/voice mode: omit token count (don't read numbers aloud).
text
50K → 🟢 GREEN
85K → 🟡 YELLOW (80 < 85 < 130)
110K → 🟡 YELLOW (80 < 110 < 130)
130K → 🔴 RED (130+)
166K → 🔴 RED (130+)
A topic is a DISTINCT subject of conversation. Examples:
Maintain a mental list of active topics. For each topic track:
text
TOPIC: [name]
STATUS: [active | completed | paused]
STARTED: message ~#N
KEY DATA: [IDs, decisions, configs that must survive]
A topic is COMPLETED when:
When ALL active topics are completed:
text
💡 Veo que ya cerramos [topic A] y [topic B].
¿Abrimos chat nuevo para el siguiente tema?
Ya guardé todo en memoria.
When SOME topics are complete but others continue:
text
📋 [Topic A] ✅ cerrado | [Topic B] 🔄 en progreso
Seguimos con [Topic B]. Contexto: XXK tokens.
text
DEFLATE ANALYSIS:
──────────────────────────────
1. Active topics: [list with status]
2. Topics completed this session: [count]
3. Critical data in chat NOT yet in MEMORY.md: [list]
4. Session type: [focused / multi-topic / chaotic]
5. Previous compressions this session: [count + last reduction %]
DECISION:
├─ Is critical data already saved to MEMORY.md?
│ ├─ YES → recommend /new (FREE, fresh context) ✅
│ └─ NO → flush to MEMORY.md first, then:
│ ├─ All topics done? → /new ✅
│ └─ Topic in progress? → /compact (PAID) ⚠️
│
└─ If /compact chosen:
├─ 1-2 active topics → expect good reduction (40-60%)
├─ 3-4 active topics → expect moderate reduction (25-40%)
└─ 5+ active topics → STOP. Flush + /new instead
/newis FREE./compactcosts tokens. Always prefer/newwhen MEMORY.md has the important stuff. Only/compactwhen you're mid-topic and can't restart.
When /compact is the right choice, use this 5-step method:
text
Identify distinct topics in the conversation.
Group messages by topic mentally.
text
ELIMINATE (zero information value):
- Greetings: "hola", "qué onda", "gracias"
- Confirmations: "ok", "va", "listo", "dale"
- Failed attempts: keep ONLY the final working solution
- Repeated info: if said 3 times, keep 1
- Tool raw output: keep results, discard JSON/logs
- Emotional reactions: "LOL", "wow", "nice"
- The agent explaining its thought process
text
For each topic, create an atomic note:
┌─ TOPIC: [keyword/name] ─────────────────┐
│ SUMMARY: [1-2 lines max] │
│ DECISION: [what was decided, by whom] │
│ DATA: [IDs, configs, values — EXACT] │
│ STATUS: [done / in-progress / blocked] │
│ NEXT: [pending action, if any] │
└──────────────────────────────────────────┘
text
The following must survive compression EXACTLY as-is:
- Numeric IDs (project_id: 42, client_id: 7)
- Dates (2026-03-20)
- Money amounts ($450.00 MXN)
- URLs and file paths
- API keys and config values
- Names (people, projects, companies)
- Code snippets that are part of solutions
text
Merge all Cornell notes into the compressed summary.
Order: MOST IMPORTANT FIRST (prevents "lost in the middle" effect).
Format:
SESSION CONTEXT (compressed from XXK → YYK):
├── [topic-keyword] Summary... | Decision: ... | IDs: ...
├── [topic-keyword] Summary... | Status: in-progress
├── [PRESERVED DATA] {all lossless items}
└── [PENDING] {actionable next steps}
text
DEFLATE LOG:
- Before: [X]K tokens
- After: [Y]K tokens
- Reduction: [Z]%
- Topics preserved: [list]
- Lossless data verified: [yes/no]
- Verdict: EFFECTIVE (>40%) | MARGINAL (20-40%) | FAILED (<20%)
ReductionVerdictNext Action>40%✅ EFFECTIVESession healthy, continue20-40%⚠️ MARGINALLast useful compress, /new next time<20%❌ FAILEDSTOP. Flush + /new immediately
TypeExpected ReductionsNotesDebugging / logs60-80%Logs = pure noise, highly compressibleData entry (repetitive)60-80%Same structure repeated, compresses wellSingle-topic design40-60%Good reduction, decisions accumulate slowlyConfiguration / setup40-60%Trial-and-error is compressibleMulti-topic (3-4)25-40%Each topic needs its own summaryStrategy / negotiation15-25%Everything is critical contextBrainstorm (5+ topics)10-20%Don't compress, just /new
Write to MEMORY.md (or memory/YYYY-MM-DD.md) with tagged sections:
markdown
## [DECISION] Brief title
Date: YYYY-MM-DD
- What: [the decision]
- Why: [1-line reason]
- Who: [user or agent decided]
## [PROJECT] Project Name
Date: YYYY-MM-DD
- Status: active | paused | done
- Key IDs: [list]
- Next: [actionable step]
## [CONFIG] What changed
Date: YYYY-MM-DD
- Setting: [name] → [new value]
- Why: [reason]
## [LEARNING] Lesson learned
Date: YYYY-MM-DD
- Problem: [what went wrong]
- Fix: [what solved it]
- Rule: [how to prevent it next time]
TagUse for[DECISION]Business or technical decisions[PROJECT]Project status and key data[CONFIG]System/tool configuration changes[LEARNING]Mistakes and lessons learned[CONTACT]People, clients, IDs[TOOL]New tools, commands, integrations[COST]Budget, API usage, optimization results[RULE]New operational rules or protocols
When the user types /new or you recommend it:
text
PRE-/NEW CHECKLIST:
□ All critical data written to MEMORY.md?
□ Active topic status saved (in-progress items noted)?
□ IDs and configs preserved exactly?
□ Pending actions clearly listed?
□ User confirmed ready for /new?
Steps:
In every heartbeat or status report, include:
text
SESSION HEALTH:
[zone emoji] Contexto: XXK tokens
📊 Compresiones: N (última: Z% reducción)
📋 Temas: [active] activos, [done] cerrados
💰 Costo estimado sesión: ~$X.XX
💡 Recomendación: [seguir | comprimir | /new]
text
Gemini Flash: ~$0.10 per 1M input tokens
Cost per message ≈ context_tokens × $0.0000001
Examples:
50K context → $0.005/msg
100K context → $0.01/msg
200K context → $0.02/msg
Add to your openclaw.json under agents.defaults.compaction:
json
{
"compaction": {
"mode": "default",
"reserveTokens": 920000,
"reserveTokensFloor": 920000,
"keepRecentTokens": 20000,
"memoryFlush": {
"enabled": true,
"softThresholdTokens": 4000
},
"identifierPolicy": "strict"
}
}
This sets up the SAFETY NET (system-level auto-compaction at ~80K). The skill handles the INTELLIGENT layer on top.
Adjust these values based on your model's context window:
Model WindowreserveTokensYellow ZoneRed Zone128K (GPT-4)8000048K+80K+200K (Claude)13000070K+120K+1M (Gemini)92000080K+130K+2M (Gemini Pro)1800000200K+500K+
Created by @thevibestack — github.com/thevibestack Methodology: Cornell-MapReduce Hybrid with Lossless Data Preservation. Research: Recursive Summarization, Knowledge Distillation, Medical Shorthand. License: MIT-0
💡 If this skill saved you money, star the repo and share it. The AI should work for everyone, not just those with big budgets.