#!/bin/bash # MEMPALACE PRE-COMPACT HOOK — Emergency save before compaction # # Claude Code "PreCompact" hook. Fires RIGHT BEFORE the conversation # gets compressed to free up context window space. # # This is the safety net. When compaction happens, the AI loses detailed # context about what was discussed. This hook forces one final save of # EVERYTHING before that happens. # # Unlike the save hook (which triggers every N exchanges), this ALWAYS # blocks — because compaction is always worth saving before. # # === INSTALL === # Add to .claude/settings.local.json: # # "hooks": { # "PreCompact": [{ # "hooks": [{ # "type": "command", # "command": "/absolute/path/to/mempal_precompact_hook.sh", # "timeout": 30 # }] # }] # } # # For Codex CLI, add to .codex/hooks.json: # # "PreCompact": [{ # "type": "command", # "command": "/absolute/path/to/mempal_precompact_hook.sh", # "timeout": 30 # }] # # === HOW IT WORKS === # # Claude Code sends JSON on stdin with: # session_id — unique session identifier # # We always return decision: "block" with a reason telling the AI # to save everything. After the AI saves, compaction proceeds normally. # # === MEMPALACE CLI === # This repo uses: mempalace mine