OpenClaw Token Optimizer by M Asif Rahman
npx skills add https://github.com/asif2bd/openclaw-token-optimizer --skill token-optimizerInstallieren Sie diesen Skill ΓΌber die CLI und beginnen Sie mit der Verwendung des SKILL.md-Workflows in Ihrem Arbeitsbereich.
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