Smart Memory (Zero Dep)
by @zgjq
Enhanced memory system for agentic workflows. Automatic memory extraction from conversations, memory type classification (preference/project/technical/lesson...
clawhub install smart-memory-zero-depπ About This Skill
name: smart-memory description: > Enhanced memory system for agentic workflows. Automatic memory extraction from conversations, memory type classification (preference/project/technical/lesson), temporal decay/archival, session-scoped temporary cache, and HOT RAM working memory with WAL protocol. Use when managing MEMORY.md, extracting insights from conversations, organizing memory files, archiving stale memories, searching memories by type, tracking current task state, or when the user says "remember this", "what do you know about X", "clean up memories", "what are we working on".
Smart Memory
Enhanced memory management for OpenClaw. Zero external dependencies. Inspired by Claude Code's memdir architecture.
Requirements
OPENCLAW_WORKSPACE β Workspace root (default: ~/.openclaw/workspace)
- OPENCLAW_SESSION_ID β Session identifier for temp cache (default: default)Security
Sensitive Data Protection
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.
Input Sanitization
Data Isolation
/tmp/ with sanitized session ID filenamesMemory Layers
| Layer | File | Purpose | Lifetime |
|-------|------|---------|----------|
| HOT RAM | SESSION-STATE.md | Current task, context, decisions | Session (survives compaction) |
| DAILY | memory/YYYY-MM-DD.md | Raw daily notes with type tags | 90 days β archive |
| CURATED | MEMORY.md | Promoted long-term facts | Permanent |
| ARCHIVE | memory/archive/YYYY-MM/ | Stale daily files | Forever (compressed) |
| CACHE | /tmp/openclaw-session-*.json | Session temp data | Session end / reboot |
Quick Reference
| Action | Script |
|--------|--------|
| WAL shortcut (any command) | scripts/wal task/decide/context/pending/done/blocker/get/snapshot/restore |
| Set current task | scripts/wal task "description" |
| Log a decision | scripts/wal decide "chose X over Y" |
| Add context | scripts/wal context key value |
| Snapshot & restore | scripts/wal snapshot / scripts/wal restore |
| Session cache | python3 scripts/session_cache.py set/get/list/clear |
| Classify (summary) | python3 scripts/classify_memory.py --summary |
| Decay (promote only) | python3 scripts/memory_decay.py --promote-only |
| Health report | bash scripts/memory_health.sh |
WAL Protocol (Write-Ahead Log)
Critical rule: Write BEFORE responding.
When the user provides information that should be remembered:
1. Write to SESSION-STATE.md (via session_state.py)
2. Then respond to the user
This prevents context loss if compaction, crash, or restart happens between response and write.
| User Action | WAL Write |
|-------------|-----------|
| States a preference | session_state.py context "pref" "value" |
| Makes a decision | session_state.py decide "chose X" |
| Gives a deadline | session_state.py context "deadline" "date" |
| Corrects agent | session_state.py decide "correction: X not Y" |
| Assigns task | session_state.py task "description" |
| Mentions blocker | session_state.py blocker "description" |
Memory Types
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-expiresCore Workflows
Session Start
1. ReadSESSION-STATE.md for current task/context
2. Run memory_search for relevant prior context
3. Check memory/YYYY-MM-DD.md for today's activityDuring Conversation (WAL)
1. User provides actionable info β write to SESSION-STATE.md FIRST 2. Important facts β append tomemory/YYYY-MM-DD.md with type tag
3. Use session_cache.py for transient session dataSession End
1. UpdateSESSION-STATE.md with final state
2. Promote durable items from daily notes to MEMORY.md
3. Run memory_health.sh periodically to check hygienePeriodic Maintenance
memory_decay.py when MEMORY.md > 200 lines or 50+ daily filesclassify_memory.py to tag orphaned entriesAgent Behavior
Auto-Extract When
Extraction Modes
extract_memories.sh --auto "text" β zero token cost, pure Pythonreferences/extraction_prompt.md template β costs tokens, better qualityDo NOT Extract
Auto-Decay When
File Format
MEMORY.md
## [PREF] Preferences
Favorite color: ζ·±θθ² [PROJ] Active Projects
ι»ιδΈη« : /root/ι»ιδΈη« /, golden3.killclaw.xyz [LESSON] Lessons Learned
Verify Telegram target before building notification workflows
Daily Notes
# 2026-03-31[PROJ] ι»ιδΈη«
Fixed scoring display to 10-point scale
SESSION-STATE.md
## Current Task
Building smart-memory skillKey Context
platform: ClawHub Recent Decisions
2026-03-31: Use zero-dependency approach Pending Actions
[ ] Publish to ClawHub
Scripts
| Script | Language | Purpose | Security |
|--------|----------|---------|----------|
| session_state.py | Python | HOT RAM working memory (WAL protocol) | Sensitive data filter + sanitization |
| session_cache.py | Python | Session-scoped temp key-value cache | Sensitive data filter + path-safe IDs |
| extract_memories.sh | Bash | Memory extraction guide and daily file init | Read-only output |
| memory_health.sh | Bash | Health report (stats, orphans, token estimate) | Read-only |
| memory_decay.py | Python | Temporal decay and archival of stale files | Dry-run mode available |
| classify_memory.py | Python | Keyword-based type classification | Dry-run mode available |
References
references/extraction_prompt.md β LLM prompt for auto-extractionreferences/memory_schema.md β Full schema and format specreferences/decay_rules.md β Decay/archival rule set