Does your AI Agent get dumber as it remembers more? This system helps you manage OpenClaw memory efficiently, reducing token usage by 78%.
Based on @ohxiyu's P0/P1/P2 priority system.
Before After
├── Lines: 427 ├── Lines: 96 (-77%)
├── Tokens: 6,618 ├── Tokens: 1,488 (-78%)
├── Maintenance: Manual ├── Maintenance: Auto cron
├── Iron Rules: 17 scattered ├── Iron Rules: 5 centralized
└── Lesson recall: Full scan └── Lesson recall: Semantic search
MEMORY.md (Hot Memory) ← Loaded every session, ≤200 lines
├── [P0] Core identity ← Never expires
├── [P1][date] Active project ← 90-day TTL
└── [P2][date] Temporary ← 30-day TTL
memory/lessons/*.jsonl ← Structured lessons, semantic search
memory/archive/ ← Expired content, searchable but not loaded
memory/YYYY-MM-DD.md ← Daily raw logs
cp templates/MEMORY.md ~/.openclaw/workspace/MEMORY.md
cp scripts/memory-janitor.py ~/.openclaw/workspace/scripts/
mkdir -p ~/.openclaw/workspace/memory/{archive,lessons}# Daily at 4 AM UTC
(crontab -l 2>/dev/null; echo "0 4 * * * python3 ~/.openclaw/workspace/scripts/memory-janitor.py >> ~/.openclaw/workspace/logs/memory-janitor.log 2>&1") | crontab -# Preview mode (no changes)
python3 scripts/memory-janitor.py --dry-run
# Show statistics
python3 scripts/memory-janitor.py --stats
# Run archival
python3 scripts/memory-janitor.py| File | Description |
|---|---|
scripts/memory-janitor.py |
Auto-archive script, P2>30d/P1>90d → archive |
templates/MEMORY.md |
Hot memory template with P0/P1/P2 format |
templates/AGENTS-rules.md |
5 core principles example |
templates/lessons.jsonl |
Structured lesson format |
Format: - [Priority][Date] Content
- P0 — Core identity, never expires. e.g., user preferences, safety rules
- P1 — Active projects, 90-day TTL. e.g., current projects, recent strategies
- P2 — Temporary, 30-day TTL. e.g., debug notes, one-time events
- [P0] User prefers Chinese responses
- [P1][2026-02-07] TaxForge v1.4.0 released
- [P2][2026-02-05] Debugged cron timezone issueKeep only 5 rules. Store other lessons in lessons/*.jsonl for semantic search:
- Real money = correctness > speed — Use identical tested code for transactions
- Confirm before external actions — Ask before sending emails, tweets, public posts
- Two automation systems — Check both system crontab + OpenClaw cron
- Process isolation — Long-running bots need setsid, or they get killed by session cleanup
- Platform rules first — Read settlement rules before trading on new platforms
cp -r skills/memory-management ~/.openclaw/skills/
# or
cp -r skills/memory-management ~/clawd/skills/Option 1: Add CLAUDE.md to project root:
cp claude-code/CLAUDE.md ~/your-project/CLAUDE.mdOption 2: Add as a rule:
mkdir -p ~/your-project/.claude/rules
cp claude-code/.claude/rules/memory-management.md ~/your-project/.claude/rules/MIT