← 返回 Skills 市场
aeromomo

claw-compactor

作者 aeromomo · GitHub ↗ · v6.0.0
cross-platform ⚠ suspicious
1421
总下载
0
收藏
4
当前安装
2
版本数
在 OpenClaw 中安装
/install cut-your-tokens-97percent-savings-on-session-transcripts-via-observation-extraction
功能描述
Claw Compactor v6.0 — 50%+ savings through rule-based compression, dictionary encoding, session observation compression, and progressive context loading.
使用说明 (SKILL.md)

🦞 Claw Compactor

Claw Compactor Banner

"Cut your tokens. Keep your facts."

Cut your AI agent's token spend in half. One command compresses your entire workspace — memory files, session transcripts, sub-agent context — using 5 layered compression techniques. Deterministic. Mostly lossless. No LLM required.

Features

  • 5 compression layers working in sequence for maximum savings
  • Zero LLM cost — all compression is rule-based and deterministic
  • Lossless roundtrip for dictionary, RLE, and rule-based compression
  • ~97% savings on session transcripts via observation extraction
  • Tiered summaries (L0/L1/L2) for progressive context loading
  • CJK-aware — full Chinese/Japanese/Korean support
  • One command (full) runs everything in optimal order

5 Compression Layers

# Layer Method Savings Lossless?
1 Rule engine Dedup lines, strip markdown filler, merge sections 4-8%
2 Dictionary encoding Auto-learned codebook, $XX substitution 4-5%
3 Observation compression Session JSONL → structured summaries ~97% ❌*
4 RLE patterns Path shorthand ($WS), IP prefix, enum compaction 1-2%
5 Compressed Context Protocol ultra/medium/light abbreviation 20-60% ❌*

*Lossy techniques preserve all facts and decisions; only verbose formatting is removed.

Quick Start

git clone https://github.com/aeromomo/claw-compactor.git
cd claw-compactor

# See how much you'd save (non-destructive)
python3 scripts/mem_compress.py /path/to/workspace benchmark

# Compress everything
python3 scripts/mem_compress.py /path/to/workspace full

Requirements: Python 3.9+. Optional: pip install tiktoken for exact token counts (falls back to heuristic).

Architecture

┌─────────────────────────────────────────────────────────────┐
│                      mem_compress.py                        │
│                   (unified entry point)                     │
└──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬────┘
       │      │      │      │      │      │      │      │
       ▼      ▼      ▼      ▼      ▼      ▼      ▼      ▼
  estimate compress  dict  dedup observe tiers  audit optimize
       └──────┴──────┴──┬───┴──────┴──────┴──────┴──────┘
                        ▼
                  ┌────────────────┐
                  │     lib/       │
                  │ tokens.py      │ ← tiktoken or heuristic
                  │ markdown.py    │ ← section parsing
                  │ dedup.py       │ ← shingle hashing
                  │ dictionary.py  │ ← codebook compression
                  │ rle.py         │ ← path/IP/enum encoding
                  │ tokenizer_     │
                  │   optimizer.py │ ← format optimization
                  │ config.py      │ ← JSON config
                  │ exceptions.py  │ ← error types
                  └────────────────┘

Commands

All commands: python3 scripts/mem_compress.py \x3Cworkspace> \x3Ccommand> [options]

Command Description Typical Savings
full Complete pipeline (all steps in order) 50%+ combined
benchmark Dry-run performance report
compress Rule-based compression 4-8%
dict Dictionary encoding with auto-codebook 4-5%
observe Session transcript → observations ~97%
tiers Generate L0/L1/L2 summaries 88-95% on sub-agent loads
dedup Cross-file duplicate detection varies
estimate Token count report
audit Workspace health check
optimize Tokenizer-level format fixes 1-3%

Global Options

  • --json — Machine-readable JSON output
  • --dry-run — Preview changes without writing
  • --since YYYY-MM-DD — Filter sessions by date
  • --auto-merge — Auto-merge duplicates (dedup)

Real-World Savings

Workspace State Typical Savings Notes
Session transcripts (observe) ~97% Megabytes of JSONL → concise observation MD
Verbose/new workspace 50-70% First run on unoptimized workspace
Regular maintenance 10-20% Weekly runs on active workspace
Already-optimized 3-12% Diminishing returns — workspace is clean

cacheRetention — Complementary Optimization

