← 返回 Skills 市场
bg1avd

Context Shrink

作者 Rao Lin · GitHub ↗ · v1.0.2 · MIT-0
cross-platform ⚠ suspicious
639
总下载
0
收藏
6
当前安装
3
版本数
在 OpenClaw 中安装
/install context-shrink
功能描述
Auto-compress session memories when context usage exceeds 85%
使用说明 (SKILL.md)

Context Shrink Hook

Auto-compresses session memories when context usage exceeds 60% threshold. Cleans up old daily logs and compresses them into MEMORY.md for long-term storage.

Features

  • 自动触发: 当 context 使用率 ≥ 85% 时自动执行
  • 智能清理: 保留最近 3 天的详细日志
  • 压缩存储: 旧日志压缩后写入 MEMORY.md
  • Git 提交: 自动 commit 变更记录

Configuration

CONTEXT_THRESHOLD = 0.85     // 85% 触发阈值
DAYS_TO_KEEP = 3           // 保留最近 N 天日志
MIN_FILES_TO_KEEP = 5      // 至少保留文件数
COMPRESSION_MODEL = 'ollama/qwen2.5:3b'

Changelog

1.0.0

  • Initial release
  • Auto-compression at 60% threshold
  • Git commit on cleanup
安全使用建议
This skill intends to compress and delete old session memory files and then commit changes to git — that behavior matches the description, but there are several red flags you should consider before installing: - The handler contains a logic bug that makes it return immediately (it checks for both 'message' and 'command' at the same time). Expect it to be non-functional until fixed. - HOOK.md requires node and git, but the registry metadata doesn't list these; the code calls git via execSync. Ensure node/git exist and understand that commits (and any future push) may expose data to configured remotes. - The skill deletes files from ~/.openclaw/workspace/memory (filtered by YYYY-MM-DD.md). Back up that workspace before enabling the hook. Although it writes compressed content to MEMORY.md and attempts a git commit, deletion is destructive unless you have a safe backup or repo history. - There is minor command-execution risk: execSync is used with interpolated workspaceDir and shell commands (cd ${workspaceDir} && git add -A). If workspaceDir can be influenced by untrusted input, that could lead to command injection; prefer safe argument passing or sanitization. - There are several content mismatches (60% vs 85% thresholds, 7 days vs 3 days retention). Ask the author to clarify the intended defaults and update documentation and package metadata to match the code. Recommendations before enabling: 1) Test in a disposable workspace (no sensitive data, no active git remotes) to observe behavior. 2) Back up your memory directory and/or ensure the workspace repo is local-only or has no remote push configured. 3) Fix the event-type logic so the handler triggers correctly (handle message and command events separately), and normalize threshold/retention values across SKILL.md, HOOK.md, package.json and handler.ts. 4) Replace execSync shell interpolation with safe child_process invocation (or at least properly quote/sanitize paths) to reduce injection risk. 5) Ask the publisher to update registry metadata to list required binaries (node/git) and to document whether git push will be performed automatically. If you cannot validate these items, treat the skill as risky and do not enable it on any workspace containing sensitive or production data.
功能分析
Type: OpenClaw Skill Name: context-shrink Version: 1.0.2 The skill contains a potential shell injection vulnerability in handler.ts, where the workspaceDir variable is used directly in an execSync call without sanitization or quoting. Additionally, the code contains a logical error in its event filtering (checking for both 'message' and 'command' types simultaneously) that effectively prevents the handler from ever executing. There are also inconsistencies between the documentation (HOOK.md) and the code (handler.ts) regarding the context usage threshold (60% vs 85%).
能力评估
Purpose & Capability
The handler implements deletion, compression into MEMORY.md, and git commits — which is coherent with 'context shrink'. However metadata/manifest inconsistencies exist: registry lists no required binaries/env, while HOOK.md documents required bins (node, git) and the code uses git. Defaults and comments in files disagree about trigger thresholds (60% vs 85%) and retention windows (HOOK.md says 7 days vs handler uses DAYS_TO_KEEP=3). These mismatches are unexpected and should be clarified.
Instruction Scope
The instructions and code are generally scoped to reading ~/.openclaw/workspace/memory, compressing and appending to MEMORY.md, deleting old files, and running git commits — all within the stated purpose. However the handler has a logic error: it checks for type === 'message' and then immediately checks for type === 'command', which cannot both be true, so the handler as written will early-return and never perform the intended work. SKILL.md/HOOK.md describe triggers (message:sent, command:reset) that the code does not properly handle. Also the code reads process.env.HOME and filesystem paths that are not declared in registry metadata.
Install Mechanism
No install script is provided (instruction-only + handler file). That keeps installation risk low. There are no remote downloads or archive extracts. However HOOK.md expects node and git to be present, which is a runtime requirement rather than an installation action.
Credentials
The skill declares no required environment variables or credentials, and its behavior mainly uses HOME (process.env.HOME) and the workspace path. That is proportionate, but the code performs file deletion and git commits which can affect local repositories and potentially expose data if a git remote is configured. The registry should explicitly declare required binaries (git) and any env assumptions.
Persistence & Privilege
always is false and the skill is a hook invoked on events (normal). It does not request permanent platform-wide privileges or modify other skills. Autonomous invocation is allowed by default and appropriate for a hook. No suspicious self-enablement behavior was found.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install context-shrink
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /context-shrink 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
- Increased context usage threshold for auto-compression from 60% to 85%. - Updated default compression model to 'ollama/qwen2.5:3b'. - Improved configuration documentation for clarity.
v1.0.1
- Changed type from "skill" to "hook" in SKILL.md. - No other changes detected.
v1.0.0
- Initial release of context-shrink skill - Automatically compresses session memories when context usage exceeds 60% - Retains detailed logs from the past 3 days; older logs are compressed into MEMORY.md - Cleans up daily logs and performs automatic git commit after changes
元数据
Slug context-shrink
版本 1.0.2
许可证 MIT-0
累计安装 6
当前安装数 6
历史版本数 3
常见问题

Context Shrink 是什么?

Auto-compress session memories when context usage exceeds 85%. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 639 次。

如何安装 Context Shrink?

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

Context Shrink 是免费的吗?

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

Context Shrink 支持哪些平台?

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

谁开发了 Context Shrink?

由 Rao Lin(@bg1avd)开发并维护,当前版本 v1.0.2。

💬 留言讨论