Claude Code memory hooks in settings.json

automatic recall across 7 lifecycle events without asking the model to call a tool

Passive MCP memory tools rely on Claude deciding to search before acting. Lifecycle hooks invert that: short local checks fire automatically in ~/.claude/settings.json when a session starts, a prompt submits, a tool edits a risky file, a command fails, compaction triggers, or the session ends.

Wire MCP and all 7 hooks in one command: deja-vu keeps your existing hooks intact in ~/.claude/settings.json and adds local FTS5 recall with zero background daemon.
$brew install deja-vu && deja install claude-auto
$npx @vshulcz/deja-vu install claude-auto
deja-vu on GitHubClaude Code setup →

The 7 hooks written to ~/.claude/settings.json

Hook eventMatcher / triggerWhat deja injects or updates
SessionStartNew or resumed sessionLoads project orient context and recent `.deja/memory.jsonl` entries (up to 2 KB)
UserPromptSubmitEvery user turnQueries local FTS5 across 52 harnesses for prior fixes and file rationale (capped at 1,536 bytes per prompt)
PreToolUseEdit/Write/Bash matchersSurfaces past blame decisions on the target file or known how invocations (about 4 KB per tool call)
PostToolUseBash command matchersChecks repeated friction loops across recent tool attempts
PostToolUseFailureFailed shell/tool executionLooks up past fix runs for the emitted error string immediately
PreCompactContext compaction triggerBuilds a 4 KB continuity packet of active goal, touched files, and tried fixes so compaction keeps decisions
SessionEndSession closeIncrementally indexes the finished session into ~/.deja/deja.db

Minimal settings.json layout

deja install claude-auto merges entries cleanly alongside existing user hooks; no other hooks are deleted. A single hook invocation runs as a short-lived Go binary process (107 ms on 19,195 indexed sessions):

{
  "hooks": {
    "SessionStart": [{"hooks": [{"type": "command", "command": "deja hook session-start"}]}],
    "UserPromptSubmit": [{"hooks": [{"type": "command", "command": "deja hook user-prompt-submit"}]}],
    "PreCompact": [{"hooks": [{"type": "command", "command": "deja hook pre-compact"}]}],
    "SessionEnd": [{"hooks": [{"type": "command", "command": "deja hook session-end"}]}]
  }
}

Prefer Claude Code's native plugin marketplace? Run claude plugin marketplace add vshulcz/deja-vu instead of modifying settings.json by hand.

Hooks vs passive MCP vs CLAUDE.md

deja install claude wires only the stdio MCP server (deja tool with 8 modes: recall, context, blame, fix, how, orient, remember, handoff). Combining it with hooks via claude-auto prevents cold-start mistakes when the model forgets to search, while staying well below unassisted token usage (52,815 vs 103,443 tokens measured on multi-step debugging tasks).

If an injected repository rule from .deja/memory.jsonl should stay out of automatic hooks, set {"activations":{"auto":{"repo":false}}} in your trust policy.

Found this useful? Star deja-vu on GitHub.