#6060: feat(onboarding): add Memory Optimization step to onboarding wizard
commands
## Summary
This PR adds a **Memory Optimization** step to the OpenClaw onboarding wizard, giving users the ability to enable powerful memory features during initial setup rather than having to manually edit config later.
Resolves discussion #6038.
## Problem
OpenClaw has excellent memory infrastructure, but these features are **off or minimal by default** and require users to know they exist and manually configure them. Most users never discover these capabilities, leading to:
- **Context amnesia** after compaction (no memory flush)
- **Poor recall** of exact names, IDs, and code symbols (no hybrid search)
- **Slow reindexing** on startup (no embedding cache)
- **Lost conversation history** (no session transcript search)
## Solution
### Interactive Mode
Adds a `setupMemoryOptimization()` step after hooks setup with a multiselect prompt offering four options:
- ๐ **Hybrid search (BM25 + vector)** โ 70/30 vector/text blend with 4x candidate pool. Dramatically improves recall for exact terms, names, error strings, and code symbols.
- ๐พ **Embedding cache** โ Caches chunk embeddings in SQLite so reindexing does not re-embed unchanged text. Saves API calls and makes search faster on startup.
- ๐ง **Pre-compaction memory flush** โ Auto-triggers a silent agentic turn before context compaction, giving the agent a chance to write durable notes to disk. Prevents the "woke up with amnesia" problem.
- ๐ **Session transcript search** โ Indexes past session transcripts via memory_search with lower delta thresholds (50KB/25 messages) for faster indexing.
### Non-Interactive Mode
Applies sensible defaults automatically: hybrid search, embedding cache, and memory flush are enabled. Session transcript search is opt-in only (it is experimental).
## Implementation
- **New file:** `src/commands/onboard-memory.ts` โ The memory optimization wizard step + `applyNonInteractiveMemoryDefaults()` export
- **New file:** `src/commands/onboard-memory.test.ts` โ 19 tests covering all options individually, all together, skip, nullish coalescing (no overwrite), immutability, and non-interactive defaults
- **Modified:** `src/wizard/onboarding.ts` โ Integrates the step after hooks setup
- **Modified:** `src/commands/onboard-non-interactive/local.ts` โ Adds non-interactive memory defaults
### Key Design Decisions
- Uses `structuredClone()` for immutability (original config never mutated)
- All nested config uses `??=` (nullish coalescing assignment) โ never overwrites existing user-set values
- Follows the existing `onboard-hooks.ts` pattern exactly for function signature and test structure
## Testing
- โ
TypeScript compiles cleanly (`tsc --noEmit`)
- โ
19/19 tests pass (`vitest run src/commands/onboard-memory.test.ts`)
- โ
Lint passes (`oxlint` โ 0 warnings, 0 errors in new files)
- โ
Format passes (`oxfmt`)
- โ
Tested on a live OpenClaw instance (Hetzner VPS, Ubuntu) running all four memory optimizations
## Why This Matters
The compaction problem that frustrates most long-running OpenClaw users has built-in solutions that almost nobody knows about. This PR makes them discoverable at first setup rather than requiring users to manually edit config JSON.
## AI-Assisted ๐ค
Built with Claude (Opus 4.5) via OpenClaw sub-agent. The irony is not lost on us: this PR improves the memory of the very system that wrote it.
cc @steipete
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a new onboarding step (`setupMemoryOptimization`) that lets users enable memory-related defaults (hybrid search, embedding cache, pre-compaction flush, session transcript search) and wires it into both interactive onboarding (`src/wizard/onboarding.ts`) and non-interactive local onboarding (`applyNonInteractiveMemoryDefaults`). It also introduces a focused test suite validating that the step sets defaults via nullish coalescing and does not mutate or overwrite existing config.
<h3>Confidence Score: 4/5</h3>
- This PR is mostly safe to merge; the main concern is handling prompt cancellation/undefined values robustly.
- Changes are additive, well-tested, and scoped to onboarding config writing. The only notable risk is an unhandled cancel/null return from `multiselect` causing a runtime crash during onboarding, plus a minor semantic question around whether `null` should be treated as โunsetโ.
- src/commands/onboard-memory.ts
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#2884: fix: Create memory directory and symlink identity files during work...
by webdevtodayjason ยท 2026-01-27
78.4%
#19341: Mind Memory Fork
by juliopx ยท 2026-02-17
77.9%
#19967: feat(memory): add semantic clustering and enhanced MMR
by alihassan6520 ยท 2026-02-18
76.8%
#11179: fix(memory): replace confusing "No API key" errors in memory tools ...
by liuxiaopai-ai ยท 2026-02-07
76.8%
#10644: feat: add runDuringHeartbeats option for memory flush (AI Assisted)
by tripphillips ยท 2026-02-06
76.6%
#12425: feat(core): Native Token Optimization Defaults (Pruning, Compaction...
by oneles ยท 2026-02-09
76.6%
#22220: feat(bootstrap): cache session's bootstrap files so we don't invali...
by anisoptera ยท 2026-02-20
76.5%
#21217: fix: memory prune command to prevent unbounded MEMORY.md growth
by theognis1002 ยท 2026-02-19
76.5%
#10591: feat(hooks): add session-start-memory bundled hook
by morningstar-daemon ยท 2026-02-06
76.2%
#13045: feat(doctor): add memory search embeddings provider health check
by asklee-klawd ยท 2026-02-10
76.2%