OpenClaw plugin for ContextPilot — faster long-context inference via in-process context optimization. Zero external dependencies — no Python, no proxy server, just install and go.
ContextPilot registers as an OpenClaw Context Engine and optimizes every LLM request by:
- Extracting documents from tool results
- Reordering documents for maximum prefix cache sharing across turns
- Deduplicating repeated content blocks with compact reference hints
- Injecting cache control markers (Anthropic
cache_control: { type: "ephemeral" })
All processing happens in-process — no external services needed.
openclaw plugins install @contextpilot-ai/contextpilotAdd to ~/.openclaw/openclaw.json:
{
"plugins": {
"load": {
"paths": [
"/path/to/ContextPilot/openclaw-plugin"
]
}
}
}In ~/.openclaw/openclaw.json, enable the plugin and set it as the context engine:
{
"plugins": {
"slots": {
"contextEngine": "contextpilot"
},
"entries": {
"contextpilot": {
"enabled": true,
"config": {
"scope": "all"
}
}
}
},
"tools": {
"allow": ["contextpilot"]
}
}| Scope | Tool Results | Description |
|---|---|---|
all (default) |
Optimized | Optimize all tool results |
tool_results |
Optimized | Same as all |
Note: System prompt optimization is not currently available — OpenClaw's context engine API does not expose the system prompt to plugins.
OpenClaw agent request
↓
ContextPilot Context Engine (assemble hook)
├─ Convert OpenClaw message format (toolResult → tool_result)
├─ Extract documents from tool results
├─ Reorder for prefix cache sharing
├─ Deduplicate repeated blocks
├─ Inject cache_control markers
↓
Optimized context → LLM Backend
The plugin registers as an OpenClaw Context Engine using api.registerContextEngine(). The assemble() hook intercepts context assembly before each LLM call.
openclaw-plugin/
├── openclaw.plugin.json # Plugin manifest (id: "contextpilot")
├── package.json # npm package (@contextpilot-ai/contextpilot)
├── src/
│ ├── index.ts # Plugin entry point
│ └── engine/
│ ├── cache-control.ts # Cache control injection
│ ├── dedup.ts # Content deduplication
│ ├── extract.ts # Document extraction
│ └── live-index.ts # Reordering engine
└── tsconfig.json
| Tool | Description |
|---|---|
contextpilot_status |
Check engine status, request count, and chars saved |
Note: The status tool is registered but may not be visible to agents due to OpenClaw plugin API limitations.
Check the gateway logs:
[ContextPilot] Stats: 5 requests, 28,356 chars saved (~7,089 tokens, ~$0.0213)
Savings depend on conversation length and repeated content:
| Scenario | Chars Saved | Token Reduction |
|---|---|---|
| Short session (few tool calls) | 0-5K | ~0-5% |
| Medium session (10+ file reads) | 20-50K | ~10-20% |
| Long session (repeated large files) | 100K+ | ~30-50% |
Run ./benchmark.sh to measure with/without comparison on your workload.
Apache-2.0