Automated daily memory backfill for OpenClaw sessions
by @mpesavento
Scrape and analyze OpenClaw JSONL session logs to reconstruct and backfill agent memory files. Use when: (1) Memory appears incomplete after model switches, (2) Verifying memory coverage, (3) Reconstructing lost memory, (4) Automated daily memory sync via cron/heartbeat. Supports simple extraction and LLM-based narrative summaries with automatic secret sanitization.
clawhub install memory-syncπ About This Skill
name: memory-sync description: > Scrape and analyze OpenClaw JSONL session logs to reconstruct and backfill agent memory files. Use when: (1) Memory appears incomplete after model switches, (2) Verifying memory coverage, (3) Reconstructing lost memory, (4) Automated daily memory sync via cron/heartbeat. Supports simple extraction and LLM-based narrative summaries with automatic secret sanitization.
Memory Sync
Tool for maintaining agent memory continuity across model switches with automatic secret sanitization.
Installation
Requires Python 3.11+ and click:
pip install clickOptional: for direct API summarization (only if not using OpenClaw backend)
pip install openai
Quick Start
# Run directly from skill directory
python ~/.openclaw/skills/memory-sync/memory_sync.py compareOr create an alias for convenience
alias memory-sync="python ~/.openclaw/skills/memory-sync/memory_sync.py"Check for gaps
memory-sync compareBackfill today's memory (simple extraction - fast, no LLM)
memory-sync backfill --todayBackfill with LLM narrative (uses OpenClaw's native model - no API key needed)
memory-sync backfill --today --summarizeBackfill all missing
memory-sync backfill --all
Commands
| Command | Description |
|---------|-------------|
| compare | Find gaps between session logs and memory files |
| backfill --today | Generate memory for current day |
| backfill --since YYYY-MM-DD | Backfill from date to present |
| backfill --all | Backfill all missing dates |
| backfill --incremental | Backfill only changed dates since last run |
| extract | Extract conversations matching criteria |
| summarize --date YYYY-MM-DD | Generate LLM summary for a single day |
| transitions | List model transitions |
| validate | Check memory files for consistency issues |
| stats | Show coverage statistics |
Simple Extraction vs LLM Summarization
The backfill command supports two modes:
Simple Extraction (default, without --summarize):
--preserve: Hand-written content is appended to the end of the new fileLLM Summarization (with --summarize) - Recommended:
--preserve: Existing content is passed to the LLM with instructions to incorporate it into the new summary, maintaining temporal order and thematic structureRecommended for regular use:
# Best quality: LLM summary that incorporates any existing notes
memory-sync backfill --today --summarize --preserve
Both modes automatically sanitize secrets before writing.
Common Workflows
Initial Setup
# Check what's missing
memory-sync compareBackfill everything (may take time)
memory-sync backfill --all
Nightly Automation (Recommended)
# Best: LLM summary that incorporates any existing notes
memory-sync backfill --today --summarize --preserveSmart: Process only days changed since last run
memory-sync backfill --incremental --summarize --preserveOr use a specific backend if preferred
memory-sync backfill --today --summarize --preserve --summarize-backend anthropic
Catch-Up After Gaps
# Backfill from last week to present
memory-sync backfill --since 2026-01-28 --summarize
Regenerate with Preserved Content
# Keep hand-written notes when regenerating
memory-sync backfill --date 2026-02-05 --force --preserve --summarize
Secret Sanitization
All content is automatically sanitized to prevent secret leakage:
Secrets are replaced with [REDACTED-TYPE] placeholders.
See SECRET_PATTERNS.md for complete pattern list.
Summarization Backends
The --summarize flag supports multiple backends via --summarize-backend:
| Backend | Description | API Key Required |
|---------|-------------|------------------|
| openclaw (default) | Uses OpenClaw's sessions spawn with your configured model | No |
| anthropic | Direct Anthropic API via openai package | ANTHROPIC_API_KEY |
| openai | Direct OpenAI API via openai package | OPENAI_API_KEY |
Examples
# Default: use OpenClaw's native model (no API key needed)
memory-sync backfill --today --summarizeExplicit backend selection
memory-sync backfill --today --summarize --summarize-backend openclaw
memory-sync backfill --today --summarize --summarize-backend anthropic
memory-sync backfill --today --summarize --summarize-backend openaiOverride model for any backend
memory-sync backfill --today --summarize --model claude-sonnet-4-20250514
memory-sync backfill --today --summarize --summarize-backend openai --model gpt-4o
The openclaw backend is recommended as it:
Automated Usage
Nightly Cron (3am)
Process today with LLM summary, preserving any existing notes:
0 3 * * * cd ~/.openclaw/skills/memory-sync && python memory_sync.py backfill --today --summarize --preserve >> ~/.memory-sync/cron.log 2>&1
Smart Incremental Mode
Automatically detects changes since last run:
# Initial backfill (run once, simple extraction for speed)
python memory_sync.py backfill --allThen set up nightly incremental with LLM summaries
0 3 * * * cd ~/.openclaw/skills/memory-sync && python memory_sync.py backfill --incremental --summarize --preserve >> ~/.memory-sync/cron.log 2>&1
State is tracked in ~/.memory-sync/state.json.
Configuration
Default paths:
~/.openclaw/agents/main/sessions/*.jsonl~/.openclaw/workspace/memory/Override with CLI flags:
--sessions-dir /path/to/sessions--memory-dir /path/to/memoryEnvironment variables (only for direct API backends):
ANTHROPIC_API_KEY - Required for --summarize-backend anthropicOPENAI_API_KEY - Required for --summarize-backend openaiThe default openclaw backend requires no API keys - it uses your OpenClaw configuration.
# Only needed if using direct API backends
export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...
Content Preservation
The --preserve flag behavior depends on whether --summarize is used:
Without --summarize (simple extraction):
With --summarize (LLM mode):
Example:
# Regenerate with LLM, incorporating existing notes into the summary
memory-sync backfill --date 2026-02-05 --force --preserve --summarize
Auto-generated markers:
*Auto-generated from N session messages**Review and edit this draft to capture what's actually important.*Content after the footer marker is considered hand-written and will be preserved.
Backfill Options
Date selection (choose one):
--date YYYY-MM-DD - Single specific date--today - Current date only (for nightly automation)--since YYYY-MM-DD - From date to present (for catch-up)--all - All missing dates (for initial setup)--incremental - Only dates changed since last run (smart automation)Additional flags:
--dry-run - Show what would be created without creating files--force - Overwrite existing files (required for regeneration)--preserve - Keep hand-written content when regenerating--summarize - Use LLM for narrative summaries--summarize-backend BACKEND - Backend for summarization: openclaw (default), anthropic, openai--model MODEL - Model override for summarization (default varies by backend)Performance
| Mode | Time per Day | Best For |
|------|-------------|----------|
| --all | 5-10 min Γ N days | Initial setup only |
| --since | 5-10 min Γ N days | Recovery after gaps |
| --today | 30-60 sec | Nightly automation |
| --incremental | 30-60 sec Γ changed days | Smart automation |
π‘ Examples
# Default: use OpenClaw's native model (no API key needed)
memory-sync backfill --today --summarizeExplicit backend selection
memory-sync backfill --today --summarize --summarize-backend openclaw
memory-sync backfill --today --summarize --summarize-backend anthropic
memory-sync backfill --today --summarize --summarize-backend openaiOverride model for any backend
memory-sync backfill --today --summarize --model claude-sonnet-4-20250514
memory-sync backfill --today --summarize --summarize-backend openai --model gpt-4o
The openclaw backend is recommended as it:
βοΈ Configuration
Default paths:
~/.openclaw/agents/main/sessions/*.jsonl~/.openclaw/workspace/memory/Override with CLI flags:
--sessions-dir /path/to/sessions--memory-dir /path/to/memoryEnvironment variables (only for direct API backends):
ANTHROPIC_API_KEY - Required for --summarize-backend anthropicOPENAI_API_KEY - Required for --summarize-backend openaiThe default openclaw backend requires no API keys - it uses your OpenClaw configuration.
# Only needed if using direct API backends
export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...