You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #673 from jphein/feat/deterministic-hook-save
Clean squash by jphein on 2026-04-21. Backwards-compatible via hook_silent_save config flag. Save marker now only advances after confirmed write — strictly safer than status quo.
Copy file name to clipboardExpand all lines: examples/HOOKS_TUTORIAL.md
+24-1Lines changed: 24 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,4 +25,27 @@ Add this to your configuration file to enable automatic background saving:
25
25
}
26
26
]
27
27
}
28
-
}
28
+
}
29
+
```
30
+
31
+
### 3. What changed (v3.1.0+)
32
+
33
+
Both hooks now have **two-layer capture**:
34
+
35
+
1.**Auto-mine**: Before blocking the AI, the hook runs the normalizer on the JSONL transcript and upserts chunks directly into the palace. This captures raw tool output (Bash results, search findings, build errors) that the AI would otherwise summarize away.
36
+
37
+
2.**Updated reason messages**: The block reason now explicitly tells the AI to save tool output verbatim — not just topics and decisions.
38
+
39
+
### 4. Backfill past conversations (one-time)
40
+
41
+
The hooks capture conversations going forward, but you probably have months of past sessions. Run this once to mine them all:
42
+
43
+
```bash
44
+
mempalace mine ~/.claude/projects/ --mode convos
45
+
```
46
+
47
+
### 5. Configuration
48
+
49
+
-**`SAVE_INTERVAL=15`** — How many human messages between saves
50
+
-**`MEMPALACE_PYTHON`** — Python interpreter with mempalace + chromadb. Auto-detects: env var → repo venv → system python3
51
+
-**`MEMPAL_DIR`** — Optional directory for auto-ingest via `mempalace mine`
Copy file name to clipboardExpand all lines: hooks/README.md
+40-14Lines changed: 40 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,10 @@ These hook scripts make MemPalace save automatically. No manual "save" commands
6
6
7
7
| Hook | When It Fires | What Happens |
8
8
|------|--------------|-------------|
9
-
|**Save Hook**| Every 15 human messages |Blocks the AI, tells it to save key topics/decisions/quotes to the palace|
10
-
|**PreCompact Hook**| Right before context compaction |Emergency save — forces the AI to save EVERYTHING before losing context |
9
+
|**Save Hook**| Every 15 human messages |Auto-mines transcript (tool output included), then blocks the AI to save topics/decisions/quotes |
10
+
|**PreCompact Hook**| Right before context compaction |Auto-mines transcript, then emergency save — forces the AI to save EVERYTHING before losing context |
11
11
12
-
The AI does the actual filing — it knows the conversation context, so it classifies memories into the right wings/halls/closets. The hooks just tell it WHEN to save.
12
+
**Two-layer capture:** Hooks auto-mine the JSONL transcript directly into the palace (capturing raw tool output — Bash results, search findings, build errors). They also block the AI with a reason message telling it to save verbatim tool output and key context. Belt and suspenders — tool output gets stored even if the AI summarizes instead of quoting.
13
13
14
14
## Install — Claude Code
15
15
@@ -68,6 +68,7 @@ Edit `mempal_save_hook.sh` to change:
68
68
-**`SAVE_INTERVAL=15`** — How many human messages between saves. Lower = more frequent saves, higher = less interruption.
69
69
-**`STATE_DIR`** — Where hook state is stored (defaults to `~/.mempalace/hook_state/`)
70
70
-**`MEMPAL_DIR`** — Optional. Set to a conversations directory to auto-run `mempalace mine <dir>` on each save trigger. Leave blank (default) to let the AI handle saving via the block reason message.
71
+
-**`MEMPALACE_PYTHON`** — Optional env var. Python interpreter with mempalace + chromadb installed. Auto-detects: `MEMPALACE_PYTHON` env var → repo `venv/bin/python3` → system `python3`. Set this if your venv is in a non-standard location.
71
72
72
73
### mempalace CLI
73
74
@@ -91,15 +92,19 @@ User sends message → AI responds → Claude Code fires Stop hook
91
92
↓
92
93
┌─── < 15 since last save ──→ echo "{}" (let AI stop)
93
94
│
94
-
└─── ≥ 15 since last save ──→ {"decision": "block", "reason": "save..."}
No counting needed — compaction always warrants a save.
128
+
No counting needed — compaction always warrants a save. The auto-mine captures raw tool output before the AI gets a chance to summarize it away.
120
129
121
130
## Debugging
122
131
@@ -150,6 +159,23 @@ Resolution priority: `$MEMPAL_PYTHON` (if set and executable) → `$(command -v
150
159
151
160
Note: the `mempalace mine` auto-ingest runs via the `mempalace` CLI, so that command also needs to be on the hook's `PATH`. Installing with `pipx install mempalace` or `uv tool install mempalace` puts it on a stable global location; otherwise extend the hook environment's `PATH` to include your venv's `bin/`.
152
161
162
+
## Backfill Past Conversations
163
+
164
+
The hooks only capture conversations going forward. To mine **past** Claude Code sessions into your palace, run a one-time backfill:
165
+
166
+
```bash
167
+
mempalace mine ~/.claude/projects/ --mode convos
168
+
```
169
+
170
+
This scans all JSONL transcripts from previous sessions and files them into the `conversations` wing. On a typical developer machine with months of history, this can yield 50K–200K drawers.
171
+
172
+
For Codex CLI sessions:
173
+
```bash
174
+
mempalace mine ~/.codex/sessions/ --mode convos
175
+
```
176
+
177
+
This only needs to be done once — after that, the hooks auto-mine each session as you go.
178
+
153
179
## Cost
154
180
155
181
**Zero extra tokens.** The hooks notify the AI that saves happened in the background — the AI doesn't need to write anything in the chat. All filing is handled automatically. Previous versions asked the AI to write diary entries and drawer content in the chat window, which cost ~$1/session in retransmitted tokens.
0 commit comments