← 返回 Skills 市场
emberdesire

Context Compactor

作者 emberDesire · GitHub ↗ · v0.3.8
cross-platform ⚠ suspicious
1717
总下载
0
收藏
4
当前安装
5
版本数
在 OpenClaw 中安装
/install context-compactor
功能描述
Token-based context compaction for local models (MLX, llama.cpp, Ollama) that don't report context limits.
使用说明 (SKILL.md)

Context Compactor

Automatic context compaction for OpenClaw when using local models that don't properly report token limits or context overflow errors.

The Problem

Cloud APIs (Anthropic, OpenAI) report context overflow errors, allowing OpenClaw's built-in compaction to trigger. Local models (MLX, llama.cpp, Ollama) often:

  • Silently truncate context
  • Return garbage when context is exceeded
  • Don't report accurate token counts

This leaves you with broken conversations when context gets too long.

The Solution

Context Compactor estimates tokens client-side and proactively summarizes older messages before hitting the model's limit.

How It Works

┌─────────────────────────────────────────────────────────────┐
│  1. Message arrives                                         │
│  2. before_agent_start hook fires                           │
│  3. Plugin estimates total context tokens                   │
│  4. If over maxTokens:                                      │
│     a. Split into "old" and "recent" messages              │
│     b. Summarize old messages (LLM or fallback)            │
│     c. Inject summary as compacted context                 │
│  5. Agent sees: summary + recent + new message             │
└─────────────────────────────────────────────────────────────┘

Installation

# One command setup (recommended)
npx jasper-context-compactor setup

# Restart gateway
openclaw gateway restart

The setup command automatically:

  • Copies plugin files to ~/.openclaw/extensions/context-compactor/
  • Adds plugin config to openclaw.json with sensible defaults

Configuration

Add to openclaw.json:

{
  "plugins": {
    "entries": {
      "context-compactor": {
        "enabled": true,
        "config": {
          "maxTokens": 8000,
          "keepRecentTokens": 2000,
          "summaryMaxTokens": 1000,
          "charsPerToken": 4
        }
      }
    }
  }
}

Options

Option Default Description
enabled true Enable/disable the plugin
maxTokens 8000 Max context tokens before compaction
keepRecentTokens 2000 Tokens to preserve from recent messages
summaryMaxTokens 1000 Max tokens for the summary
charsPerToken 4 Token estimation ratio
summaryModel (session model) Model to use for summarization

Tuning for Your Model

MLX (8K context models):

{
  "maxTokens": 6000,
  "keepRecentTokens": 1500,
  "charsPerToken": 4
}

Larger context (32K models):

{
  "maxTokens": 28000,
  "keepRecentTokens": 4000,
  "charsPerToken": 4
}

Small context (4K models):

{
  "maxTokens": 3000,
  "keepRecentTokens": 800,
  "charsPerToken": 4
}

Commands

/compact-now

Force clear the summary cache and trigger fresh compaction on next message.

/compact-now

/context-stats

Show current context token usage and whether compaction would trigger.

/context-stats

Output:

📊 Context Stats

Messages: 47 total
- User: 23
- Assistant: 24
- System: 0

Estimated Tokens: ~6,234
Limit: 8,000
Usage: 77.9%

✅ Within limits

How Summarization Works

When compaction triggers:

  1. Split messages into "old" (to summarize) and "recent" (to keep)
  2. Generate summary using the session model (or configured summaryModel)
  3. Cache the summary to avoid regenerating for the same content
  4. Inject context with the summary prepended

If the LLM runtime isn't available (e.g., during startup), a fallback truncation-based summary is used.

Differences from Built-in Compaction

Feature Built-in Context Compactor
Trigger Model reports overflow Token estimate threshold
Works with local models ❌ (need overflow error)
Persists to transcript ❌ (session-only)
Summarization Pi runtime Plugin LLM call

Context Compactor is complementary — it catches cases before they hit the model's hard limit.

Troubleshooting

Summary quality is poor:

  • Try a better summaryModel
  • Increase summaryMaxTokens
  • The fallback truncation is used if LLM runtime isn't available

Compaction triggers too often:

  • Increase maxTokens
  • Decrease keepRecentTokens (keeps less, summarizes earlier)

Not compacting when expected:

  • Check /context-stats to see current usage
  • Verify enabled: true in config
  • Check logs for [context-compactor] messages

