Clever Compact
Publisher: Axiom Stream Group
Version: 2.2.3
Tier: Free
Requires: OpenClaw ≥ 2026.3.7 · Recommended: 2026.3.12+ (fixes double-compaction loop)
ClaWHub: https://clawhub.ai/jfulmines-star/clever-compact
Support: kit@axiomstreamgroup.com
What This Skill Does
Clever Compact fixes the three memory failure modes that hit every serious OpenClaw user:
- -
/new amnesia — you start a fresh session and your agent acts like it's never met you - Compaction loss — context fills up, compact fires, the agent forgets what you were doing mid-task
- Memory drift — decisions made three sessions ago quietly disappear; the agent makes the same mistake again
v2 is a native OpenClaw plugin with two parts:
Part 1 — Session restore (automatic)
At the start of every session (including after
/new and after compaction), Clever Compact checks for a recent state file. If one exists (written within 72 hours), it injects the content as system context on the
first turn only. Your agent wakes up oriented — no repeated context injections, no per-turn token overhead.
Part 2 — State write (triggered)
OpenClaw does not currently expose a pre-compaction lifecycle hook, so the write side is
triggered explicitly — not automatic. You have three options:
- 1. Manual trigger: Tell your agent
"Run a Clever Compact flush and save state." It writes memory/compact-state-YYYY-MM-DD-HHmm.md immediately. - Pre-compact cron: Set up a cron job that fires before your scheduled compact with the system event:
"Pre-compaction memory flush. Store durable memories now." Your agent writes state, then compact fires. - Heartbeat entry: Add a flush step to your
HEARTBEAT.md that periodically writes state — no timing races because it runs on demand.
The plugin also exposes api.fn("clever-compact:write") so any tool in your stack can trigger a state write programmatically.
Security & Privacy
State files are stored as plaintext Markdown in your memory/ directory. They are local to your machine and not transmitted anywhere by this plugin.
Do not include in state files:
- - API keys, tokens, or secrets
- Passwords or credentials
- Private personal information you wouldn't put in a text file
The plugin generates a reminder header in every state file. Review memory/compact-state-*.md periodically and remove any sensitive content that may have been captured inadvertently.
The api.fn("clever-compact:write") exposure is intentional — it allows your heartbeat, cron, or other tools to trigger a state flush programmatically. Audit any automation that calls this function to ensure it writes only session context, not credentials.
How the write side works
Your agent is active and responsive right up until compact fires — so a cron job 5 minutes before your scheduled compact, or a heartbeat flush at 75% context, gives you a clean, predictable save point every time.
When OpenClaw ships a pre-compaction lifecycle hook, Clever Compact will use it automatically. Until then, the cron + heartbeat pattern is the right architecture — and it works.
Installation
Requires OpenClaw ≥ 2026.3.7
Step 1 — Install the plugin:
CODEBLOCK0
Or copy the folder to ~/.openclaw/extensions/clever-compact/.
Step 2 — Add to plugins.allow in ~/.openclaw/openclaw.json:
CODEBLOCK1
Step 3 — Restart the gateway:
CODEBLOCK2
Step 4 — Set up a flush trigger (pick one):
Option A — Cron (recommended):
CODEBLOCK3
Option B — Heartbeat:
Add to HEARTBEAT.md:
CODEBLOCK4
Option C — Manual:
Tell your agent: "Run a Clever Compact flush and save state."
State file format
CODEBLOCK5
State files live in memory/ and are ignored after 72 hours.
Reduce compaction frequency (recommended)
Push compaction later in the context window by lowering reserveTokens:
CODEBLOCK6
Default is 50,000 (fires at ~150k/200k). Setting to 15,000 fires at ~185k — roughly 3–4× fewer compactions per heavy session.
Migration from v2.0 / v2.1
The injection behavior is unchanged. One fix to apply:
v2.0/v2.1 injected the state file on every prompt turn — this added token overhead mid-session and contributed to faster compactions. v2.2.0 injects only once per session (first turn). No other changes needed; your existing state files and cron setup carry over.
Migration from v1
- 1. Remove the Clever Compact blocks from your INLINECODE17
- Remove heartbeat entries that referenced the pre-compact scan
- Follow the v2 installation steps above
- Existing state files in
memory/ are picked up automatically
Changelog
- - 2.2.3 (2026-03-16): Version sync across all files (package.json, openclaw.plugin.json, index.ts were mismatched). Fixed install step count in description. Updated recommended OpenClaw version to 2026.3.12+. Rewrote defensive "explicit write" section. No functional changes.
- 2.2.0 (2026-03-11): Fixed per-turn injection (now injects once at session start only — eliminates mid-session token overhead). Accurately documents write side as explicit/triggered, not automatic. Exposes
clever-compact:write fn for programmatic state writes. No breaking changes. - 2.1.0 (2026-03-10): Added
writeState() export. Clarified hooks. - 2.0.0 (2026-03-08): Full rewrite as native OpenClaw plugin. Requires OpenClaw ≥ 2026.3.7. Breaking change from v1.
- 1.3.1 (2026-03-06): Clarified config/reference language. No functional changes.
- 1.3.0 (2026-03-05): Fully free. All features available at no cost.
- 1.2.0 (2026-03-04): Reframed around the three failure modes.
- 1.1.0 (2026-03-03): Added
reserveTokens tuning guide. - 1.0.0 (2026-03-01): Initial release.
Built by Axiom Stream Group — axiomstreamgroup.com
We built this because we needed it. We run it on our own agents every day.
Clever Compact
发布者: Axiom Stream Group
版本: 2.2.3
层级: 免费
要求: OpenClaw ≥ 2026.3.7 · 推荐:2026.3.12+(修复双重压缩循环)
ClaWHub: https://clawhub.ai/jfulmines-star/clever-compact
支持: kit@axiomstreamgroup.com
此技能的功能
Clever Compact 修复了每位重度 OpenClaw 用户都会遇到的三种内存故障模式:
- - /new 失忆症 — 你开始一个新会话,你的代理表现得好像从未见过你
- 压缩丢失 — 上下文填满,压缩触发,代理忘记你在任务中途正在做什么
- 记忆漂移 — 三个会话前做出的决定悄然消失;代理再次犯同样的错误
v2 是一个原生 OpenClaw 插件,包含两个部分:
第一部分 — 会话恢复(自动)
在每个会话开始时(包括 /new 之后和压缩之后),Clever Compact 会检查最近的状态文件。如果存在(在 72 小时内写入),它会在
第一轮仅一次将内容注入为系统上下文。你的代理醒来时已定位——无需重复注入上下文,无需每轮令牌开销。
第二部分 — 状态写入(触发式)
OpenClaw 目前不暴露压缩前的生命周期钩子,因此写入端是
显式触发的——而非自动。你有三种选择:
- 1. 手动触发: 告诉你的代理 运行 Clever Compact 刷新并保存状态。 它会立即写入 memory/compact-state-YYYY-MM-DD-HHmm.md。
- 压缩前定时任务: 设置一个定时任务,在计划压缩前触发系统事件:压缩前内存刷新。立即存储持久记忆。 你的代理写入状态,然后压缩触发。
- 心跳条目: 在 HEARTBEAT.md 中添加一个刷新步骤,定期写入状态——无时序竞争,因为它按需运行。
该插件还暴露了 api.fn(clever-compact:write),因此你堆栈中的任何工具都可以以编程方式触发状态写入。
安全与隐私
状态文件以纯文本 Markdown 格式存储在你的 memory/ 目录中。它们位于你的本地机器上,不会被此插件传输到任何地方。
状态文件中不得包含:
- - API 密钥、令牌或机密
- 密码或凭证
- 你不会放在文本文件中的私人个人信息
该插件在每个状态文件中生成一个提醒头。定期检查 memory/compact-state-*.md 并删除任何可能无意中被捕获的敏感内容。
api.fn(clever-compact:write) 的暴露是有意为之——它允许你的心跳、定时任务或其他工具以编程方式触发状态刷新。审计任何调用此函数的自动化程序,确保它只写入会话上下文,而不是凭证。
写入端的工作原理
你的代理在压缩触发前一直保持活跃和响应——因此在计划压缩前 5 分钟设置定时任务,或在上下文达到 75% 时进行心跳刷新,每次都能提供一个干净、可预测的保存点。
当 OpenClaw 发布压缩前生命周期钩子时,Clever Compact 将自动使用它。在此之前,定时任务 + 心跳模式是正确的架构——并且它有效。
安装
需要 OpenClaw ≥ 2026.3.7
步骤 1 — 安装插件:
bash
openclaw plugins install ./skills/clever-compact
或者将文件夹复制到 ~/.openclaw/extensions/clever-compact/。
步骤 2 — 在 ~/.openclaw/openclaw.json 的 plugins.allow 中添加:
json
{
plugins: {
allow: [clever-compact]
}
}
步骤 3 — 重启网关:
bash
openclaw gateway restart
步骤 4 — 设置刷新触发器(选择一种):
选项 A — 定时任务(推荐):
计划:在夜间压缩前 5 分钟
负载:压缩前内存刷新。立即存储持久记忆 (memory/YYYY-MM-DD.md)。如果无内容可存储,回复 NO_REPLY。
选项 B — 心跳:
添加到 HEARTBEAT.md:
markdown
上下文刷新(每次心跳在上下文 > 75% 时)
- - 如果上下文 > 75%:运行 Clever Compact 刷新 — 将状态写入 memory/compact-state-YYYY-MM-DD-HHmm.md
选项 C — 手动:
告诉你的代理:运行 Clever Compact 刷新并保存状态。
状态文件格式
markdown
压缩状态 — [ISO 时间戳]
由 Clever Compact v2.2.0 生成 | Axiom Stream Group
活跃工作流
| 名称 | 状态 | 阻塞项 | 备注 |
|---|
| [名称] | 进行中 | [阻塞项 或 —] | [关键上下文] |
关键决策
开放任务
记住标记
下一会话:在响应任何内容之前读取此文件。
状态文件位于 memory/ 中,72 小时后被忽略。
减少压缩频率(推荐)
通过降低 reserveTokens 将压缩推迟到上下文窗口的后期:
json
{
agents: {
defaults: {
compaction: {
mode: safeguard,
reserveTokens: 15000
}
}
}
}
默认值为 50,000(在约 150k/200k 时触发)。设置为 15,000 在约 185k 时触发——每个重度会话大约减少 3–4 倍压缩次数。
从 v2.0 / v2.1 迁移
注入行为未变。需要应用一个修复:
v2.0/v2.1 在每次提示轮次都注入状态文件——这在会话中期增加了令牌开销,并导致更快的压缩。v2.2.0 仅在每个会话中注入一次(第一轮)。无需其他更改;你现有的状态文件和定时任务设置会延续。
从 v1 迁移
- 1. 从你的 AGENTS.md 中移除 Clever Compact 块
- 移除引用压缩前扫描的心跳条目
- 按照上述 v2 安装步骤操作
- memory/ 中现有的状态文件会被自动拾取
更新日志
- - 2.2.3(2026-03-16):所有文件版本同步(package.json、openclaw.plugin.json、index.ts 之前不匹配)。修复了描述中的安装步骤计数。更新了推荐的 OpenClaw 版本至 2026.3.12+。重写了防御性显式写入部分。无功能变更。
- 2.2.0(2026-03-11):修复了每轮注入(现在仅在会话开始时注入一次——消除了会话中期的令牌开销)。准确地将写入端记录为显式/触发式,而非自动。暴露了 clever-compact:write 函数用于程序化状态写入。无破坏性变更。
- 2.1.0(2026-03-10):添加了 writeState() 导出。澄清了钩子。
- 2.0.0(2026-03-08):完全重写为原生 OpenClaw 插件。需要 OpenClaw ≥ 2026.3.7。与 v1 相比为破坏性变更。
- 1.3.1(2026-03-06):澄清了配置/参考语言。无功能变更。
- 1.3.0(2026-03-05):完全免费。所有功能免费提供。
- 1.2.0(2026-03-04):围绕三种故障模式重新构建。
- 1.1.0(2026-03-03):添加了 reserveTokens 调优指南。
- 1.0.0(2026-03-01):初始发布。
由 Axiom Stream Group 构建 — axiomstreamgroup.com
我们构建它是因为我们需要它。我们每天都在自己的代理上运行它。