An optimization suite for OpenClaw agents to prevent token leaks and context bloat.
- 🔒 Cron Isolation — Run background tasks without polluting your main context
- 🔍 Local RAG — Semantic search over memory files instead of loading everything
- 🔄 Reset & Summarize — Protocol for context consolidation when hitting limits
- 📜 Transcript Indexing — Search through old session transcripts
- ⚡ Hybrid Search — Combine vector and keyword search for better recall
openclaw skill install token-optimizer- Clone this repository into your skills folder:
cd ~/.openclaw/workspace/skills/
git clone https://github.com/D4kooo/Openclaw-Token-memory-optimizer/tree/main- The skill will be automatically detected by OpenClaw.
In your openclaw.json, set sessionTarget: "isolated" for cron jobs:
{
"cron": {
"jobs": [
{
"name": "My Background Task",
"schedule": { "kind": "every", "everyMs": 1800000 },
"sessionTarget": "isolated",
"payload": {
"kind": "agentTurn",
"message": "Do the thing. Use message tool if human needs to know."
}
}
]
}
}Configure semantic search for your memory files:
{
"memorySearch": {
"embedding": {
"provider": "local",
"model": "hf:second-state/All-MiniLM-L6-v2-Embedding-GGUF"
},
"store": "sqlite"
}
}When context exceeds 100k tokens:
- Ask your agent to summarize the session
- Update MEMORY.md with important facts
- Run
openclaw gateway restart
| Setting | Description | Default |
|---|---|---|
memorySearch.embedding.provider |
Embedding provider (local, openai) |
— |
memorySearch.embedding.model |
Model for embeddings | — |
memorySearch.store |
Storage backend (sqlite, memory) |
memory |
memorySearch.paths |
Paths to index | ["memory/", "MEMORY.md"] |
cron.jobs[].sessionTarget |
Session type (main, isolated) |
main |
Long-running OpenClaw sessions accumulate tokens from:
- Heartbeat checks
- Background task results
- File reads and tool outputs
- Conversation history
Without optimization, you'll hit context limits and experience:
- Slower responses
- Higher API costs
- Lost context when truncation kicks in
This skill teaches your agent to stay lean.
PRs welcome! Areas we'd love help with:
- Native hybrid search implementation
- Automatic context monitoring
- Smart transcript archiving
- Cost tracking integration
- shAde — Original concept
- Clément — Implementation
MIT — Use freely, credit appreciated.
Part of the OpenClaw ecosystem. 🦦