Skip to content

vt-c-dream

Memory consolidation — clean up contradictions, stale dates, dead references, and duplicates in auto-memory files AND Open Brain persistent thoughts. Ask human before removing uncertain memories.

Plugin: core-standards
Category: Other
Command: /vt-c-dream


Memory Consolidation (/dream)

Perform a reflective consolidation pass over Claude Code's auto-memory files and Open Brain persistent thoughts. Fixes contradictions, stale dates, dead references, and duplicates across both local and cloud memory. Rule: ask a human if unsure — never silently delete memories that might still be valid.

When to Use

  • Memory feels stale (Claude references outdated decisions)
  • After a major project restructuring (files moved, branches deleted)
  • Periodically (every few weeks) as maintenance
  • When MEMORY.md exceeds 200 lines

Invocation

/vt-c-dream              # Consolidate current project memory (default)
/vt-c-dream user         # Consolidate user-level memory
/vt-c-dream all          # Consolidate both project and user memory

Execution

Phase 0: Open Brain Connectivity

Check if Open Brain MCP tools are available for cloud memory consolidation.

  1. Attempt to call thought_stats:
  2. If the tool is available and returns data → set open_brain_available = true
  3. If the tool is not available, times out, or errors → set open_brain_available = false

  4. Display result:

  5. If connected: Open Brain: connected ({N} thoughts)
  6. If not connected: Open Brain: not connected (skipping cloud phases)

All "B" sub-phases below check open_brain_available and skip silently if false.

