# MemPalace Hooks — Auto-Save for Terminal AI Tools These hook scripts make MemPalace save automatically. No manual "save" commands needed. ## What They Do | Hook | When It Fires | What Happens | |------|--------------|-------------| | **Save Hook** | Every 15 human messages | Blocks the AI, tells it to save key topics/decisions/quotes to the palace | | **PreCompact Hook** | Right before context compaction | Emergency save — forces the AI to save EVERYTHING before losing context | 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. ## Install — Claude Code Add to `.claude/settings.local.json`: ```json { "hooks": { "Stop": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "/absolute/path/to/hooks/mempal_save_hook.sh", "timeout": 30 }] }], "PreCompact": [{ "hooks": [{ "type": "command", "command": "/absolute/path/to/hooks/mempal_precompact_hook.sh", "timeout": 30 }] }] } } ``` Make them executable: ```bash chmod +x hooks/mempal_save_hook.sh hooks/mempal_precompact_hook.sh ``` ## Install — Codex CLI (OpenAI) Add to `.codex/hooks.json`: ```json { "Stop": [{ "type": "command", "command": "/absolute/path/to/hooks/mempal_save_hook.sh", "timeout": 30 }], "PreCompact": [{ "type": "command", "command": "/absolute/path/to/hooks/mempal_precompact_hook.sh", "timeout": 30 }] } ``` ## Configuration Edit `mempal_save_hook.sh` to change: - **`SAVE_INTERVAL=15`** — How many human messages between saves. Lower = more frequent saves, higher = less interruption. - **`STATE_DIR`** — Where hook state is stored (defaults to `~/.mempalace/hook_state/`) - **`MEMPAL_DIR`** — Optional. Set to a conversations directory to auto-run `mempalace mine