Characters per token wrong:

  • Default of 4 works for English
  • Try 3 for CJK languages
  • Try 5 for highly technical content

Logs

Enable debug logging:

{
  "plugins": {
    "entries": {
      "context-compactor": {
        "config": {
          "logLevel": "debug"
        }
      }
    }
  }
}

Look for:

  • [context-compactor] Current context: ~XXXX tokens
  • [context-compactor] Compacted X messages → summary

Links

安全使用建议
This plugin is internally coherent and appears to do what it claims: estimate tokens, summarize older messages, and inject a compacted summary for local models. Before installing: - Verify the package source: check the npm page and GitHub repo referenced in the README (ensure they match the publisher you trust). npx will fetch remote code, so confirm the package contents/maintainer. - Backup your openclaw.json (the CLI already does this, but you can manually back up before running commands). - Review the included files (index.ts, cli.js) locally if possible rather than running npx directly, or install from a tarball you inspected. - If you use sensitive local providers, confirm the plugin's modelFilter setting so it only runs where you want it. If you want higher assurance, run the CLI from a checked-out copy of this repository instead of via npx so you control the exact code being executed.
功能分析
Type: OpenClaw Skill Name: context-compactor Version: 0.3.8 The skill is classified as suspicious due to the `cli.js` script's extensive file system access and modification capabilities, specifically its ability to read and write to `~/.openclaw/openclaw.json`. While the script explicitly states its privacy policy, asks for user consent, and its current implementation appears to only extract non-sensitive configuration parameters relevant to its function (model IDs, context windows, base URLs), the inherent capability to access and modify a file that can contain sensitive data (like API keys) without clear evidence of malicious intent warrants a 'suspicious' classification. No evidence of data exfiltration, remote code execution, or malicious prompt injection against the agent was found in `SKILL.md`, `README.md`, or `index.ts`.
能力评估
Purpose & Capability
Name/description (context compaction for local LLMs) align with the included code and runtime instructions. The plugin inspects OpenClaw config, reads session transcripts, estimates tokens, summarizes old messages, and prepends a summary — all consistent with the stated functionality.
Instruction Scope
SKILL.md and the code limit actions to reading openclaw.json (with an explicit prompt in the CLI), reading session transcripts (when provided by the runtime), writing plugin files into ~/.openclaw/extensions/, and calling the local OpenClaw LLM runtime for summaries. There are no instructions to read unrelated system files, access unrelated env vars, or transmit data to external endpoints.
Install Mechanism
There is no formal install spec in the registry, but SKILL.md instructs using `npx jasper-context-compactor setup`. Running via npx will fetch the package from npm, which is normal but carries the usual supply-chain risk (downloading and executing remote code). The included CLI copies files into ~/.openclaw/extensions — expected for a plugin installer. Recommend verifying the npm package and GitHub repository before running npx.
Credentials
The skill requests no environment variables, no credentials, and no config paths beyond user OpenClaw config paths under the user's home directory. The code only touches ~/.openclaw/, consistent with its purpose.
Persistence & Privilege
The skill does not request always:true or system-wide elevated privileges. The installer writes plugin files under the user's home (~/.openclaw/extensions/context-compactor) and updates openclaw.json — reasonable for a user-installed plugin. It does not modify other skills' configs or system settings beyond the user's OpenClaw config.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install context-compactor
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /context-compactor 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.3.8
v0.3.8: Enhanced Ollama detection
v0.3.0
Safer setup: backs up config, asks consent, clearer docs
v0.2.0
Interactive setup: detects model, suggests token limits, asks permission first
v0.1.1
Added setup CLI: npx openclaw-context-compactor setup
v0.1.0
Initial release: Token-based context compaction for local models (MLX, llama.cpp, Ollama)
元数据
Slug context-compactor
版本 0.3.8
许可证
累计安装 4
当前安装数 4
历史版本数 5
常见问题

Context Compactor 是什么?

Token-based context compaction for local models (MLX, llama.cpp, Ollama) that don't report context limits. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1717 次。

如何安装 Context Compactor?

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

Context Compactor 是免费的吗?

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

Context Compactor 支持哪些平台?

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

谁开发了 Context Compactor?

由 emberDesire(@emberdesire)开发并维护,当前版本 v0.3.8。

💬 留言讨论