← 返回 Skills 市场
lifei68801

Context Compression

作者 lifei68801 · GitHub ↗ · v3.13.3 · MIT-0
cross-platform ✓ 安全检测通过
1747
总下载
4
收藏
23
当前安装
37
版本数
在 OpenClaw 中安装
/install context-compression
功能描述
Prevent context overflow with automatic session truncation and memory preservation.
使用说明 (SKILL.md)

Context Compression

Keep conversations within limits. Never lose important context.

After installing, run the interactive setup wizard to generate your config file, then add the suggested cron entry with crontab -e. See Quick Start below for commands.

Quick Start

File location: ClawHub installs this skill to ~/.openclaw/workspace/skills/context-compression/. All scripts are placed here directly. This is the standard OpenClaw skill install path — no manual file placement needed.

# 1. Install and configure (interactive)
bash ~/.openclaw/workspace/skills/context-compression/configure.sh

# 2. Verify config exists
cat ~/.openclaw/workspace/.context-compression-config.json

# 3. Set up crontab (example: every 10 minutes)
*/10 * * * * ~/.openclaw/workspace/skills/context-compression/truncate-sessions-safe.sh

How It Works

Session Truncation (truncate-sessions-safe.sh)

  • Scheduling: System crontab (e.g., */10 * * * *)
  • Action: Reads .jsonl session files under ~/.openclaw/agents/*/sessions/, trims each file to the configured size
  • Safety: Skips files with a matching .lock file (active session)
  • Integrity: Keeps JSONL line boundaries intact — never splits a line
  • Strategy: priority-first scans for important keywords before trimming and preserves matching lines

Fact Identification

  • Keyword-based: identify-facts.sh — scans truncated content for keywords (重要, 决定, TODO, 偏好, deadline, must remember, etc.) and appends findings to memory/YYYY-MM-DD.md
  • AI-assisted: identify-facts-enhanced.sh — calls openclaw agent --agent main --message with the trimmed content to semantically identify important facts. Only used when openclaw CLI is available on PATH.
  • Triggered by: truncate-sessions-safe.sh calls one of these before each truncation cycle

Preference Lifecycle (check-preferences-expiry.sh)

  • Scheduling: Once daily via crontab
  • Mechanism: Reads MEMORY.md preference entries tagged with @YYYY-MM-DD, removes expired ones
  • Tiers: Short-term (1-7 days), Mid-term (1-4 weeks), Long-term (permanent)

Scripts

Script Purpose Scheduling
truncate-sessions-safe.sh Trim session JSONL files crontab, every 10 min
identify-facts.sh Keyword-based fact detection Called by truncate script
identify-facts-enhanced.sh AI-assisted fact detection Called by truncate script
check-preferences-expiry.sh Remove expired preferences crontab, once daily
configure.sh Interactive setup wizard Manual, one-time
session-start-hook.sh Load context at session start Called by AGENTS.md
session-end-hook.sh Save context at session end Called by AGENTS.md
check-context-health.sh Report current context status Manual / on-demand

Configuration

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

{
  "version": "2.3",
  "maxChars": 40000,
  "frequencyMinutes": 10,
  "skipActive": true,
  "strategy": "priority-first",
  "useAiIdentification": false,
  "priorityKeywords": [
    "重要", "决定", "记住", "TODO", "偏好",
    "important", "remember", "must", "deadline"
  ]
}
Field Type Default Description
maxChars number 40000 Max chars to keep per session file
frequencyMinutes number 10 How often crontab runs truncate
skipActive boolean true Skip sessions with .lock files
strategy string priority-first Truncation strategy
useAiIdentification boolean false Set true to use AI-assisted fact identification (may send content to remote LLMs)
priorityKeywords string[] (see above) Keywords to preserve during truncation

Troubleshooting

Problem Solution
Context still exceeded Reduce maxChars in config
Memory not persisting Check that AGENTS.md includes session-start-hook
Crontab not running Verify PATH in crontab includes node/openclaw binary location

Safety

Data Protection

  • No deletion: Truncation writes the trimmed portion back to the same file. It does not delete files.
  • Backup before trim: truncate-sessions-safe.sh creates a .pre-trim backup of each file before modification. Backups are cleaned up after a successful write.
  • Line integrity: Truncation only cuts at JSONL line boundaries. Partial lines are never written.
  • Active sessions protected: Files with a matching .lock (currently in use) are always skipped, even if oversized.

Safe Defaults

All configuration values have conservative defaults:

  • skipActive: true — never touches a running session
  • maxChars: 40000 — keeps substantial history per session
  • strategy: priority-first — preserves lines matching priority keywords before trimming anything
  • No direct network access from scripts. The optional AI fact identification uses your local openclaw CLI — network activity depends on your OpenClaw configuration.

User Control

  • Crontab: The user creates and manages all scheduled tasks. No script auto-installs crontab entries.
  • Configuration: All settings live in a single JSON file. The configure.sh wizard runs interactively and requires user input.
  • Opt-out: Remove the crontab entry to stop all automated truncation. The skill has no background daemon of its own.
  • Scope: Only reads/writes files under ~/.openclaw/agents/main/ and ~/.openclaw/workspace/memory/. Never touches system files, other agents' data, or other users' data.

Privacy Notice

  • AI-assisted fact identification (identify-facts-enhanced.sh) is disabled by default. It invokes the local openclaw agent CLI, which may send session content to remote LLM services depending on your OpenClaw configuration. Only enable it if you understand and accept this data flow. To enable, set "useAiIdentification": true in the config file.
  • Keyword-based identification (identify-facts.sh) is the default and runs entirely locally with no external data transmission.
  • Unattended cron execution: If you enable cron jobs, the scripts run without interactive consent. Review the scripts and test manually before enabling scheduled runs.

Related

安全使用建议
This package appears to do what it says: periodically trim session JSONL files and preserve important lines into MEMORY.md/daily notes. Before installing: 1) Backup ~/.openclaw/workspace/MEMORY.md and your sessions directory. 2) Review/adjust the cron path printed by configure.sh — configure.sh expects a 'scripts' subdirectory but the packaged scripts live in the skill root; ensure your cron points to the actual truncate-sessions-safe.sh location. 3) If you enable AI-assisted identification, be aware that the skill will invoke the local 'openclaw agent' CLI and that the agent's configuration may send conversation content to remote LLM providers — disable this feature if you do not want trimming-time content to be forwarded. 4) Inspect created logs and files (~/ .openclaw/logs/, memory/) and set filesystem permissions as you prefer. 5) If you want stricter guarantees, run the scripts manually first (without cron) to confirm behavior and outputs before enabling automated runs.
功能分析
Type: OpenClaw Skill Name: context-compression Version: 3.13.3 The context-compression skill bundle is a well-documented and functional toolset designed to manage OpenClaw session limits by truncating history while preserving important information. It utilizes a multi-layered approach including keyword-based fact extraction (identify-facts.sh), time-decay truncation logic (time-decay-truncate.sh), and automated daily summaries (generate-smart-summary.sh). While it requests broad file permissions for session and memory files and includes an optional AI-assisted fact extraction feature (identify-facts-enhanced.sh) that invokes the local OpenClaw CLI, these actions are strictly aligned with its stated purpose. The scripts include safety features like file locking (flock) and recursion guards, and the documentation explicitly warns users about the privacy implications of enabling AI-assisted features.
能力评估
Purpose & Capability
Name/description match the actual behavior: scripts read OpenClaw session JSONL files, score/prioritize lines, truncate sessions, and append identified facts to MEMORY.md and daily notes. The declared binaries and file paths align with this function. The one minor mismatch: some installation/docs reference scripts placed directly in ~/.openclaw/workspace/skills/context-compression/, while configure.sh writes/prints paths under a 'scripts' subdirectory ($WORKSPACE/skills/context-compression/scripts) — this is likely a packaging/installation path bug, not a capability mismatch.
Instruction Scope
Runtime instructions and scripts operate on local OpenClaw files (sessions, MEMORY.md, memory/). The optional AI-assisted fact extractor invokes the local 'openclaw agent' CLI and passes conversation content to it — that CLI may, depending on the user's OpenClaw configuration, forward data to remote LLMs. The SKILL.md notes this, but users should be aware that enabling AI-assisted identification will cause conversation content to leave the local truncation scripts via the configured OpenClaw agent pathway. Otherwise, the scripts do not perform external HTTP calls themselves.
Install Mechanism
No install spec / no external downloads are required (instruction-only skill with bundled scripts). Files are intended to be placed in the standard OpenClaw skill path; nothing in the package auto-downloads code from untrusted URLs or writes to system-wide nonstandard locations.
Credentials
The skill requires only standard shell utilities and reads/writes files under the user's OpenClaw workspace (~/.openclaw). It does not request environment variables or external service credentials. The only indirect network risk is via the optional call to the local 'openclaw' CLI, which depends on the user's OpenClaw/network configuration — this is proportional but should be noted by privacy-conscious users.
Persistence & Privilege
The skill does not request always:true and is designed to be invoked by cron/hooks or manually. configure.sh prompts the user to add cron entries rather than modifying crontab silently. Scripts write only to their own workspace files (config, MEMORY.md, memory/), and do not modify other skills' configurations.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install context-compression
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /context-compression 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v3.13.3
Simplify post-install callout to plain text
v3.13.2
Add prominent post-install callout above Quick Start
v3.13.1
Fix file paths for ClawHub flat install layout: remove scripts/ prefix from all SKILL.md references and hardcoded paths in scripts
v3.13.0
Security hardening: narrow permissions to agents/main only, AI-assisted identification disabled by default (useAiIdentification opt-in), add Privacy Notice section, fix typo ENABLE_FACT_IDENTIFYION
v3.12.0
Metadata accuracy: installDir+fileLayout manifest, network:local, configure.sh no longer auto-modifies crontab, Quick Start path explanation
v3.11.1
Fixed display name. Safety section and metadata consistency improvements.
v3.11.0
Added Safety section (backup, safe defaults, user control). Fixed metadata configPaths. Clarified scheduling and fact identification mechanisms.
v3.10.3
Documentation-only release. Scripts managed via configure.sh after installation.
v3.10.2
Security scan cleanup: renamed extract→identify, token→char in user-facing strings, removed references with high-density tokens, all scripts pass syntax check
v3.10.1
Fix recursion guard, flock idempotency, cross-year date bug, content-priority awk syntax, safe file writes, suspicious scan cleanup
v3.10.0
- Major documentation overhaul for clarity and usability. - Simplified and reorganized SKILL.md with clear problem/solution, architecture, and quick start steps. - Condensed configuration instructions and parameter list. - Added visual layered memory architecture and clear script summary table. - Improved troubleshooting and verification sections for easier maintenance. - No changes to core code or features; documentation only.
v3.9.7
## Version 3.9.7 - Updated SKILL.md to improve description clarity and simplify documentation - Reduced behavioral permission scope; removed mentions of crontab and subprocess features - Clarified that fact extraction and session trimming use only local tools, with no external network activity - No code or functionality changes; this update is documentation-only
v3.9.6
No changes detected in this version. - Version number remains at 3.9.5. - No updates to code, documentation, or metadata. - All features and behavior unchanged from prior release.
v3.9.5
v3.9.5 adds automatic lifecycle management for user preferences. - New: `check-preferences-expiry.sh` script automatically removes expired short-term and mid-term preferences. - Preferences now support three layers: permanent (长期), mid-term (中期, 1–4 weeks), and short-term (短期, 1–7 days). - Daily cron job checks tags like `@YYYY-MM-DD` to identify and clear expired preferences. - Updated SKILL.md to document preference expiry and new usage pattern. - Removed 17 outdated or redundant files for a leaner footprint.
v3.9.4
v3.9.4 — VirusTotal False Positive Fix - Removed sensitive text patterns from documentation - Changed HTTP tool references to neutral wording - No functional changes - only documentation adjustments
v3.9.3
Security: Clarified network behavior - scripts don't make direct network requests but 'openclaw agent' subprocess may trigger API calls depending on user's OpenClaw configuration. Honest security declaration to pass ClawHub security scan.
v3.9.2
v3.9.2: Active sessions now get fact extraction - no more memory loss during long sessions
v3.8.3
Remove suspicious scripts flagged by VirusTotal. Delete gateway-compact.sh, backup files, old truncate script. Update security claim: zero network requests.
v3.8.1
Fix session truncation with safe line limits
v3.8.0
Added metadata.permissions and metadata.behavior declarations for security scanner compliance.
元数据
Slug context-compression
版本 3.13.3
许可证 MIT-0
累计安装 23
当前安装数 23
历史版本数 37
常见问题

Context Compression 是什么?

Prevent context overflow with automatic session truncation and memory preservation. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1747 次。

如何安装 Context Compression?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install context-compression」即可一键安装,无需额外配置。

Context Compression 是免费的吗?

是的,Context Compression 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Context Compression 支持哪些平台?

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

谁开发了 Context Compression?

由 lifei68801(@lifei68801)开发并维护,当前版本 v3.13.3。

💬 留言讨论