Phase 1: Orient

  1. Resolve memory directory based on scope. Note: Claude Code stores memory at ~/.claude/ on macOS/Linux, %APPDATA%\claude\ on Windows. Use the platform-appropriate path.
  2. project (default): Find the current project's memory directory. Run ls ~/.claude/projects/ and match the current working directory hash. The memory path is ~/.claude/projects/{project-hash}/memory/.
  3. user: ~/.claude/memory/
  4. all: Process both in sequence (project first, then user)

  5. List all memory files:

    ls {memory_dir}/*.md
    

  6. Read MEMORY.md index (the file loaded at the start of every session)

  7. Count and report:

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Phase 1: Orient — {scope} memory
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Directory: {memory_dir}
    Files: {N} memory files ({M} total lines)
    MEMORY.md: {L} lines (limit: 200)
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    

  8. If no memory files found: display "No memory files found in {scope}. Nothing to consolidate." (Continue to Open Brain phases if connected.)

Phase 1B: Open Brain Inventory

Skip if open_brain_available is false.

  1. Reuse thought_stats result from Phase 0 (already called for connectivity check) to get overview:
  2. Total thought count
  3. Top topics/categories
  4. Date range (earliest to latest)

  5. Call list_thoughts to sample recent activity (last 30 days)

  6. Display alongside local report:

    Open Brain Inventory:
      Total thoughts: {N}
      Last 30 days: {M} new thoughts
      Top topics: {topic1}, {topic2}, {topic3}
      Date range: {earliest} — {latest}
    

  7. If 0 thoughts: display "Open Brain is empty. Nothing to consolidate." and skip remaining B phases.

Phase 2: Gather Signal

For each memory file (excluding MEMORY.md itself):

  1. Read the file content

  2. Check for staleness indicators:

a. File path references — grep for paths like /path/to/file, src/, plugins/, etc. For each path found:

ls {referenced_path} 2>/dev/null
If the file doesn't exist → flag as dead_reference

b. Function/class references — grep for identifiers like functionName(), ClassName, CONSTANT_NAME For notable identifiers:

grep -r "{identifier}" --include="*.py" --include="*.ts" --include="*.md" . -l
If not found anywhere in the codebase → flag as dead_reference

c. Branch references — grep for branch names like feature/, fix/

git branch --list "{branch_name}"
If branch doesn't exist → flag as dead_reference

c2. Spec status references — grep for SPEC-NNN patterns If .design-state.yaml exists:

# For each SPEC-NNN found in memory content
grep "SPEC-{NNN}" .design-state.yaml
- If spec has status: completed but memory says "IN PROGRESS" or "active" → flag as stale_status - If spec ID not found in design state → flag as dead_reference - If spec is completed and memory entry only describes that spec's work → flag as ask_human (may no longer be relevant)

d. Date analysis — look for dates in the content: - Relative dates ("last week", "next Friday", "tomorrow", "yesterday") → flag as stale_date - Absolute dates older than 90 days → flag as old_date

e. Contradiction detection — compare key statements: - If two memory files claim different values for the same fact (e.g., "using React" vs "switched to Vue") → flag as contradiction - Compare against MEMORY.md index entries for consistency

  1. Classify each finding:
Classification Criteria Action
auto_remove Dead file/branch reference, date > 90 days old, clearly contradicted by newer memory Remove automatically
ask_human Ambiguous context, might still apply, function not found but could be in external dependency Present to user
keep Verified current, recent dates, references confirmed No action
  1. Report findings:
    Phase 2: Gather Signal
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Scanned: {N} files
    
    Findings:
      {X} clearly stale (auto-remove)
      {Y} uncertain (will ask you)
      {Z} current (no action)
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    

Phase 2B: Open Brain Staleness Detection

Skip if open_brain_available is false.

For recent thoughts (from Phase 1B sample), check for staleness:

a. Dead spec references — For each thought mentioning SPEC-NNN: - Check .design-state.yaml for the spec's status - If spec is completed/rejected but thought implies active work → flag as stale_status - If spec ID not found → flag as dead_reference

b. Contradictions — Use search_thoughts to find thoughts on the same topic: - If a newer thought reverses an earlier decision (e.g., "switched to X" vs earlier "using Y") → flag as contradiction - Keep the newer thought, flag the older for removal

c. Duplicates — Look for thoughts with very similar content captured within 24 hours: - Same topic, same conclusion, different timestamp → flag as duplicate - These typically come from the same workflow running twice

d. Temporal anomalies — Check thought dates: - Future dates → flag as anomaly - Dates older than 1 year → flag as old_thought

Classify each finding: auto_remove / ask_human / keep (same as local memory).

Display:

Phase 2B: Open Brain Signal
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Thoughts checked: {N}

Findings:
  {X} clearly stale (auto-remove)
  {Y} uncertain (will ask you)
  {Z} current (no action)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Phase 3: Consolidate

3a. Auto-remove clearly stale items:

For each auto_remove finding: - If the entire memory file is stale (all content references deleted things) → delete the file - If only specific lines are stale → edit the file to remove those lines - Log each removal to the archive file: {memory_dir}/archived-YYYY-MM-DD.log

# Archived by /vt-c-dream on YYYY-MM-DD

## Removed: {filename}
Reason: {reason}
Content:
{original content}
Append to existing archive file if it exists for today's date.

Display: "{X} stale entries auto-removed"

3b. Human confirmation for uncertain items:

For each ask_human finding, present via AskUserQuestion:

Memory: {filename}
Content: "{the relevant memory text}"

Why it might be stale:
  {reason — e.g., "References function calculate_total() which was not found in the codebase"}

Options: - Remove — delete this memory entry - Keep — it's still relevant, leave it - Edit — modify the memory (user provides updated text)

3c. Merge duplicates:

If two memory files cover the same topic (similar title, overlapping content): - Show both to the user - Ask: "These memories overlap. Merge into one?" - If yes: combine content, delete the duplicate file

3d. Fix dates:

Convert relative dates to absolute: - "last Friday" → "2026-03-28" (based on file modification date as reference) - "next week" → flag for human review (relative to when?)

Phase 3B: Open Brain Consolidation

Skip if open_brain_available is false or no findings from Phase 2B.

3B-a. Present stale thoughts for confirmation:

For each auto_remove finding from Phase 2B, show the batch:

Open Brain — {N} thoughts flagged for removal:

1. "{thought content preview}" — {reason}
2. "{thought content preview}" — {reason}
...

Confirm removal?

Use AskUserQuestion: - Remove all — purge all flagged thoughts - Review individually — present each one for Remove / Keep decision - Keep all — skip removal

3B-b. For ask_human findings, present each individually:

Thought: "{content preview}"
Captured: {date}
Why it might be stale: {reason}

Options: - Remove — purge this thought - Keep — it's still relevant

3B-c. Execute removals:

For each confirmed removal, call purge_content with the thought ID.

Display: "{X} Open Brain thoughts removed, {Y} kept"

Phase 4: Prune and Index

  1. Rebuild MEMORY.md:
  2. Read all remaining memory files
  3. For each file, generate a one-line entry (under 150 chars): - [{Title}]({filename}) — {one-line description}
  4. Sort semantically by topic (not chronologically)
  5. Remove any entries pointing to files that no longer exist
  6. Add entries for any memory files not yet in the index
  7. Target: under 200 lines

  8. If MEMORY.md exceeds 200 lines after rebuild:

  9. Display warning: "MEMORY.md is {N} lines (limit: 200). Consider consolidating more memories."
  10. Suggest which entries could be merged

  11. Write the updated MEMORY.md

  12. Display summary report (see Report Format below)

Report Format

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Memory Consolidation — {scope}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Local Memory:
  Files scanned: {N}
  Lines before: {before} → after: {after} (Δ {delta})
  Changes: {X} removed, {Y} kept, {W} merged, {D} dates fixed
  MEMORY.md: {lines} lines (limit: 200)

Open Brain: {connected | not connected}
  Thoughts checked: {N}
  Removed: {X} | Kept: {Y}
  Duplicates found: {W}

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

If Open Brain was not connected, the Open Brain section shows "not connected (skipped)".

Edge Cases

Scenario Handling
Empty memory directory Report "no files" and exit (continue to Open Brain if connected)
MEMORY.md doesn't exist Create it from scratch by scanning all memory files
Memory file has no frontmatter Process content as plain text
User-level memory directory missing Report and skip (only process what exists)
All memories are current Report "all current, no changes needed"
Memory references external system (Asana, GitHub) Skip verification — only verify local file/branch refs
Open Brain MCP tools unavailable Skip all B phases silently, display "not connected"
thought_stats returns 0 thoughts Skip 2B/3B, report "Open Brain is empty"
purge_content fails for a thought Log error, continue with remaining removals
list_thoughts times out Skip 2B/3B with warning, report in summary