3.8 Memory Prefetch
Memory prefetch is an optimization mechanism where Claude Code searches for relevant memory files in parallel while the model is generating its response. Its core value is hiding latency — searching memory files requires disk I/O, and rather than waiting for the model response to complete before searching (serial), it's better to start searching while the model is thinking (parallel).
startRelevantMemoryPrefetch() (src/utils/attachments.ts) is launched at the entry of each query loop iteration:
typescript
// src/query.ts — Using the 'using' keyword to ensure dispose
using pendingMemoryPrefetch = startRelevantMemoryPrefetch(
state.messages, state.toolUseContext,
)Workflow:
- Launch condition:
isAutoMemoryEnabled()is true and relevant feature flags are active