Token Optimization for Openclaw

A technical framework for slashing OpenClaw per-turn prompt costs by 70% through intelligent file splitting, prompt caching, and context management.

jack-yang-ai
v1.1.0
Mar 17, 2026
2
2k
0

Install & Download

1. ClawHub CLI

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

npx clawhub@latest install token-optimization

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 token-optimization 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 Optimization?

This skill provides a systematic approach to optimizing token consumption within the OpenClaw ecosystem. By implementing structural changes to workspace files and fine-tuning model configurations, users can significantly reduce API overhead while maintaining full functionality. It is specifically designed for developers running production-scale Openclaw Skills who need to manage high-volume context windows and Anthropic API billing.

The methodology focuses on three primary layers: architectural file splitting to keep the core system prompt lean, enabling advanced prompt caching for persistent context, and aggressive context pruning to prevent memory bloat over long sessions. This ensures your agents remain fast and cost-effective.

Token Optimization Use Cases

  • High API costs on premium Anthropic models like Claude Opus or Sonnet.
  • Session status showing context usage over 30% on simple messages.
  • Consistently low or 0% cache hit rates despite frequent interactions.
  • Managing bloated workspace files where AGENTS.md or MEMORY.md exceed recommended sizes.

How Token Optimization Works

  1. Run a session audit to record baseline cache hit rates and context percentage usage.
  2. Refactor the workspace by splitting large, static files into on-demand sub-documents to reduce the permanent system prompt size.
  3. Configure prompt caching in the JSON settings to allow the model provider to store and reuse frequently accessed data.
  4. Implement context pruning rules to automatically discard stale message history based on time-to-live (TTL) thresholds.
  5. Optimize model routing by assigning low-complexity tasks, such as heartbeats, to free or lightweight model tiers.
  6. Restart the gateway and monitor session KPIs to ensure the cache hit rate targets of >80% are achieved.

Token Optimization Setup

To implement these optimizations, modify your openclaw.json configuration and clean your workspace directory.

# Check current workspace file sizes
wc -c ~/.openclaw/workspace/*.md

# Remove unnecessary bootstrap files
mv ~/.openclaw/workspace/BOOTSTRAP.md ~/.openclaw/workspace/BOOTSTRAP.md.bak

# Restart the gateway to apply configuration changes
openclaw gateway restart

Token Optimization Data Schema & Taxonomy

The optimization process targets specific file sizes and configuration parameters to ensure efficient execution of Openclaw Skills.

Component Target Constraint Description
AGENTS.md <= 5KB Core logic, safety rules, and subagent references.
MEMORY.md <= 3KB High-frequency reference items only.
cacheRetention long Configures 1-hour cache windows for Anthropic models.
contextPruning cache-ttl Mode for automated memory management based on message age.

Token Optimization Advanced Features

  • Intelligent tool-specific context denial to prevent large, one-off tool outputs (like web fetches) from bloating the context.
  • Keep-warm heartbeat triggers that maintain permanent cache layers through scheduled low-cost model pings.
  • Tiered model routing for Openclaw Skills to balance intelligence requirements with operational budget.
  • Custom pruning ratios (soft/hard) to fine-tune the balance between agent memory and token efficiency.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*