Before compression runs, enable prompt caching for a 90% discount on cached tokens:

{
  "models": {
    "model-name": {
      "cacheRetention": "long"
    }
  }
}

Compression reduces token count, caching reduces cost-per-token. Together: 50% compression + 90% cache discount = 95% effective cost reduction.

Heartbeat Automation

Run weekly or on heartbeat:

## Memory Maintenance (weekly)
- python3 skills/claw-compactor/scripts/mem_compress.py \x3Cworkspace> benchmark
- If savings > 5%: run full pipeline
- If pending transcripts: run observe

Cron example:

0 3 * * 0 cd /path/to/skills/claw-compactor && python3 scripts/mem_compress.py /path/to/workspace full

Configuration

Optional claw-compactor-config.json in workspace root:

{
  "chars_per_token": 4,
  "level0_max_tokens": 200,
  "level1_max_tokens": 500,
  "dedup_similarity_threshold": 0.6,
  "dedup_shingle_size": 3
}

All fields optional — sensible defaults are used when absent.

Artifacts

File Purpose
memory/.codebook.json Dictionary codebook (must travel with memory files)
memory/.observed-sessions.json Tracks processed transcripts
memory/observations/ Compressed session summaries
memory/MEMORY-L0.md Level 0 summary (~200 tokens)

FAQ

Q: Will compression lose my data? A: Rule engine, dictionary, RLE, and tokenizer optimization are fully lossless. Observation compression and CCP are lossy but preserve all facts and decisions.

Q: How does dictionary decompression work? A: decompress_text(text, codebook) expands all $XX codes back. The codebook JSON must be present.

Q: Can I run individual steps? A: Yes. Every command is independent: compress, dict, observe, tiers, dedup, optimize.

Q: What if tiktoken isn't installed? A: Falls back to a CJK-aware heuristic (chars÷4). Results are ~90% accurate.

Q: Does it handle Chinese/Japanese/Unicode? A: Yes. Full CJK support including character-aware token estimation and Chinese punctuation normalization.

Troubleshooting

  • FileNotFoundError on workspace: Ensure path points to workspace root (contains memory/ or MEMORY.md)
  • Dictionary decompression fails: Check memory/.codebook.json exists and is valid JSON
  • Zero savings on benchmark: Workspace is already optimized — nothing to do
  • observe finds no transcripts: Check sessions directory for .jsonl files
  • Token count seems wrong: Install tiktoken: pip3 install tiktoken

Credits

License

MIT

