OpenClaw Token Optimizer by M Asif Rahman
npx skills add https://github.com/asif2bd/openclaw-token-optimizer --skill token-optimizerInstall this skill with the CLI and start using the SKILL.md workflow in your workspace.
Reduce OpenClaw token usage and API costs by 50-80%
An OpenClaw skill for smart model routing, lazy context loading, optimized heartbeats, budget tracking, and native OpenClaw 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment).
clawhub install Asif2BD/openclaw-token-optimizer
Or browse to: clawhub.ai/Asif2BD/openclaw-token-optimizer
git clone https://github.com/Asif2BD/OpenClaw-Token-Optimizer.git \
~/.openclaw/skills/openclaw-token-optimizer
Then add to openclaw.json:
{
"skills": {
"load": {
"extraDirs": ["~/.openclaw/skills/openclaw-token-optimizer"]
}
}
}
"Install the OpenClaw Token Optimizer skill from https://clawhub.ai/Asif2BD/openclaw-token-optimizer ā or if ClawHub isn't available, clone https://github.com/Asif2BD/OpenClaw-Token-Optimizer and add the path to skills.load.extraDirs in openclaw.json"
Three native config patches that work today with zero external dependencies:
Auto-trim old tool results when the Anthropic cache TTL expires ā reduces cache re-write costs.
{ "agents": { "defaults": { "contextPruning": { "mode": "cache-ttl", "ttl": "5m" } } } }
Cap workspace file injection into the system prompt (20-40% reduction for large workspaces).
{ "agents": { "defaults": { "bootstrapMaxChars": 10000, "bootstrapTotalMaxChars": 15000 } } }
Amortize cache write costs on long Opus sessions.
{ "agents": { "defaults": { "models": { "anthropic/claude-opus-4-5": { "params": { "cacheRetention": "long" } } } } } }
Keep the Anthropic 1h prompt cache warm ā avoid the re-write penalty.
python3 scripts/heartbeat_optimizer.py cache-ttl
# ā recommended_interval: 55min (3300s)
1. Context optimization (biggest win):
python3 scripts/context_optimizer.py recommend "hi, how are you?"
# ā Load only 2 files, skip everything else ā ~80% savings
2. Model routing:
python3 scripts/model_router.py "design a microservices architecture"
# ā Complex task ā Opus
python3 scripts/model_router.py "thanks!"
# ā Simple ack ā Sonnet (cheapest available)
3. Optimized heartbeat:
cp assets/HEARTBEAT.template.md ~/.openclaw/workspace/HEARTBEAT.md
python3 scripts/heartbeat_optimizer.py plan
4. Token budget check:
python3 scripts/token_tracker.py check
5. Cache TTL alignment:
python3 scripts/heartbeat_optimizer.py cache-ttl
# Set heartbeat to 55min to keep Anthropic 1h cache warm
/context list ā per-file token breakdown (use before applying bootstrap limits)
/context detail ā full system prompt breakdown
/usage tokens ā append token count to every reply
/usage cost ā cumulative cost summary
openclaw-token-optimizer/
āāā SKILL.md ā Skill definition (loaded by OpenClaw)
āāā SECURITY.md ā Full security audit + provenance
āāā CHANGELOG.md ā Version history
āāā .clawhubsafe ā SHA256 integrity manifest (13 files)
āāā .clawhubignore ā Files excluded from publish bundle
āāā scripts/
ā āāā context_optimizer.py ā Context lazy-loading
ā āāā model_router.py ā Task classification + model routing
ā āāā heartbeat_optimizer.py ā Interval management + cache-ttl alignment
ā āāā token_tracker.py ā Budget monitoring
ā āāā optimize.sh ā Convenience CLI wrapper (calls Python scripts)
āāā assets/
ā āāā config-patches.json ā Ready-to-apply config patches
ā āāā HEARTBEAT.template.md ā Drop-in optimized heartbeat template
ā āāā cronjob-model-guide.md ā Model selection for cron tasks
āāā references/
āāā PROVIDERS.md ā Multi-provider strategy guide
| Strategy | Context | Model | Monthly (100K tok/day) | Savings |
|---|---|---|---|---|
| Baseline (no optimization) | 50K | Sonnet | $9.00 | 0% |
| Context optimization only | 10K | Sonnet | $5.40 | 40% |
| Model routing only | 50K | Mixed | $5.40 | 40% |
| Both (this skill) | 10K | Mixed | $2.70 | 70% |
All scripts are local-only ā no network calls, no subprocess spawning, no system modifications. See SECURITY.md for full per-script audit.
Verify integrity:
cd ~/.openclaw/skills/openclaw-token-optimizer
sha256sum -c .clawhubsafe
Quick audit (should return nothing):
grep -r "urllib\|requests\|socket\|subprocess\|curl\|wget" scripts/
See CHANGELOG.md for full version history.
v1.4.2 ā Security scanner fixes (provenance, optimize.sh manifest, SECURITY.md)
v1.4.1 ā .clawhubignore added (fixes public visibility)
v1.4.0 ā Native OpenClaw 2026.2.15 features (session pruning, bootstrap limits, cache TTL)
v1.3.3 ā Correct display name on ClawHub
v1.3.2 ā Security audit, SECURITY.md, .clawhubsafe manifest