context-compression

Prevent context overflow with automatic session truncation and memory preservation. Never lose important conversations again. Features: token-based trimming, AI fact extraction, preference lifecycle management. Use when: (1) context window exceeds limit (2) setting up memory hierarchy (3) managing user preferences with expiry.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "context-compression" with this command: npx skills add lifei68801/context-compression

Memory Compression

Prevent context overflow. Never lose important conversations.

The Problem

OpenClaw sessions grow indefinitely. When context exceeds the model's limit:

  • New sessions fail to load
  • Important information is lost
  • Cron tasks inherit huge context and crash

The Solution

Automatic session truncation + hierarchical memory preservation:

  1. Trim sessions before they exceed limits
  2. Extract facts (preferences, decisions, tasks) before trimming
  3. Preserve memory through layered storage (MEMORY.md, daily notes, summaries)

🚀 Quick Start

Step 1: Check Configuration

cat ~/.openclaw/workspace/.context-compression-config.json 2>/dev/null

Step 2: Configure (Interactive)

When this skill loads, it guides you through:

QuestionOptionsRecommended
Context preservation20k/40k/60k tokens40k
Truncation frequency10min/30min/1h10min
Skip active sessionsYes/NoYes
Daily summariesYes/NoNo

Step 3: Verify

ls -la ~/.openclaw/workspace/.context-compression-config.json
ls -la ~/.openclaw/workspace/skills/context-compression/scripts/truncate-sessions-safe.sh

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Context Budget: ~80k tokens              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  L4: MEMORY.md (~5k)      ← User preferences, key facts    │
│  L3: Daily summaries (~10k) ← Compressed older sessions    │
│  L2: Recent sessions (~25k) ← Last N session files         │
│  L1: Current session (~40k) ← Active conversation          │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Key principle: L4 > L3 > L2 in priority. Always preserve MEMORY.md.


🔧 How It Works

Session Truncation

  • Runs in background (independent of agent)
  • Trims to last N tokens per session
  • Skips active sessions (.lock files)
  • Preserves JSONL line integrity

Fact Extraction

  • Detects keywords: 重要/决定/TODO/偏好, important/decision/must
  • Extracts to MEMORY.md before truncation
  • Categories: [偏好], [决策], [任务], [时间], [关系], [重要]

Preference Lifecycle

  • Short-term (1-7 days): Tag with @YYYY-MM-DD
  • Mid-term (1-4 weeks): Auto-expire via daily check
  • Long-term: Permanent in MEMORY.md

📜 Scripts

ScriptPurpose
truncate-sessions-safe.shTrim session files safely
extract-facts-enhanced.shAI-powered fact extraction
check-preferences-expiry.shRemove expired preferences
check-context-health.shReport context status

⚙️ Configuration File

~/.openclaw/workspace/.context-compression-config.json:

{
  "version": "2.3",
  "maxTokens": 40000,
  "frequencyMinutes": 10,
  "skipActive": true,
  "enableSummaries": false,
  "strategy": "priority-first",
  "priorityKeywords": [
    "重要", "决定", "记住", "TODO", "偏好",
    "important", "remember", "must", "deadline", "decision"
  ]
}

✅ Verification Checklist

  • Config file exists
  • Scripts are executable
  • MEMORY.md exists and is current
  • Truncation log shows recent runs: tail ~/.openclaw/logs/truncation.log

🔍 Troubleshooting

ProblemSolution
Context still exceededReduce maxTokens, check truncation log
Memory not persistingVerify real-time writing in AGENTS.md
Summaries not generatedCheck daily notes exist in memory/

📚 Related

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Memory Organizer

Organize, compress, and curate OpenClaw memory without polluting permanent memory. Use when the user wants to compress memory files, clean dated memory notes...

Registry SourceRecently Updated
1314
Profile unavailable
General

Session Context Compressor

Compress OpenClaw session context to reduce token usage and extend session lifetime. Uses NLP summarization (Sumy) to intelligently compact conversation history while preserving essential context. Triggers on mentions of session compression, token reduction, context cleanup, or when session size exceeds safe thresholds (~300KB). Use when (1) OpenClaw approaches 50% context limit, (2) Sessions are slowing down due to large context, (3) Reducing API costs from excessive token consumption, (4) Extending session lifetime without forced reboots.

Registry SourceRecently Updated
0616
Profile unavailable
General

Continuous Context Preserver

Continuous session event recording for inter-session memory survival. Use when you want to persist conversation context between sessions, prevent memory loss...

Registry SourceRecently Updated
091
Profile unavailable