Enhanced memory management for OpenClaw. Zero external dependencies. Inspired by Claude Code's memdir architecture.
Runtime: Python 3.10+ (standard library only), Bash 4.0+ (health/extract scripts only)
OS: Linux, macOS
Environment variables (all optional, with defaults):
OPENCLAW_WORKSPACE — Workspace root (default: ~/.openclaw/workspace)OPENCLAW_SESSION_ID — Session identifier for temp cache (default: default)All write commands ( session_state.py, session_cache.py) automatically reject inputs matching:
sk-*, GitHub ghp_*, ClawHub clh_*)password=, passwd:, etc.)-----BEGIN PRIVATE KEY-----)This is a hard block at the script level — the agent cannot bypass it. The regex patterns are conservative (high precision, may miss exotic formats); the agent should additionally avoid extracting any credential-like text even if not matched.
/tmp/ with sanitized session ID filenamesLayerFilePurposeLifetimeHOT RAMSESSION-STATE.mdCurrent task, context, decisionsSession (survives compaction)DAILYmemory/YYYY-MM-DD.mdRaw daily notes with type tags90 days → archiveCURATEDMEMORY.mdPromoted long-term factsPermanentARCHIVEmemory/archive/YYYY-MM/Stale daily filesForever (compressed)CACHE/tmp/openclaw-session-*.jsonSession temp dataSession end / reboot
ActionScriptWAL shortcut (any command)scripts/wal task/decide/context/pending/done/blocker/get/snapshot/restoreSet current taskscripts/wal task "description"Log a decisionscripts/wal decide "chose X over Y"Add contextscripts/wal context key valueSnapshot & restorescripts/wal snapshot / scripts/wal restoreSession cachepython3 scripts/session_cache.py set/get/list/clearClassify (summary)python3 scripts/classify_memory.py --summaryDecay (promote only)python3 scripts/memory_decay.py --promote-onlyHealth reportbash scripts/memory_health.sh
Critical rule: Write BEFORE responding.
When the user provides information that should be remembered:
session_state.py)This prevents context loss if compaction, crash, or restart happens between response and write.
User ActionWAL WriteStates a preferencesession_state.py context "pref" "value"Makes a decisionsession_state.py decide "chose X"Gives a deadlinesession_state.py context "deadline" "date"Corrects agentsession_state.py decide "correction: X not Y"Assigns tasksession_state.py task "description"Mentions blockersession_state.py blocker "description"
All entries tagged with a type prefix:
[PREF] — User preferences, habits, style[PROJ] — Project context, active work, goals[TECH] — Technical details, configs, system knowledge[LESSON] — Lessons learned, errors, corrections[PEOPLE] — People, relationships, social context[TEMP] — Session-scoped, auto-expiresSESSION-STATE.md for current task/contextmemory_search for relevant prior contextmemory/YYYY-MM-DD.md for today's activitymemory/YYYY-MM-DD.md with type tagsession_cache.py for transient session dataSESSION-STATE.md with final stateMEMORY.mdmemory_health.sh periodically to check hygienememory_decay.py when MEMORY.md > 200 lines or 50+ daily filesclassify_memory.py to tag orphaned entriesextract_memories.sh --auto "text" — zero token cost, pure Pythonreferences/extraction_prompt.md template — costs tokens, better qualitymarkdown
## [PREF] Preferences
- Favorite color: 深蓝色
## [PROJ] Active Projects
- 黄金三章: /root/黄金三章/, golden3.killclaw.xyz
## [LESSON] Lessons Learned
- Verify Telegram target before building notification workflows
markdown
# 2026-03-31
## [PROJ] 黄金三章
- Fixed scoring display to 10-point scale
markdown
## Current Task
Building smart-memory skill
## Key Context
- **platform**: ClawHub
## Recent Decisions
- **2026-03-31**: Use zero-dependency approach
## Pending Actions
- [ ] Publish to ClawHub
ScriptLanguagePurposeSecuritysession_state.pyPythonHOT RAM working memory (WAL protocol)Sensitive data filter + sanitizationsession_cache.pyPythonSession-scoped temp key-value cacheSensitive data filter + path-safe IDsextract_memories.shBashMemory extraction guide and daily file initRead-only outputmemory_health.shBashHealth report (stats, orphans, token estimate)Read-onlymemory_decay.pyPythonTemporal decay and archival of stale filesDry-run mode availableclassify_memory.pyPythonKeyword-based type classificationDry-run mode available
references/extraction_prompt.md — LLM prompt for auto-extractionreferences/memory_schema.md — Full schema and format specreferences/decay_rules.md — Decay/archival rule set