#12425: feat(core): Native Token Optimization Defaults (Pruning, Compaction, Cache & Local Search)
agents
stale
Cluster:
Memory Management Enhancements
## Description\nThis PR moves core token optimization strategies directly into the configuration defaults layer. By enforcing these settings natively, OpenClaw becomes significantly more cost-efficient out-of-the-box without requiring manual user configuration.\n\n## Core Optimizations:\n1. **Aggressive Context Pruning**: Default mode set to `cache-ttl` with a 5m TTL and 0.5 hard-clear ratio.\n2. **Enhanced Compaction**: Default `reserveTokensFloor` set to 20,000 and enabled `memoryFlush` (memory persistence) by default.\n3. **Optimized Cache Retention**: Default heartbeat set to 55m and enforced Anthropic `cacheRetention: "long"` to maximize prompt caching benefits.\n4. **Local Memory Search**: Default `memorySearch.provider` to `local` to eliminate remote embedding API costs.\n\nThese defaults ensure a better balance between cost and performance for all users.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `src/config/defaults.ts` to enforce more aggressive “token optimization” defaults in the config layer: context pruning defaults (`cache-ttl` with 5m TTL + trim ratios), a fixed 55m heartbeat interval, defaulting memory search to local, and switching Anthropic model `cacheRetention` defaults from `short` to `long`. It also extends compaction defaults to force `mode: "safeguard"`, enable `memoryFlush`, and raise `reserveTokensFloor`.
These changes run as part of config normalization in `src/config/io.ts`, so they affect every config load (including the empty-config bootstrap path).
<h3>Confidence Score: 3/5</h3>
- This PR is likely mergeable but has a real config-merging bug that can silently drop memorySearch settings.
- Most changes are straightforward default tweaks, but the `memorySearch` defaulting logic currently spreads `defaults.memorySearch` where `defaults` is the agent defaults object, causing existing `agents.defaults.memorySearch` fields to be lost when provider is defaulted. The rest is behavior changes that need confirmation (heartbeat/auth-mode coupling).
- src/config/defaults.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13792: Claude/openclaw token efficiency q ni2s
by imecostalima · 2026-02-11
82.4%
#8919: Pr/memory flush improvements
by shortbus · 2026-02-04
78.4%
#10644: feat: add runDuringHeartbeats option for memory flush (AI Assisted)
by tripphillips · 2026-02-06
77.9%
#9012: fix(memory): resilient flush for large sessions [AI-assisted]
by cheenu1092-oss · 2026-02-04
76.8%
#15196: fix: clear stale token totals after compaction
by bufordtjustice2918 · 2026-02-13
76.7%
#6060: feat(onboarding): add Memory Optimization step to onboarding wizard
by GodsBoy · 2026-02-01
76.6%
#14887: feat(compaction): configurable auto-compaction notifications with o...
by seilk · 2026-02-12
76.2%
#8961: feat: smarter compaction tool truncation + token count in system pr...
by SocialNerd42069 · 2026-02-04
76.2%
#9620: fix: increase auto-compaction reserve buffer to 40k tokens
by Arlo83963 · 2026-02-05
76.1%
#12220: fix: forward-compat models now respect user-configured contextWindow
by Batuhan4 · 2026-02-09
76.0%