/install clawpressor
ClawPressor - Session Context Compressor
Intelligently compress OpenClaw session files to reduce token usage by 85-96%.
Author: JARVIS (AI Coder) | Managed by: BeBoX License: MIT | Version: 1.0.0
Quick Start
# Preview compression without changes
python3 scripts/compress.py --dry-run
# Apply compression
python3 scripts/compress.py --apply
# Restore from backup
python3 scripts/compress.py --restore
When to Use
| Situation | Action |
|---|---|
| Context at 30-40% | Plan compression soon |
| Context at 50% | URGENT — OpenClaw will force compact |
| Session > 300KB | Compress to restore performance |
| Slow responses | Large context likely the cause |
| High API costs | Compress regularly to save tokens |
How It Works
- Preserves recent context — Keeps last 5 messages intact for immediate context
- Summarizes old messages — Uses LexRank algorithm to extract key information
- Replaces with compact block — Single system message containing summary
- Creates backup — Original preserved as
.backupfile
Prerequisites
pip install sumy
python -c "import nltk; nltk.download('punkt_tab'); nltk.download('stopwords')"
Command Reference
# Find and compress latest session (dry-run)
python3 scripts/compress.py
# Compress specific session
python3 scripts/compress.py --session /path/to/session.jsonl --apply
# Keep more recent messages (default: 5)
python3 scripts/compress.py --keep 10 --apply
# Restore if something went wrong
python3 scripts/compress.py --restore
# View compression statistics
python3 scripts/compress.py --stats
Typical Results
| Metric | Before | After | Gain |
|---|---|---|---|
| Messages | 168 | 6 | -96% |
| Size | 347 KB | 12 KB | -96% |
| Context tokens | ~50k | ~8k | -84% |
| Session duration | ~30 min | ~2-3h | +400% |
Integration with Workflows
In HEARTBEAT.md:
## Context Maintenance (1x/jour)
- Check session size: `ls -lh ~/.openclaw/agents/main/sessions/*.jsonl`
- If > 200KB: `python3 skills/clawpressor/scripts/compress.py --apply`
Manual check:
# See current session stats
ls -lh ~/.openclaw/agents/main/sessions/*.jsonl | head -1
Safety
- Always creates
.backupbefore compressing --restorerecovers original session- Recent messages always preserved intact
- Summary stored as system message (visible to model)
Troubleshooting
| Issue | Solution |
|---|---|
| "Sumy not installed" | Run pip install sumy and NLTK downloads |
| No session found | Check ~/.openclaw/agents/main/sessions/ exists |
| Backup not found | File may have been overwritten; no recovery |
| Poor summaries | Increase --keep to preserve more context |
Credits
- Coding: JARVIS (AI Assistant)
- Project Management: BeBoX
- Technique: NLP summarization via Sumy (LexRank algorithm)
Related
- See
memory/openclaw-context-optimization.mdfor full strategy - Combine with SOUL_MIN/USER_MIN files for maximum efficiency
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install clawpressor - 安装完成后,直接呼叫该 Skill 的名称或使用
/clawpressor触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
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. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 914 次。
如何安装 Session Context Compressor?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install clawpressor」即可一键安装,无需额外配置。
Session Context Compressor 是免费的吗?
是的,Session Context Compressor 完全免费(开源免费),可自由下载、安装和使用。
Session Context Compressor 支持哪些平台?
Session Context Compressor 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Session Context Compressor?
由 beboxos(@beboxos)开发并维护,当前版本 v1.0.0。