Systematic guide to reduce per-turn token consumption by 70%+ without losing any functionality.
session_status shows Context > 30% on simple messagesopenclaw.jsonRun session_status and record:
text
Cache: X% hit · Y cached, Z new
Context: Xk/200k (X%)
Then check file sizes:
bash
wc -c ~/.openclaw/workspace/*.md
Red flags:
Move infrequently-needed content to separate files:
ContentMove ToLoad WhenSubagent protocolsAGENTS_SUBAGENT.mdOnly when spawningHeartbeat rulesAGENTS_HEARTBEAT.mdOnly during heartbeatDetailed examplesmemory/ directoryOn demand via read
Target: AGENTS.md ≤ 5KB
Keep only: session rules, safety, formatting, quick-reference subagent table.
Add references at the top:
markdown
> Subagent protocol → `AGENTS_SUBAGENT.md` (read on demand)
> Heartbeat protocol → `AGENTS_HEARTBEAT.md` (read during heartbeat)
Move detailed SOPs and procedures to memory/ subdirectory files. Keep only high-frequency referenced items.
Target: MEMORY.md ≤ 3KB
Delete it after initial setup. It loads every turn for zero value.
bash
mv ~/.openclaw/workspace/BOOTSTRAP.md ~/.openclaw/workspace/BOOTSTRAP.md.bak
bash
# Sum only files that load every turn
cat ~/.openclaw/workspace/{AGENTS,SOUL,TOOLS,IDENTITY,USER,HEARTBEAT,MEMORY}.md | wc -c
# Target: < 15KB total
Add cacheRetention to each Anthropic model in openclaw.json:
json
{
"agents": {
"defaults": {
"models": {
"anthropic/claude-opus-4-6": {
"params": { "cacheRetention": "long" }
},
"anthropic/claude-sonnet-4-6": {
"params": { "cacheRetention": "long" }
},
"openrouter/anthropic/claude-3.5-sonnet": {
"params": { "cacheRetention": "short" }
}
}
}
}
}
ValueCache WindowBest FornoneNo cachingBursty/notification agentsshort~5 minutesOpenRouter modelslong~1 hourMain agent (recommended)
ProviderSupportAnthropic direct API✅ FullOpenRouter anthropic/*✅ Auto cache_control injectionBedrock Anthropic Claude✅ Pass-throughOther providers❌ No effect
Pair cacheRetention: "long" with heartbeat at ~55 min intervals to keep cache permanently warm:
json
"heartbeat": {
"every": "55m",
"model": "your/cheap-model"
}
json
{
"agents": {
"defaults": {
"contextPruning": {
"mode": "cache-ttl",
"ttl": "3m",
"keepLastAssistants": 2,
"softTrimRatio": 0.25,
"hardClearRatio": 0.45,
"tools": {
"allow": ["exec", "read", "browser"],
"deny": ["web_search", "web_fetch"]
}
}
}
}
}
ParameterAggressiveModerateConservativettl2m3m5mkeepLastAssistants123softTrimRatio0.200.250.30hardClearRatio0.400.450.50
Move large, one-off tool outputs to deny:
web_fetch — page content is large and rarely reusedweb_search — search results change every timeKeep frequently reused tools in allow:
exec — command outputs often referenced in follow-upread — file contents may be discussed across turnsbrowser — snapshot data may be referencedUse cheap/free models for low-value tasks:
json
"heartbeat": {
"every": "4h",
"model": "your/free-flash-model"
}
TaskModel TierWhyHeartbeat/cronFree/flashSimple checks, zero costSimple Q&AFree/flashDoesn't need intelligenceMedium tasksMid-tierBalance cost and qualityComplex/multi-stepPremiumWorth the investment
After applying all changes, restart gateway and check:
bash
openclaw gateway restart
Then send a simple message and run session_status:
MetricTargetCheck ViaCache Hit Rate> 80%Cache: X% hitSimple Q&A Input< 20k tokensTokens: X inContext (idle)< 30%Context: Xk/200kCompactions/day< 2Compactions: X
SymptomCauseFixCache still 0%Model doesn't support cachingCheck provider is AnthropicHigh cacheWrite every turnVolatile content in system promptMove volatile files to on-demandContext > 50% quicklyPruning too looseLower ttl and softTrimRatioCompactions > 3/dayLong conversations without pruningEnable cache-ttl mode
wc -c on workspace files + session_statuscacheRetention: "long" on Anthropic modelscontextPruning with aggressive settingssession_status shows cache hits + low context %