Token Optimizer for Openclaw

An optimization suite for AI agents designed to eliminate context bloat and prevent token leaks through isolation and RAG protocols.

klautimus
v1.0.0
Feb 12, 2026
0
2k
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install openclaw-token-memory-optimizer

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install openclaw-token-memory-optimizer using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Token Optimizer?

The Token Optimizer skill is a technical framework designed to keep your AI environment lean, efficient, and cost-effective. As a vital component within the ecosystem of Openclaw Skills, it provides developers with the procedural logic needed to manage large-scale context windows without sacrificing performance. It specifically addresses the issues of session degradation and high latency by implementing task isolation and structured memory management.

By utilizing this skill, agents can maintain long-term continuity through the Digital Soul protocol, which involves periodic summarization and fact extraction. This ensures that the agent remains focused on current objectives while offloading historical data to a local retrieval system, effectively bypassing the limitations of standard context windows.

Token Optimizer Use Cases

  • Preventing background cron tasks and heartbeat checks from polluting the main conversation history.
  • Managing complex coding projects where the context usage frequently exceeds 100k tokens.
  • Implementing local RAG to search through months of session transcripts without loading them into active memory.
  • Reducing operational costs and latency by clearing session history while retaining core project facts.
  • Troubleshooting rapid context growth and identifying token-heavy workflows.

How Token Optimizer Works

  1. The system identifies background or recurring tasks and routes them through isolated, transient sessions to keep the primary context clean.
  2. When token usage reaches a critical threshold, the Reset & Summarize protocol triggers a manual scan of the current session for new facts and preferences.
  3. Extracted information is consolidated into a permanent MEMORY.md file and daily log files to preserve the agent's state.
  4. Local embedding models index the memory directory and past session transcripts into a searchable SQLite database.
  5. The agent utilizes hybrid search tools to retrieve specific snippets only when needed, maintaining a lean active context.

Token Optimizer Setup

To deploy these Openclaw Skills, first configure your background tasks in openclaw.json to use isolated sessions:

{
  "cron": {
    "jobs": [
      {
        "name": "System Check",
        "sessionTarget": "isolated",
        "payload": { "deliver": true }
      }
    ]
  }
}

Next, enable local RAG by specifying your embedding model and memory paths:

# Create the required memory structure
mkdir -p memory/
touch MEMORY.md
{
  "memorySearch": {
    "embedding": {
      "provider": "local",
      "model": "hf:second-state/All-MiniLM-L6-v2-Embedding-GGUF"
    },
    "store": "sqlite",
    "paths": ["memory/", "MEMORY.md"]
  }
}

Token Optimizer Data Schema & Taxonomy

The skill organizes knowledge across three primary layers to ensure efficient retrieval and context preservation:

Component Format Purpose
Global Memory MEMORY.md Persistent store for high-level project rules, tech stacks, and user preferences.
Temporal Logs memory/YYYY-MM-DD.md Daily activity logs that provide a chronological audit trail of agent decisions.
Session Archives ~/.openclaw/sessions/*.jsonl Raw interaction data used for semantic search and historical indexing.
Vector Index SQLite (Local) Stores embeddings for local RAG, enabling sub-second retrieval of historical facts.

Token Optimizer Advanced Features

  • Isolated Session Execution: Decouples background maintenance from user interactions to prevent context drift.
  • Digital Soul Protocol: A structured workflow for session consolidation that ensures no vital information is lost during history resets.
  • Hybrid Retrieval: Combines semantic vector search for concepts with BM25 keyword matching for exact technical terms.
  • Transcript Indexing: Extends the agent's memory by indexing historical .jsonl session files for searchable recall.
  • Automated Tooling: Integration with memory_search and memory_get to surgically inject data into the context window.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*