$npx -y skills add HelloRuru/claude-memory-engine --skill skillMemory management system for Claude Code — Student Loop, Smart Context, Auto Learn, Session Handoff, Correction Cycle. Triggered by memory commands (/save, /reflect, /handoff, /check) or memory-related questions. Not for general programming tasks.
| 1 | # Memory Engine v1.6 |
| 2 | |
| 3 | A memory and learning system for Claude Code, built with hooks and markdown. |
| 4 | |
| 5 | ## Modules |
| 6 | |
| 7 | ### 1. Smart Context |
| 8 | |
| 9 | Auto-detects the current project from your working directory and loads its memory. |
| 10 | |
| 11 | - Resolves per-project memory directory automatically — no hardcoded paths |
| 12 | - Implementation: `~/.claude/scripts/hooks/session-start.js` |
| 13 | - Config: `references/smart-context.md` |
| 14 | |
| 15 | ### 2. Auto Learn (Pitfall Detection) |
| 16 | |
| 17 | Detects pitfall patterns before context compression — retries, errors followed by fixes, user corrections. |
| 18 | |
| 19 | - Saves both the problem and the fix to `~/.claude/skills/learned/` |
| 20 | - Same mistake 3+ times across different days → suggests writing it into permanent rules |
| 21 | - Implementation: `shared-utils.js` → `detectPitfalls()` + `savePitfalls()` |
| 22 | |
| 23 | ### 3. Student Loop (/reflect) |
| 24 | |
| 25 | 8-step learning cycle. First 3 steps are automatic (every session). Last 5 via `/reflect`. |
| 26 | |
| 27 | 1. Takes notes — records what was done, files changed, decisions made |
| 28 | 2. Links them — tags the project, connects to previous notes |
| 29 | 3. Spots patterns — scans for pitfall signals |
| 30 | |
| 31 | There is no real "end" to a Claude Code conversation. Memory Engine saves at three points: |
| 32 | - **Every 20 messages** (`mid-session-checkpoint`) — most reliable, self-counted |
| 33 | - **Before context compression** (`pre-compact`) — pitfall detection runs here, context is fullest |
| 34 | - **When conversation ends** (`session-end`) — best-effort, not guaranteed to fire |
| 35 | |
| 36 | You don't need to remember to run any command before closing. |
| 37 | 4. Review — read past 7 days, mark useful vs outdated |
| 38 | 5. Refine — 4-question decision tree (Keep? Condense? Already covered? Delete as last resort) |
| 39 | 6. Re-study — re-analyze cleaned data for buried patterns |
| 40 | 7. Slim down — list removable items, wait for user confirmation |
| 41 | 8. Wrap up — produce a report |
| 42 | |
| 43 | ### 4. Session Handoff (/handoff) |
| 44 | |
| 45 | Pass context between Claude Code windows without losing progress. |
| 46 | |
| 47 | - `/handoff` saves a `handoff-*.md` file with progress, decisions, unfinished tasks |
| 48 | - Next session auto-detects it on startup (`session-start.js`) |
| 49 | - Mid-conversation detection via `memory-sync.js` |
| 50 | - Each handoff is shown once, tracked by `.handoff-read.json` |
| 51 | |
| 52 | ### 5. Correction Cycle (/analyze) |
| 53 | |
| 54 | Learns from user corrections — mistakes that don't show up in error logs. |
| 55 | |
| 56 | - **Analyze** (`/analyze`) — compare user's edits against rules, log missed rules, distill new ones |
| 57 | - **Correct** (auto, before tasks) — scan the error list as a reminder |
| 58 | - **Reflect** (`/reflect` step 6) — same mistake 3+ times → upgrade to hard rule |
| 59 | |
| 60 | ## Hooks |
| 61 | |
| 62 | | Hook | File | What it does | |
| 63 | | :--- | :--- | :----------- | |
| 64 | | SessionStart | session-start.js | Load last summary + project memory + pending handoffs + pitfall review + /reflect reminder | |
| 65 | | SessionEnd | session-end.js | Save summary + project index + backup (best-effort, may not fire) | |
| 66 | | PreCompact | pre-compact.js | Snapshot + pitfall detection + backup — the real safety net | |
| 67 | | UserPromptSubmit | memory-sync.js | Cross-session memory change detection + handoff detection | |
| 68 | | UserPromptSubmit | mid-session-checkpoint.js | Checkpoint every 20 messages | |
| 69 | | PreToolUse(Write) | write-guard.js | Sensitive file write warning | |
| 70 | | PreToolUse(Bash) | pre-push-check.js | Safety check before git push | |
| 71 | | — | memory-backup.sh | Bidirectional sync script (push/pull/sync) — v1.6 | |
| 72 | |
| 73 | Shared logic between `session-end.js` and `pre-compact.js` is extracted into `shared-utils.js`. |
| 74 | |
| 75 | ## Commands (36 files, 18 pairs EN + ZH) |
| 76 | |
| 77 | | EN | ZH | Function | |
| 78 | | :- | :- | :------- | |
| 79 | | /save | /存記憶 | Save memory — auto-dedup, route to correct file | |
| 80 | | /reload | /讀取 | Load memory into current conversation | |
| 81 | | /todo | /待辦 | Cross-project task tracking | |
| 82 | | /backup | /備份 | Push local memory to GitHub (`memory-backup.sh push`) | |
| 83 | | /sync | /同步 | Bidirectional sync (`memory-backup.sh sync`) — v1.6 pull+push | |
| 84 | | /handoff | /交接 | Session handoff — pass progress to next window | |
| 85 | | /diary | /回顧 | Generate reflection diary | |
| 86 | | /reflect | /反思 | Analyze pitfalls, find patterns | |
| 87 | | /learn | /學習 | Manually save a pitfall | |
| 88 | | /analyze | /分析 | Record corrections into error notebook | |
| 89 | | /correct | /訂正 | Review error notebook anytime | |
| 90 | | /check | /健檢 | Quick health scan | |
| 91 | | /full-check | /大健檢 | Full audit | |
| 92 | | /memory-health | /記憶健檢 | Memory file stats + capacity warnings | |
| 93 | | /memory-search | /搜尋記憶 | Keyword search across all memory files | |
| 94 | | /recover | /想起來 | Restore memory from GitHub (`memory-backup.sh pull`) — v1.6 auto-distribute | |
| 95 | | /compact-guide | /壓縮建議 | When to compact and when not to | |
| 96 | | /overview | /全覽 | List all available commands | |
| 97 | |
| 98 | ## File Structure |
| 99 | |
| 100 | ```text |
| 101 | ~/.claude/ |
| 102 | scripts/hooks/ |
| 103 | session-start.js # Load recall + smart-context + handoff |
| 104 | session-end.js |