reflectAndCleanMemory
NuggetShelf. The pass performs four sequential operations:
Archive low-value notes
Notes with empty content, very short content with zero hits, or titles matching
tmp/temp/scratch patterns are soft-deleted.Normalize content
Duplicate lines and excess whitespace are removed. The
lastRewrittenAt timestamp is updated.Improve tags
Tags are re-derived from the title, content, scope, and type. System tags (
scope:*, type:*) are added where missing.The shelf to operate on.
Restrict the pass to a single nugget. Omit to process all nuggets.
Maximum number of notes to inspect per run. Capped internally at
10.ReflectionResult.
reflectAndCleanMemory is also exposed on NuggetShelf directly as shelf.reflectAndCleanMemory(nuggetName?, limit?).promoteFacts
hits >= 3 (recalled across at least 3 distinct sessions) and writes them to MEMORY.md in the Claude project memory directory (~/.claude/projects/<cwd>/memory/MEMORY.md).
If the memory directory does not exist, the function returns 0 without writing anything. The file is only created or updated when the directory already exists, making this safe to call in any environment.
The generated MEMORY.md is structured as:
learnings and preferences first, then remaining sections alphabetically. Within each section, entries are keyed by note title and valued by note content.
The shelf to read notes from.
MEMORY.md in this call. Updates to existing entries are applied silently and do not increment the count.
ReflectionResult
Returned byreflectAndCleanMemory.
ISO 8601 timestamp of when the reflection pass started.
Total number of notes examined during the pass.
Number of notes whose content was normalised.
Number of near-duplicate note pairs that were merged.
Number of low-value notes that were soft-archived.
Number of notes whose tags were updated.
Number of new links added between related notes.
Ordered log of every individual action taken. See
ReflectionChange.ReflectionChange
A single action record within aReflectionResult.
The kind of action performed:
| Value | Meaning |
|---|---|
"rewrite" | Note content was normalised. |
"merge" | A duplicate note was merged into this note. |
"hide" | The note was soft-archived as low-value. |
"tag" | The note’s tags were updated. |
"link" | A new link was added to a related note. |
Name of the nugget that owns the affected note.
ID of the note that was changed.
Human-readable description of what changed. Examples:
"Normalized duplicated whitespace and repeated lines""Merged duplicate note note-project-b5c6d7e8""Tags -> scope:project, type:fact, deploy""Archived low-value note""Linked to note-project-c9d0e1f2"