Automatic memory consolidation inspired by Claude Code's autoDream/KAIROS. Runs as a background cron job every 24h — reviews recent sessions, consolidates memory, prunes stale entries, and updates MEMORY.md. Zero manual intervention needed. Use to enable always-on memory maintenance.
Inspired by Claude Code's leaked autoDream service and KAIROS always-on agent. Runs automatically as a cron job to keep your memory clean, current, and useful.
Every 24 hours (configurable), auto-dream:
┌─────────────────────────────────────────────┐
│ AUTO-DREAM CYCLE │
│ │
│ Cron fires (every 24h) │
│ ↓ │
│ Gate check: │
│ - 24h since last dream? ✓ │
│ - New activity exists? ✓ │
│ ↓ │
│ Spawn isolated sub-agent │
│ ↓ │
│ Phase 1: Orient (read MEMORY.md) │
│ Phase 2: Gather (scan daily files) │
│ Phase 3: Consolidate (update memories) │
│ Phase 4: Prune (trim, clean, index) │
│ ↓ │
│ Log result to memory/dream-log.json │
│ Update last-dream timestamp │
│ ↓ │
│ Done (silent unless notable changes) │
└─────────────────────────────────────────────┘
The agent should create this cron on first use:
Schedule: every 24 hours (e.g., 03:00 UTC = 11:00 WITA)
Session: isolated (separate from main)
Payload: agentTurn with the dream prompt
Delivery: announce (notify Lucy only if significant changes)
Say: "Dream now" or "Consolidate memory"
This is what the sub-agent receives. It follows Claude Code's 4-phase structure adapted for OpenClaw:
# Dream: Memory Consolidation
You are performing a dream — a reflective pass over your memory files.
Synthesize what you've learned recently into durable, well-organized memories.
Memory directory: ~/.openclaw/workspace/memory/
Main memory: ~/.openclaw/workspace/MEMORY.md
---
## Phase 1 — Orient
- Read MEMORY.md to understand the current long-term memory state
- List memory/ directory to see daily files and evaluations
- Skim the last 3 days of memory/YYYY-MM-DD.md files
- Check memory/lessons.json if it exists (L2 knowledge)
- Check memory/dream-log.json for last dream results
## Phase 2 — Gather Recent Signal
Look for new information worth persisting:
1. Recent daily files (last 48h) — new decisions, discoveries, events
2. Evaluation files (memory/evaluations/) — task quality patterns
3. Contradictions — facts in MEMORY.md that conflict with recent activity
4. Stale entries — references to completed/cancelled projects, outdated context
Focus on SIGNAL, not noise. Don't persist routine operations.
## Phase 3 — Consolidate
For each thing worth remembering:
- If it updates existing MEMORY.md content → edit in place
- If it's new long-term knowledge → add to appropriate section
- If it contradicts existing memory → fix the old entry
- Convert relative dates to absolute ("yesterday" → "2026-04-04")
- Merge duplicate entries
For lessons.json (if hierarchical-memory skill is active):
- Check if any L1 evaluations from last 7 days form patterns (3+ occurrences)
- Promote to L2 lessons if warranted
## Phase 4 — Prune and Index
MEMORY.md maintenance:
- Remove entries about completed/cancelled projects (unless lesson is universal)
- Remove outdated contact info, stale URLs, obsolete infrastructure details
- Keep under 200 lines — if over, prune least-referenced entries
- Ensure all sections are current and accurate
Daily file maintenance:
- Files older than 90 days → move to memory/archive/YYYY-MM/
## Phase 5 — Log
Write dream results to memory/dream-log.json:
{
"timestamp": "ISO 8601",
"changes": ["what was added/updated/removed"],
"memory_md_lines_before": N,
"memory_md_lines_after": N,
"files_archived": N,
"lessons_promoted": N,
"notable": true/false
}
If notable=true (significant changes), summarize what changed.
If nothing changed, log "no changes needed" and exit quietly.
---
Return a brief summary of what you consolidated, updated, or pruned.
Before running the dream, check:
memory/dream-log.json timestamp)If any gate fails, skip silently.
memory/dream-log.json:
{
"lastDreamAt": "2026-04-04T03:00:00Z",
"dreams": [
{
"timestamp": "2026-04-04T03:00:00Z",
"changes": [
"Updated Council agent table (added Metis)",
"Removed stale DataFlow April 5 deadline reference",
"Archived 3 daily files (>90 days old)",
"Promoted 1 lesson: sub-agent timeout pattern"
],
"memory_md_lines_before": 155,
"memory_md_lines_after": 148,
"files_archived": 3,
"lessons_promoted": 1,
"notable": true
}
]
}
Keep only last 30 dream entries. Older ones get dropped.
If the hierarchical-memory skill is installed, auto-dream also:
memory/rules.md for consistency — remove contradicted rules, add new ones from recent correctionsThis replaces the need for separate weekly/monthly cron jobs.
Default values (can be adjusted):
dreamIntervalHours: 24minActivityFiles: 1 (minimum daily files since last dream)dreamTimeUtc: "03:00" (11:00 WITA — while Lucy sleeps)maxMemoryMdLines: 200archiveAfterDays: 90maxDreamLogEntries: 30announceIfNotable: true (send notification if significant changes)