The advisor confirms this post is essentially already clean. MemPalace is a third-party public open-source project credited by attribution ("their v4") — not the author's internal codename — so it stays. The code-block paths (obsidian-rag, apollo_rag.hooks.mine) are descriptive functional names, not private codenames, and are part of the technical story. No dollar/revenue figures are present. No people's names slip through. The post comes back unchanged:


TLDR: Two Claude Code hooks aren't enough — there are four ways a session can end, and only one of them is obvious. Wire all four or you'll keep losing sessions.

The Problem That Kept Biting Me

Apollo is my persistent AI assistant, (my name for the Claude Code agent I've built around my daily work).

The whole point is continuity — decisions, insights, design rationale all carry forward from session to session.

Except they weren't.

Two failure modes were quietly murdering that continuity:

  1. Compaction — Claude Code's context compression would silently summarize away mid-session detail I actually needed.
  2. The "good moment" problem — something sharp gets figured out, session ends, I forget to save it. Gone.

What I Shipped First (and Why It Wasn't Enough)

On May 8th I wired two hooks: Stop (fires when Claude finishes a turn) and PreCompact (fires right before compaction).

I thought: that's it, covered.

It wasn't.

Stop has blind spots I hadn't thought through:

  • It never sees subagent transcripts — those live in separate agent-*.jsonl (newline-delimited JSON log) files that Stop simply doesn't touch.
  • It never fires when you close the terminal, run /clear, /resume, or /exit. All of those sessions? Invisible.

So I kept losing exactly the sessions I most needed to save — the ones where I ran a subagent to do the heavy lifting, or the ones where I just closed the window at the end of the night.

The Fix: Enumerate Every Exit Path

Three days later I went back and wired the full set:

  • Stop — throttled, mines when current_human_msg_count - last_mined ≥ 5 (was 15 — dropped it when I realized I was skipping too many sessions)
  • SubagentStop — same throttle as Stop, catches those separate subagent transcripts that Stop never saw
  • SessionEndunconditional, mines every time, covers terminal close + /clear + /resume + /exit
  • PreCompactunconditional, mines right before any compaction so nothing gets summarized away mid-session

One Python entry point. All four hooks point at the same command:

cd obsidian-rag && uv run python -m apollo_rag.hooks.mine

Why Deterministic Python, Not AI

I was inspired by MemPalace (an open-source hook system on GitHub) — specifically their v4, which moved away from "block + AI saves" because of token cost and chat noise.

Apollo started clean with that lesson already learned.

The mining is pure Python — strips four noisy system tags (<system-reminder>, <command-message>, <command-name>, <local-command-stdout>), renders the JSONL to a local markdown log, exits 0 always.

No AI involved. No tokens burned. No noise in my chat.

Zero cost per session.

The Lesson That Transfers

When you're building any capture system — for sessions, meetings, Slack threads, whatever — enumerate every way the thing can end.

The obvious hook covers maybe half.

For Claude Code specifically: Stop misses subagents, misses terminal-close, misses /clear. PreCompact misses everything except compaction. You need all four, or you have gaps that silently eat exactly the sessions you'd want back.

One more thing worth knowing: kill -9 still won't fire. SIGHUP on terminal close might fire SessionEnd, but I haven't verified it in the logs yet. That's the honest edge case still living on my list.

P.S. These hooks fire globally — across every project, every client. That means locally-persisted transcripts include client-confidential work. I accepted that tradeoff with eyes open: files stay on local disk, never synced, never committed. If a session ever crosses a line I'm not comfortable with on disk, I can bump the threshold or disable temporarily. Worth thinking through before you adopt this pattern for sensitive work.