安全使用建议
What to consider before installing: - Coherence: The code implements what the skill claims (workspace compression, session transcript observation extraction). That part is internally consistent. - Sensitive file access: The skill will read session transcripts from ~/.openclaw/sessions and will write memory/.observed-sessions.json and memory/observations/ inside the target workspace. Those session files can contain private data — back up and inspect them first. - Prompt-injection risk: The compressed_context module and SKILL.md suggest prepending decompression instructions to model/system prompts. That is functionally necessary to make compressed notation readable by an LLM, but it is also a high-risk operation because it alters model steering. Do NOT automatically modify your agent’s system prompt or global model configuration without manual review. If you must use decompression instructions, keep them minimal and review their exact text. - LLM use paths: The code contains LLM prompt templates and both rule-based and LLM-driven extraction paths. By default many commands use rule-based functions, but some utilities can generate prompts for LLMs. Before enabling any LLM-based compression, verify there are no unintended network endpoints and confirm which prompts/data would be sent out. - Run safely first: Use the --dry-run/benchmark modes and run on a copy of your workspace. Inspect generated artifacts (memory/.observed-sessions.json, memory/.codebook.json, memory/observations/) and the code paths that would call an LLM (search for code that invokes network libraries or external APIs in the omitted files). - Check for hidden characters: Scan README/SKILL.md and compressed text for zero-width or control characters that could hide instructions (tools like `cat -v`, hexdump, or editors that show invisibles can help). - Review compressed_context behavior: aggressive 'ultra' compression removes many function words and applies abbreviations; ensure the resulting compressed text + decompression instructions preserve all facts you care about and that you trust the decompression guidance. If you are not comfortable auditing the code paths that might call an external LLM or that will modify model prompts, consider running the tool in an isolated environment or container and only using the purely rule-based (no-LLM) modes.
功能分析
Type: OpenClaw Skill Name: cut-your-tokens-97percent-savings-on-session-transcripts-via-observation-extraction Version: 6.0.0 The skill accesses sensitive session transcripts from `~/.openclaw/sessions` via `scripts/observation_compressor.py` and `scripts/mem_compress.py`. While this is explicitly stated as part of its 'session observation compression' purpose, accessing such a sensitive directory without clear external data exfiltration (which is not present here) still represents a high-risk capability. Additionally, the `install` command in `scripts/mem_compress.py` modifies the workspace's `HEARTBEAT.md` file to enable self-maintenance, which is a form of self-modification of the agent's environment. These actions, while aligned with the stated purpose, introduce risky capabilities that warrant a 'suspicious' classification rather than 'benign' due to the strict threshold for this task.
能力评估
Purpose & Capability
The name/description (token/workspace compression, observation extraction) align with the included code: compression, dictionary, RLE, observation extraction, tiered summaries, and tokenizer optimizers are all present. File accesses (workspace markdown files and a memory/ folder) are expected for this purpose.
Instruction Scope
Runtime instructions and code will read session transcripts from ~/.openclaw/sessions and write compressed observations into workspace memory/.observed-sessions.json and memory/observations/. The compressed_context module explicitly produces 'decompression instructions' intended to be prepended to a model/system prompt — recommending edits to system prompts is powerful and can be abused for prompt-injection. The SKILL.md and source contain LLM prompt templates (COMPRESS_PROMPT) and text that could be used to call LLMs if a user enables that path; you should confirm that you do not inadvertently send sensitive session content to an external LLM. Overall the file operations are coherent with the stated purpose but the system-prompt modification guidance and presence of LLM prompts raise safety concerns.
Install Mechanism
No remote download/install spec is present — the skill is provided as code files (pyproject, scripts). Nothing in the manifest points to fetching arbitrary remote binaries or archives. That reduces supply-chain risk compared to an external download.
Credentials
The skill requests no environment variables, no external credentials, and no special config paths in the registry metadata. Its runtime behavior reads local workspace files and the user's session directory (~/.openclaw/sessions), which is proportionate to a session-transcript compressor but is sensitive data access — the absence of credentials is appropriate.
Persistence & Privilege
The skill is not always-enabled and does not request elevated platform privileges. It writes artifacts inside the workspace (memory/.observed-sessions.json, memory/observations/, memory/.codebook.json) which is expected. However the SKILL.md and compressed_context code recommend prepending decompression instructions to system prompts — that would change model behavior if applied; do not modify system prompts automatically without review. Autonomous invocation (default) is normal but combine caution with the instruction-scope concerns above.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install cut-your-tokens-97percent-savings-on-session-transcripts-via-observation-extraction
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /cut-your-tokens-97percent-savings-on-session-transcripts-via-observation-extraction 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v6.0.0
- Rebranded from "OpenClaw Token Compressor" to "Claw Compactor" with version update to v6.0. - Project directory, command, and configuration file references updated for the new name. - Added a new banner image (assets/banner.png). - Minor text and credit updates throughout documentation.
v5.11.0
OpenClaw Token Compressor initial release. - Compress your entire AI agent workspace with 5-layered, mostly lossless techniques—achieving 50%+ token savings. - Supports rule-based compression, dictionary encoding, session observation compression (~97% savings), and tiered summaries for progressive context loading. - CJK-aware and fully deterministic; does not require LLMs. - Unified command line tool (`mem_compress.py`), modular design, and easy integration. - Optional config, detailed troubleshooting, and real-world savings data included.
元数据
Slug cut-your-tokens-97percent-savings-on-session-transcripts-via-observation-extraction
版本 6.0.0
许可证
累计安装 4
当前安装数 4
历史版本数 2
常见问题

claw-compactor 是什么?

Claw Compactor v6.0 — 50%+ savings through rule-based compression, dictionary encoding, session observation compression, and progressive context loading. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1421 次。

如何安装 claw-compactor?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install cut-your-tokens-97percent-savings-on-session-transcripts-via-observation-extraction」即可一键安装,无需额外配置。

claw-compactor 是免费的吗?

是的,claw-compactor 完全免费(开源免费),可自由下载、安装和使用。

claw-compactor 支持哪些平台?

claw-compactor 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 claw-compactor?

由 aeromomo(@aeromomo)开发并维护,当前版本 v6.0.0。

💬 留言讨论