|
| 1 | +# Amygdala Design |
| 2 | + |
| 3 | +**Date:** 2026-01-17 |
| 4 | +**Status:** Ready for implementation |
| 5 | +**Branch:** chore/explore-amygdala |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Amygdala is a feature within memento that extracts behavioral habits from session history and injects them as low-context reflexes. While memento handles *declarative memory* (what happened), amygdala handles *procedural memory* (how to behave). |
| 10 | + |
| 11 | +**Neuroscience parallel:** |
| 12 | +- Hippocampus/explicit memory → Memento (sessions, facts) |
| 13 | +- Amygdala/implicit memory → Amygdala (habits, reflexes) |
| 14 | + |
| 15 | +### Core Concept |
| 16 | + |
| 17 | +``` |
| 18 | +Session files (memento) → Pattern extraction → Habits → Automatic injection |
| 19 | +``` |
| 20 | + |
| 21 | +### Key Constraints |
| 22 | + |
| 23 | +- Habits must be low-context (~10-15 tokens each) |
| 24 | +- Habits are behavioral ("when X, do Y") not factual ("user prefers Z") |
| 25 | +- Human-in-the-loop approval for all habit changes |
| 26 | +- Works offline, no remote infrastructure |
| 27 | +- Total habit injection: ~80-100 tokens |
| 28 | + |
| 29 | +### What Amygdala is NOT |
| 30 | + |
| 31 | +- Not a replacement for mantra rules (habits complement, don't replace) |
| 32 | +- Not automatic/unsupervised learning (you approve all habits) |
| 33 | +- Not a facts database (that's Claude /memory's job) |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +### Branding |
| 38 | + |
| 39 | +- Skill namespace: `/memento:amygdala` |
| 40 | +- Storage namespace: `.claude/amygdala/` |
| 41 | +- Documentation: "Memento's Amygdala" feature |
| 42 | + |
| 43 | +### Independence |
| 44 | + |
| 45 | +Amygdala uses memento's existing injection hooks. No dependency on mantra. |
| 46 | + |
| 47 | +``` |
| 48 | +mantra hooks → inject rules (independent) |
| 49 | +memento hooks → inject session context + amygdala habits (independent) |
| 50 | +``` |
| 51 | + |
| 52 | +## Storage Structure |
| 53 | + |
| 54 | +### Two-tier storage (global + project) |
| 55 | + |
| 56 | +``` |
| 57 | +~/.claude/amygdala/ |
| 58 | +├── habits.md # Global habits (travel with you) |
| 59 | +└── learned/ # Future: analysis artifacts |
| 60 | + └── patterns.json # Extracted patterns awaiting approval |
| 61 | +
|
| 62 | +<project>/.claude/amygdala/ |
| 63 | +├── habits.md # Project-specific habits |
| 64 | +└── learned/ |
| 65 | + └── patterns.json # Project-specific patterns |
| 66 | +``` |
| 67 | + |
| 68 | +### Why markdown (not JSON) |
| 69 | + |
| 70 | +- Human-readable and editable |
| 71 | +- Easy to manually curate in near-term |
| 72 | +- Git-friendly diffs |
| 73 | +- Matches mantra rules convention |
| 74 | +- Can include comments/context |
| 75 | + |
| 76 | +### Loading order |
| 77 | + |
| 78 | +1. Global habits (`~/.claude/amygdala/habits.md`) |
| 79 | +2. Project habits (`.claude/amygdala/habits.md`) |
| 80 | + |
| 81 | +Project habits are additive, not overriding. Both get injected. |
| 82 | + |
| 83 | +### Gitignore considerations |
| 84 | + |
| 85 | +- `habits.md` → committed (shared with team) |
| 86 | +- `learned/` → gitignored (personal analysis artifacts) |
| 87 | + |
| 88 | +## Habit Format |
| 89 | + |
| 90 | +### Ultra-compact stimulus → response |
| 91 | + |
| 92 | +```markdown |
| 93 | +# Amygdala |
| 94 | +error|bug|fail → reproduce → evidence → root-cause → fix |
| 95 | +new-feature → types → test-plan → implement |
| 96 | +about-to-code → check-existing-patterns |
| 97 | +complex-task → break-into-phases → verify-each |
| 98 | +commit → test → build → lint → commit |
| 99 | +milestone → update-session |
| 100 | +null-handling → check-null-before-stream |
| 101 | +async-operation → add-grace-period |
| 102 | +``` |
| 103 | + |
| 104 | +### Format specification |
| 105 | + |
| 106 | +- Left side: trigger/stimulus (context words separated by `|`) |
| 107 | +- Arrow `→`: implies automatic response |
| 108 | +- Right side: action sequence (steps separated by `→`) |
| 109 | + |
| 110 | +### Token budget |
| 111 | + |
| 112 | +- Target: ~80-100 tokens for all habits |
| 113 | +- ~8-10 habits × ~10-12 tokens = efficient injection |
| 114 | + |
| 115 | +## Injection Mechanism |
| 116 | + |
| 117 | +### Where |
| 118 | + |
| 119 | +Memento's existing `SessionStart` hook |
| 120 | + |
| 121 | +### When |
| 122 | + |
| 123 | +Every session start (same as session file detection) |
| 124 | + |
| 125 | +### Implementation |
| 126 | + |
| 127 | +```javascript |
| 128 | +// memento/hooks/session-start.js |
| 129 | +const globalHabits = loadIfExists(path.join(os.homedir(), '.claude/amygdala/habits.md')); |
| 130 | +const projectHabits = loadIfExists('.claude/amygdala/habits.md'); |
| 131 | + |
| 132 | +const amygdalaContext = [globalHabits, projectHabits] |
| 133 | + .filter(Boolean) |
| 134 | + .join('\n'); |
| 135 | + |
| 136 | +return { |
| 137 | + additionalContext: ` |
| 138 | +📂 Session: ${sessionPath} |
| 139 | +${sessionGuidance} |
| 140 | +
|
| 141 | +${amygdalaContext ? `🧠 Amygdala\n${amygdalaContext}` : ''} |
| 142 | + ` |
| 143 | +}; |
| 144 | +``` |
| 145 | + |
| 146 | +### User sees |
| 147 | + |
| 148 | +``` |
| 149 | +📂 Session: .claude/sessions/issue-feature-42.md |
| 150 | +🧠 Amygdala |
| 151 | +error|bug|fail → reproduce → evidence → root-cause → fix |
| 152 | +commit → test → build → lint → commit |
| 153 | +... |
| 154 | +``` |
| 155 | + |
| 156 | +## Skills |
| 157 | + |
| 158 | +### `/memento:amygdala` |
| 159 | + |
| 160 | +Show current habits and status. |
| 161 | + |
| 162 | +``` |
| 163 | +$ /memento:amygdala |
| 164 | +
|
| 165 | +🧠 Amygdala Status |
| 166 | +Global habits: ~/.claude/amygdala/habits.md (8 habits) |
| 167 | +Project habits: .claude/amygdala/habits.md (3 habits) |
| 168 | +
|
| 169 | +Current habits: |
| 170 | + error|bug|fail → reproduce → evidence → root-cause → fix |
| 171 | + commit → test → build → lint → commit |
| 172 | + ... |
| 173 | +``` |
| 174 | + |
| 175 | +### `/memento:amygdala add "<verbose>"` |
| 176 | + |
| 177 | +Takes verbose natural language, compacts to stimulus→response. |
| 178 | + |
| 179 | +``` |
| 180 | +$ /memento:amygdala add "When I'm debugging a bug, I should always |
| 181 | + reproduce it first, then gather evidence like logs or SQL queries, |
| 182 | + then identify the root cause before writing any fix code" |
| 183 | +
|
| 184 | +Compacted: |
| 185 | + bug|debug → reproduce → evidence → root-cause → fix |
| 186 | +
|
| 187 | +Add to: (1) global (2) project? 2 |
| 188 | +✓ Added to project habits |
| 189 | +``` |
| 190 | + |
| 191 | +The skill handles: |
| 192 | +- Extracting trigger words (bug, debug, commit, etc.) |
| 193 | +- Identifying action sequence |
| 194 | +- Compressing to `→` chain format |
| 195 | +- Asking global vs project |
| 196 | +- Writing to appropriate file |
| 197 | + |
| 198 | +### `/memento:amygdala learn` (Phase 2) |
| 199 | + |
| 200 | +Analyze recent sessions, suggest habits for approval. |
| 201 | + |
| 202 | +``` |
| 203 | +$ /memento:amygdala learn |
| 204 | +
|
| 205 | +Analyzing 12 sessions... |
| 206 | +
|
| 207 | +Suggested habits (approve with 'y', skip with 'n'): |
| 208 | +
|
| 209 | +1. filter-bug → verify-hierarchy-level (appeared 8/12 sessions) |
| 210 | + [y/n]? y ✓ Added |
| 211 | +
|
| 212 | +2. state-issue → check-single-source-of-truth (appeared 6/12 sessions) |
| 213 | + [y/n]? n ✗ Skipped |
| 214 | +``` |
| 215 | + |
| 216 | +### `/memento:amygdala prune` (Phase 2) |
| 217 | + |
| 218 | +Review habits, remove stale ones. |
| 219 | + |
| 220 | +## Coexistence with Mantra |
| 221 | + |
| 222 | +### Key distinction |
| 223 | + |
| 224 | +| Aspect | Mantra Rules | Amygdala Habits | |
| 225 | +|--------|--------------|-----------------| |
| 226 | +| Format | Rich YAML, BLOCKING requirements | Ultra-compact stimulus→response | |
| 227 | +| Enforcement | "You MUST... STOP" - hard stops | Gentle reminder - no enforcement | |
| 228 | +| Scope | Specific triggers, verification phrases | General behavioral nudges | |
| 229 | +| Token cost | ~100-500 tokens per rule | ~10-15 tokens per habit | |
| 230 | +| Purpose | Enforce compliance | Reinforce reflex | |
| 231 | + |
| 232 | +### Example of complementary coexistence |
| 233 | + |
| 234 | +``` |
| 235 | +MANTRA RULE (behavior.md): |
| 236 | + trigger: user reports error, bug |
| 237 | + priority: BLOCKING |
| 238 | + action: find-documented-evidence-before-fixing |
| 239 | + verify: "Consulting troubleshoot checklist" |
| 240 | +
|
| 241 | +AMYGDALA HABIT: |
| 242 | + bug|error → reproduce → evidence → root-cause → fix |
| 243 | +``` |
| 244 | + |
| 245 | +- Mantra **enforces** the full process with verification |
| 246 | +- Amygdala **reminds** of the sequence at a glance |
| 247 | + |
| 248 | +### Coexistence rules |
| 249 | + |
| 250 | +1. **Habits don't override rules** - Mantra BLOCKING requirements always win |
| 251 | +2. **Habits are reminders** - Quick glance reference, not enforcement |
| 252 | +3. **No duplicate enforcement** - If mantra has a rule, habit is just a nudge |
| 253 | +4. **Different triggers** - Habits fire on context; rules fire on explicit user language |
| 254 | + |
| 255 | +## Implementation Plan |
| 256 | + |
| 257 | +### Phase 1: Near-term (manual curation) - ~3-4 hours |
| 258 | + |
| 259 | +| Task | Effort | Files | |
| 260 | +|------|--------|-------| |
| 261 | +| Create storage structure | 15 min | `~/.claude/amygdala/habits.md` template | |
| 262 | +| Add habit loading to SessionStart hook | 1 hour | `memento/hooks/session-start.js` | |
| 263 | +| Create `/memento:amygdala` skill (show habits) | 30 min | `memento/commands/amygdala.md` | |
| 264 | +| Create `/memento:amygdala add` skill (verbose→compact) | 1.5 hours | `memento/commands/amygdala-add.md` | |
| 265 | +| Seed with discovered habits from analysis | 30 min | `habits.md` content | |
| 266 | +| Tests | 30 min | `memento/__tests__/amygdala.test.js` | |
| 267 | + |
| 268 | +### Phase 2: Long-term (automatic learning) - ~2-3 days |
| 269 | + |
| 270 | +| Task | Effort | |
| 271 | +|------|--------| |
| 272 | +| `/memento:amygdala learn` - session analysis | 4-6 hours | |
| 273 | +| Pattern extraction algorithm | 4-6 hours | |
| 274 | +| Confidence scoring | 2 hours | |
| 275 | +| `/memento:amygdala prune` - staleness detection | 2 hours | |
| 276 | +| `learned/patterns.json` storage | 1 hour | |
| 277 | + |
| 278 | +### Files to create/modify |
| 279 | + |
| 280 | +``` |
| 281 | +memento/ |
| 282 | +├── hooks/ |
| 283 | +│ └── session-start.js # MODIFY: add habit loading |
| 284 | +├── commands/ |
| 285 | +│ ├── amygdala.md # NEW: show habits |
| 286 | +│ ├── amygdala-add.md # NEW: add habit (verbose→compact) |
| 287 | +│ ├── amygdala-learn.md # NEW (phase 2): analyze sessions |
| 288 | +│ └── amygdala-prune.md # NEW (phase 2): remove stale |
| 289 | +├── lib/ |
| 290 | +│ └── amygdala.js # NEW: habit loading utilities |
| 291 | +└── __tests__/ |
| 292 | + └── amygdala.test.js # NEW: tests |
| 293 | +``` |
| 294 | + |
| 295 | +## Success Criteria |
| 296 | + |
| 297 | +- [ ] Habits appear in session context with 🧠 emoji |
| 298 | +- [ ] `/memento:amygdala` shows current habits |
| 299 | +- [ ] `/memento:amygdala add "verbose"` compacts and saves |
| 300 | +- [ ] Global habits work across projects |
| 301 | +- [ ] Project habits are additive |
| 302 | +- [ ] ~100 tokens total habit injection |
| 303 | + |
| 304 | +## Research Summary |
| 305 | + |
| 306 | +### Data analyzed |
| 307 | + |
| 308 | +- 139 sessions across 2 projects (client-backend: 89, client-frontend: 50) |
| 309 | +- 30,844 lines of session history |
| 310 | +- Corpus saved to `/tmp/amygdala-corpus/` |
| 311 | + |
| 312 | +### Discovered universal habits (Tier 1-2, 85-100% frequency) |
| 313 | + |
| 314 | +- Test before commit |
| 315 | +- Track files changed |
| 316 | +- Pre-implementation context gathering |
| 317 | +- Build → lint → test order |
| 318 | +- Root cause documentation before fixing |
| 319 | +- Type safety first |
| 320 | + |
| 321 | +### Existing alternatives reviewed |
| 322 | + |
| 323 | +- **Claude Diary** - Similar concept, focuses on knowledge not behaviors |
| 324 | +- **Mem0** - Extracts facts/preferences, not action patterns |
| 325 | +- **USER-LLM** - Model-level user embeddings, not user-controllable |
| 326 | +- **CLAUDE.md** - Static rules, no learning loop |
| 327 | + |
| 328 | +### Gap filled by Amygdala |
| 329 | + |
| 330 | +Learned behavioral reflexes from session patterns with human-in-the-loop approval. |
| 331 | + |
| 332 | +## Sources |
| 333 | + |
| 334 | +- [Claude Diary by Lance Martin](https://rlancemartin.github.io/2025/12/01/claude_diary/) |
| 335 | +- [Mem0 Chat History Guide](https://mem0.ai/blog/llm-chat-history-summarization-guide-2025) |
| 336 | +- [Claude Code Memory Docs](https://code.claude.com/docs/en/memory) |
| 337 | +- [Claude Code Feature Request #87](https://github.com/anthropics/claude-code/issues/87) |
| 338 | +- [USER-LLM Google Research](https://research.google/blog/user-llm-efficient-llm-contextualization-with-user-embeddings/) |
0 commit comments