Documents

Token Optimizer for OpenClaw & Hermes

Try it

Reduce recurring OpenClaw token waste via lazy context, Sonnet/Opus routing, and cache-aware heartbeats.

What it does

Local scripts for OpenClaw 2026.6.x agents that recommend the minimum context for each prompt, route routine work to Sonnet and complex reasoning to Opus, schedule heartbeat checks with quiet hours and cache-TTL awareness, and track local daily token budgets. Writes to the workspace only when explicitly requested, and backs up HEARTBEAT.md before replacement. Includes a SHA256 manifest (.clawhubsafe) for verifying installed files.

When to use it

  • Picking the minimum context bundle for a prompt
  • Routing a routine reply to Sonnet instead of Opus
  • Scheduling heartbeat checks around quiet hours and cache TTL
  • Checking a local daily token budget before expensive work

The skill document

OpenClaw Token Optimizer v3.2.0

Version License

Built for current OpenClaw 2026.6.x agents by Asif2BD · GitHub · Security Notes

Security notice: local-only optimization toolkit. The Python scripts make no network requests and do not execute dynamic code. Commands that write files are explicit, documented, and backup-safe.


Install

openclaw skills install @asif2bd/openclaw-token-optimizer

What's New in v3.2

Modern ClawHub Card

The skill card now leads with a clearer product promise, current OpenClaw compatibility, security posture, and practical commands instead of the older long-form v3.0 copy.

Current OpenClaw Model Routing

Routine Anthropic work maps to anthropic/claude-sonnet-4-5; only explicitly complex reasoning routes to anthropic/claude-opus-4-5.

Audit-Safe Writes

  • context_optimizer.py generate-agents prints to stdout by default.
  • Writing an optimized AGENTS.md requires --output or --workspace-output.
  • ./scripts/optimize.sh heartbeat previews only by default.
  • ./scripts/optimize.sh heartbeat install writes HEARTBEAT.md only after backing up an existing file.

What It Optimizes

Context Loading

Stop loading every workspace file into every session. Recommend only the context needed for the current prompt.

python3 scripts/context_optimizer.py recommend "hi"

Typical result: SOUL.md + IDENTITY.md only for a greeting.

Model Routing

Keep standard work on Sonnet and reserve Opus for deep reasoning.

python3 scripts/model_router.py "thanks!"
python3 scripts/model_router.py "design a multi-agent architecture"

Heartbeat Scheduling

Run only checks that are due, respect quiet hours, and align heartbeat timing with prompt-cache TTL.

python3 scripts/heartbeat_optimizer.py plan
python3 scripts/heartbeat_optimizer.py cache-ttl

Token Budgets

Track local daily budget state and surface warnings before runaway spend.

python3 scripts/token_tracker.py check

Quick Start

1. Find the minimum context for a request

python3 scripts/context_optimizer.py recommend "write a deployment checklist"

2. Preview an optimized AGENTS.md

python3 scripts/context_optimizer.py generate-agents

Save a review copy only when you explicitly ask for it:

python3 scripts/context_optimizer.py generate-agents --output ~/.openclaw/workspace/AGENTS.md.optimized

3. Preview heartbeat installation

./scripts/optimize.sh heartbeat

Install with backup protection:

./scripts/optimize.sh heartbeat install

4. Route a task

python3 scripts/model_router.py "debug this error"

Savings Profile

AreaTypical wasteOptimizer approach
Startup contextLoading docs, memory, tools, and old logs every turnLazy-load only what the prompt needs
Routine model useOpus used for quick replies or simple checksSonnet for routine work, Opus for complex reasoning
HeartbeatsEvery check runs on every heartbeatDue-check planner + quiet hours
Cache TTLIdle sessions trigger expensive cache rewrites55-minute heartbeat guidance for 1-hour cache TTL
Budget controlSpend discovered after the factLocal budget checks before expensive work

Expected savings: 50-80% in context-heavy OpenClaw workspaces, with context optimization usually delivering the biggest win.


Files

Scripts

  • scripts/context_optimizer.py — prompt classification and context bundle recommendations
  • scripts/model_router.py — Sonnet/Opus-aware task routing
  • scripts/heartbeat_optimizer.py — due-check planning, quiet hours, cache-TTL interval guidance
  • scripts/token_tracker.py — local budget tracking
  • scripts/optimize.sh — convenience wrapper around bundled scripts

Assets

  • assets/HEARTBEAT.template.md — backup-safe heartbeat template
  • assets/cronjob-model-guide.md — scheduled-task model guidance
  • assets/config-patches.json — native and optional config examples

References

  • references/PROVIDERS.md — optional external-provider strategy notes
  • SECURITY.md — complete security and data-handling breakdown

Security Posture

  • No network calls in executable scripts
  • No eval, dynamic imports, shell command execution, or downloader behavior
  • Local JSON state only under the OpenClaw workspace memory directory
  • Workspace writes require explicit commands
  • Existing HEARTBEAT.md is backed up before replacement
  • .clawhubsafe covers every published file with SHA256 hashes

Verify locally:

sha256sum -c .clawhubsafe

Native OpenClaw Diagnostics

Use OpenClaw's built-in context and usage commands alongside this skill:

/context list
/context detail
/usage tokens
/usage cost

Use the built-ins to see where tokens are going, then use Token Optimizer to reduce the recurring waste.


Best Fit

  • Multi-agent OpenClaw workspaces with large instruction files
  • Agents that run heartbeats or scheduled checks
  • Teams trying to keep Opus for hard work instead of routine work
  • xCloud, MissionDeck, or other hosted OpenClaw deployments where every saved prompt token compounds across users

More by Asif2BD

openclaw skills install @asif2bd/jarvis-mission-control
openclaw skills search asif2bd

Related skills

Stores durable facts in a categorized, plain-markdown vault on disk, alongside your agent's built-in memory.

by Iván559 installs18 stars

Find why your productivity system keeps failing, then apply the smallest fix — capacity math, bottleneck routing, durable local notes.

by Iván855 installs69 stars

Join a video meeting as an AI bot with voice, avatar, and screenshare across four operating modes.

by johnpatternai22 installs8 stars

Generate and edit Draw.io, Mermaid, and Excalidraw diagrams from natural language using a structured JSON spec.

by nssa.io1.0k installs47 stars

Fetch raw ad creative, app, ranking, and revenue data from AdMapix as structured JSON.

by fly0pants4.3k installs296 stars

More from asif2bd

Browse all skills

Get a Docker project ready for xCloud with confirmation-gated file edits and port fixes.

by asif2bd38 installs

Publish content directly to WordPress sites via REST API with full Gutenberg block support. Create and publish posts/pages, auto-load and select categories from website, generate SEO-optimized tags, preview articles before publishing, and generate Gutenberg blocks for tables, images, lists, and rich formatting. Use when user wants to publish to WordPress, post to blog, create WordPress article, update WordPress post, or convert markdown to Gutenberg blocks.

by asif2bd189 installs10 stars

Universal travel planning skill for OpenClaw agents. Plan itineraries, check weather, discover attractions, and estimate budgets — all through natural conver...

by asif2bd33 installs

Install, authenticate, and use Claude Code CLI as a native coding tool for any OpenClaw agent system.

by asif2bd32 installs

Dramatically reduce per-session token usage by loading skills and context files only when needed — not at session start. Includes the SKILLS catalog pattern,...

by asif2bd36 installs