OpenClaw Plugin SDK hook for per-turn context compression via Compresh — episodic memory architecture for LLM conversations.
On every agent turn, the hook intercepts before_prompt_build, relays the conversation history to a local compresh-mcp process, and appends a compressed view of older turns to the system prompt. The protection-zone tail (last 2 / 4 / 8 turns depending on mode) stays raw and untouched in the message list.
Works with or without an account:
- No Compresh key → compression runs locally and free (open-source
tulbasecore: extractive LexRank summarization — fast, private, lossy). Nothing is sent anywhere. - With a Compresh key → paid models get TUL 2.0: query-aware retrieval on Compresh infrastructure. Instead of summarizing, it pulls the full, unedited older turns relevant to the current question — lossless.
Your provider API key never leaves OpenClaw in either mode. Only the transcript is sent to api.compre.sh — and only when a Compresh key is configured.
- OpenClaw v2026.5.0 or later
- Node.js 18+
compresh-mcp>=0.3.3— install withpipx install compresh-mcp. (Plainpip installfails on Homebrew/Debian system Python with PEP 668 "externally-managed-environment"; pipx is the fix. Check the installed version withpipx list | grep compresh— notcompresh-mcp --version, which starts the MCP server and waits on stdin.)
A Compresh API key (sk-comp_...) is optional. Get one with any of:
compresh-mcp login --google # sign in with Google…
compresh-mcp login --github # …or GitHub (instant, counts as verified)
compresh-mcp signup you@example.com # or email-only signup, no cardNew accounts include a 5-day free TUL 2.0 trial (no card, no commitment). Verify your email — or sign in with Google/GitHub, which counts as verified — and you get $30 of free Compresh credit (we waive our savings-share up to $30). When the trial ends with no credit, the hook falls back to free local tulbase automatically; you never lose compression.
openclaw plugins install npm:@compresh/openclaw-hookEdit ~/.openclaw/openclaw.json:
{
"plugins": {
"entries": {
"compresh": {
"hooks": {
"allowConversationAccess": true
},
"config": {
"protectionMode": "balanced"
}
}
}
}
}Add "apiKey": "sk-comp_..." to config to unlock TUL 2.0. Without it the plugin still compresses locally (free tulbase) and shows a one-time note about the upgrade path.
hooks.allowConversationAccess: true is required. Non-bundled plugins cannot read raw conversation hooks (before_prompt_build, llm_input, llm_output, etc.) without this opt-in.
| Key | Default | Notes |
|---|---|---|
apiKey |
$COMPRESH_API_KEY |
Optional. Unlocks TUL 2.0 retrieval on paid models; without it compression is local tulbase. |
binPath |
compresh-mcp |
Path to the compresh-mcp executable ($COMPRESH_BIN). If the gateway runs outside your shell (LaunchAgent/systemd), it may not inherit your PATH — set the full path from which compresh-mcp. |
binArgs |
— | Extra arguments passed to compresh-mcp ($COMPRESH_BIN_ARGS). |
protectionMode |
balanced |
aggressive / balanced / conservative — trailing raw turns (2 / 4 / 8). |
providerHint |
from context | Telemetry only. Derived from the active provider; fallback anthropic. |
modelHint |
from context | Telemetry only. Derived from the active model; fallback claude-sonnet-4-5. |
minMessages |
6 |
Skip compression below this turn count. |
timeoutMs |
10000 |
Timeout for the compress call. |
Env variable fallbacks (COMPRESH_API_KEY, COMPRESH_PROTECTION_MODE, etc.) work for every option.
[compresh] before_prompt_build sid=openclaw-abc12345 applied tier=pro_quarterly compressed=14/22 saving=18420chars
[compresh] llm_output sid=openclaw-abc12345 input=4210 output=850 budget=180000
| Tier | Budget required | Savings-share |
|---|---|---|
| No key / free / local models | — | 0% (free local tulbase compression) |
| Starter (free + loaded budget) | > $0 | 30% |
| Pro Quarterly ($18 / 3 mo) | — | 20% |
| Pro Semi-Annual ($33 / 6 mo) | — | 16% |
| Pro Annual ($60 / yr) | — | 12% |
Every verified account gets $30 free credit. Top-ups receive a permanent 25% discount at payment time. Full pricing: compre.sh/pricing.
- Without a Compresh key, nothing leaves your machine — compression is fully local.
- With a key, the conversation transcript is sent to
api.compre.sh/v1/tul2for retrieval. Processing is in-flight; no message content is stored. - Your provider API key (the one you use to call Claude / GPT / etc.) stays inside OpenClaw and is never sent to Compresh, in any mode.
- Per-call savings totals are logged to
/v1/usage/reportfor the dashboard. No message content is sent in telemetry.
A drop-in proxy means routing your provider key through Compresh — fewer privacy boundaries. A hook keeps the key inside OpenClaw and only inspects the transcript. For users who do not want their provider key to leave their machine, the hook path is the safer integration.
- Compresh: https://compre.sh
- Compresh docs: https://compre.sh/docs/overview
- Issues: https://github.com/compresh/openclaw-hook/issues
- OpenClaw Plugin SDK: https://docs.openclaw.ai/plugins/sdk-overview
- OpenClaw hook catalog: https://docs.openclaw.ai/plugins/hooks
MIT