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.
~/.claude/settings.json and adds local FTS5 recall with zero background daemon.brew install deja-vu && deja install claude-autonpx @vshulcz/deja-vu install claude-autoThe 7 hooks written to ~/.claude/settings.json
| Hook event | Matcher / trigger | What deja injects or updates |
|---|---|---|
SessionStart | New or resumed session | Loads project orient context and recent `.deja/memory.jsonl` entries (up to 2 KB) |
UserPromptSubmit | Every user turn | Queries local FTS5 across 52 harnesses for prior fixes and file rationale (capped at 1,536 bytes per prompt) |
PreToolUse | Edit/Write/Bash matchers | Surfaces past blame decisions on the target file or known how invocations (about 4 KB per tool call) |
PostToolUse | Bash command matchers | Checks repeated friction loops across recent tool attempts |
PostToolUseFailure | Failed shell/tool execution | Looks up past fix runs for the emitted error string immediately |
PreCompact | Context compaction trigger | Builds a 4 KB continuity packet of active goal, touched files, and tried fixes so compaction keeps decisions |
SessionEnd | Session close | Incrementally 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.