Dream — Memory Consolidation
Consolidate, prune, and optimize project memory files. Analogous to how the brain consolidates memories during sleep — removes noise, strengthens signal, resolves contradictions.
When to Run
- After many sessions (5+) without cleanup
- When memory files reference deleted code, renamed files, or outdated decisions
- When the MEMORY.md index is out of sync with actual memory files
- When the user explicitly requests memory optimization
- Proactively at the end of long sessions with significant project changes
Memory Schema Reference
Before starting, load references/memory-schema.md to understand the expected file format, frontmatter fields, and index conventions. Use it to identify malformed files during Phase 2.
Consolidation Process
Execute all 7 phases in order. Report findings after each phase.
Phase 0: Memory Location Discovery
Before doing anything else, locate the active memory directory. Check the following locations in priority order:
- Claude Code auto-memory —
~/.claude/projects/<hashed-cwd>/memory/
- Derive
<hashed-cwd> by replacing / with - in the absolute working directory path (e.g. /Users/alice/projects/foo → -Users-alice-projects-foo)
- Full path:
~/.claude/projects/<hashed-cwd>/memory/
- Project-level memory —
.claude/memory/ relative to the current working directory
- Bare memory folder —
memory/ relative to the current working directory
- Docs subfolder —
docs/memory/ relative to the current working directory
- User-specified — if the user passed a path as an argument, use that
Use the first location that contains a MEMORY.md file. If none is found, list all candidate paths and ask the user which to use (or whether to create one).
Report: memory directory path, how it was discovered.
Phase 1: Inventory
- Read the
MEMORY.md index from the discovered memory directory
- List all
.md files in the directory (excluding MEMORY.md itself)
- Identify:
- Orphaned files: exist on disk but not referenced in the index
- Broken links: referenced in the index but file is missing
- Report: total files, orphans, broken links
Phase 2: Temporal Normalization
For each memory file:
- Read the file content
- Find relative date references: "yesterday", "today", "last week", "recently", "just now", "a few days ago", and equivalents in other languages
- If the file is missing frontmatter
type or description, flag it as malformed
- Convert relative dates to absolute dates using the file's git last-modified date or frontmatter hints as an anchor
- Write the file back if changes were made
Phase 3: Staleness Verification
For each memory file:
- If the memory references specific file paths — verify they still exist using Glob
- If the memory references specific function names, classes, or variables — verify with Grep
- If the memory references specific URLs or endpoints — note for manual verification
- If the memory references server/infra state (container names, ports, domains) — verify against current config files
- Mark memories as
STALE if referenced artifacts no longer exist
- For stale memories: remove them if purely factual (file X does Y), update them if the fact evolved (file X was renamed to Y)
Phase 4: Contradiction Resolution
Compare memories that share the same topic (identified by filename prefix or frontmatter name):
- Group memories by topic area (e.g., all
project_*, all feedback_*)
- Within each group, check for contradictions — different values for the same fact
- Resolve contradictions by keeping the most recent version (check git log for last edit date)
- If both are current and non-contradictory, merge into a single memory with combined facts
Phase 5: Deduplication & Merging
- Identify memories with overlapping content (>50% similar facts)
- Merge overlapping memories into a single file with a unified structure
- Keep the more descriptive filename; delete the other
- Preserve all unique facts from both sources
Phase 6: Index Rebuild
- Regenerate
MEMORY.md from the current memory files
- Ensure each entry is one line, under 150 characters
- Group by type: Project, Feedback, Reference, User, Archive
- Sort within groups by relevance (active items first, archived last)
- Trim index to under 200 lines
Output Report
After all phases, output a summary:
## Dream Report
**Date**: YYYY-MM-DD
**Memory directory**: <path>
**Memory files**: X total (Y before)
**Changes**:
- Removed: [list of deleted files with reason]
- Updated: [list of modified files with change summary]
- Merged: [list of merge operations]
- Created: [list of new files, if any]
- Index: rebuilt / no changes
**Stale references found**: N
**Contradictions resolved**: N
**Duplicates merged**: N
Rules
- Never delete a memory without verifying it is truly stale (check code, git log, config)
- When in doubt, update rather than delete
- Preserve the frontmatter structure (
name, description, type)
- Do not modify memory content beyond what consolidation requires
- Always show the user what changed before writing files — ask for confirmation on deletions
- Archive session logs older than 30 days by moving to an "Archive" section in the index
1---2name: dream3description: Memory consolidation and optimization skill. Use when the user says "/dream", "dream", "consolidate memory", "clean up memory", "optimize memory", or when memory files have accumulated across many sessions and need maintenance. Dynamically discovers the project memory directory, removes stale facts, converts relative dates to absolute, resolves contradictions, merges duplicates, and rebuilds the index.4---56# Dream — Memory Consolidation78Consolidate, prune, and optimize project memory files. Analogous to how the brain consolidates memories during sleep — removes noise, strengthens signal, resolves contradictions.910## When to Run1112- After many sessions (5+) without cleanup13- When memory files reference deleted code, renamed files, or outdated decisions14- When the MEMORY.md index is out of sync with actual memory files15- When the user explicitly requests memory optimization16- Proactively at the end of long sessions with significant project changes1718## Memory Schema Reference1920Before starting, load `references/memory-schema.md` to understand the expected file format, frontmatter fields, and index conventions. Use it to identify malformed files during Phase 2.2122## Consolidation Process2324Execute all 7 phases in order. Report findings after each phase.2526### Phase 0: Memory Location Discovery2728Before doing anything else, locate the active memory directory. Check the following locations in priority order:29301. **Claude Code auto-memory** — `~/.claude/projects/<hashed-cwd>/memory/`31 - Derive `<hashed-cwd>` by replacing `/` with `-` in the absolute working directory path (e.g. `/Users/alice/projects/foo` → `-Users-alice-projects-foo`)32 - Full path: `~/.claude/projects/<hashed-cwd>/memory/`332. **Project-level memory** — `.claude/memory/` relative to the current working directory343. **Bare memory folder** — `memory/` relative to the current working directory354. **Docs subfolder** — `docs/memory/` relative to the current working directory365. **User-specified** — if the user passed a path as an argument, use that3738Use the first location that contains a `MEMORY.md` file. If none is found, list all candidate paths and ask the user which to use (or whether to create one).3940Report: memory directory path, how it was discovered.4142### Phase 1: Inventory43441. Read the `MEMORY.md` index from the discovered memory directory452. List all `.md` files in the directory (excluding `MEMORY.md` itself)463. Identify:47 - **Orphaned files**: exist on disk but not referenced in the index48 - **Broken links**: referenced in the index but file is missing494. Report: total files, orphans, broken links5051### Phase 2: Temporal Normalization5253For each memory file:54551. Read the file content562. Find relative date references: "yesterday", "today", "last week", "recently", "just now", "a few days ago", and equivalents in other languages573. If the file is missing frontmatter `type` or `description`, flag it as malformed584. Convert relative dates to absolute dates using the file's git last-modified date or frontmatter hints as an anchor595. Write the file back if changes were made6061### Phase 3: Staleness Verification6263For each memory file:64651. If the memory references specific **file paths** — verify they still exist using Glob662. If the memory references specific **function names, classes, or variables** — verify with Grep673. If the memory references specific **URLs or endpoints** — note for manual verification684. If the memory references **server/infra state** (container names, ports, domains) — verify against current config files695. Mark memories as `STALE` if referenced artifacts no longer exist706. For stale memories: remove them if purely factual (file X does Y), update them if the fact evolved (file X was renamed to Y)7172### Phase 4: Contradiction Resolution7374Compare memories that share the same topic (identified by filename prefix or frontmatter `name`):75761. Group memories by topic area (e.g., all `project_*`, all `feedback_*`)772. Within each group, check for contradictions — different values for the same fact783. Resolve contradictions by keeping the most recent version (check git log for last edit date)794. If both are current and non-contradictory, merge into a single memory with combined facts8081### Phase 5: Deduplication & Merging82831. Identify memories with overlapping content (>50% similar facts)842. Merge overlapping memories into a single file with a unified structure853. Keep the more descriptive filename; delete the other864. Preserve all unique facts from both sources8788### Phase 6: Index Rebuild89901. Regenerate `MEMORY.md` from the current memory files912. Ensure each entry is one line, under 150 characters923. Group by type: Project, Feedback, Reference, User, Archive934. Sort within groups by relevance (active items first, archived last)945. Trim index to under 200 lines9596## Output Report9798After all phases, output a summary:99100```101## Dream Report102103**Date**: YYYY-MM-DD104**Memory directory**: <path>105**Memory files**: X total (Y before)106**Changes**:107- Removed: [list of deleted files with reason]108- Updated: [list of modified files with change summary]109- Merged: [list of merge operations]110- Created: [list of new files, if any]111- Index: rebuilt / no changes112113**Stale references found**: N114**Contradictions resolved**: N115**Duplicates merged**: N116```117118## Rules119120- Never delete a memory without verifying it is truly stale (check code, git log, config)121- When in doubt, update rather than delete122- Preserve the frontmatter structure (`name`, `description`, `type`)123- Do not modify memory content beyond what consolidation requires124- Always show the user what changed before writing files — ask for confirmation on deletions125- Archive session logs older than 30 days by moving to an "Archive" section in the index