Lifecycle hooks
Hooks inject retrieved memories at session and prompt events. Individual scripts in hooks/ handle each lifecycle event, configured via hooks.json (plugin) or ~/.claude/settings.json (standalone).
Status as of 2026-09-20 Canonical hook contract and measurements.
Event Types
9 events ▾- Realm detection from environment, the realm marker, or git repo; linked worktrees use the main checkout's realm. The marker keeps its pre-rename spelling; see migration notes.
- Incremental codebase re-indexing (only changed files)
- Transcript registration for distillation tracking
- Soul context + user profile injection into system prompt
- Active goals and behavioral corrections loaded
- Ledger checkpoint restored for session continuity
- Git diff awareness — surfaces recent changes
- Daemon start if not already running
- Realm-scoped recall across six parallel lanes — semantic, thread context, hybrid, keyword, corrections, and a cross-realm fallback
- Admission filter: confidence floors, deduplication against what this session already saw, and a calibrated confidence band that silences low-signal lanes. See Recall
- Learning opportunity detection (corrections, preferences, frustration, milestones)
- Code symbol injection for files referenced in the prompt
anticipation_predict— predict likely actions from context patterns- Runs to a wall-clock budget (
CHITTA_HOOK_BUDGET_MS, 6000 ms). Optional enrichment is skipped once it is spent; memory injection and the correction lanes never are
- Auto-learning: extract
[SOLUTION],[GOTCHA],[PREFERENCE],[DECISION],[FAILURE],[PATTERN]markers - Correction and preference detection from response text
- Milestone detection from response content
anticipation_observe— record context→action pattern- Auto-checkpoint every 5 turns
- Ledger save with mood, active files, decisions, and next steps
- Save ledger checkpoint to preserve work state before context window shrinks
- Surface relevant file memories for the file being read or edited
- Past decisions and gotchas associated with the target file; the first Read per session can add
[traces]from memories naming that file (CHITTA_FILE_TRACES=0disables). - Command corrections for Bash — warn about known failure patterns
- Log the command that ran, and append its outcome to the outcome ledger
artifact-trace.shrecords newly written scripts as[artifact] path sha:… purpose:…signals for later reuse.
- Session teardown, final ledger write, and a
session_endoutcome-ledger event
- Capture what the subagent learned, asynchronously
- Re-index the changed file, asynchronously
Hook Configuration
plugin & settings ▾hooks.json to wire lifecycle events to individual scripts in hooks/. Activated when running as a Claude Code plugin via claude --plugin-dir or the plugins list.
hooks.json file defines event matchers that dispatch to dedicated scripts: session-start-hook.sh, prompt-hook.sh, stop-hook.sh, etc.
~/.claude/settings.json to wire lifecycle events to the same individual scripts in hooks/. Installed by smart-install.sh.
session-start-hook.sh, prompt-hook.sh, stop-hook.sh, pre-compact-hook.sh, pre-tool-hook.sh, post-bash-hook.sh.
Two roots, on purpose. Inside hooks.json, lifecycle handlers resolve against ${CLAUDE_PLUGIN_ROOT} — the plugin cache — while the PreToolUse matchers and most PostToolUse matchers resolve against ${HOME}/.claude/hooks. A source checkout is neither. That is why editing a checkout changes nothing until you install, and why scripts/dev-install.sh symlinks both live paths back at your checkout. A plugin update can replace those symlinks with a fresh clone, so re-run it afterwards.
Proactive Learning
4 detectors ▾Hooks automatically detect patterns in Claude’s responses and user messages, storing learnings without explicit commands.
learn_correction to store the mistake and the correct approach as a high-confidence counter-memory.
"actually" "that's wrong" "I was mistaken"learn_preference to store as a global preference visible across all projects.
"I prefer" "don't do X" "always Y"learn_milestone to record the achievement as a relationship marker.
"shipped" "released" "finished"learn_approach to improve future interactions.
"no" "stop" "wrong"Anticipation
predict → observe → strengthen ▾The hook system records context→action patterns and surfaces matching predictions on subsequent prompts.
anticipation_predict checks if the current context matches known patterns. If a match is found, the predicted action is surfaced in the system prompt alongside recalled memories.
anticipation_observe records what action was taken in response to context. This builds the pattern database that predictions draw from.
anticipation_success. Patterns that consistently predict correctly become stronger over time.
Key Scripts
11 scripts ▾chittad background process.Socket Communication
daemon protocol ▾/tmp/chitta-{hash}.sock where {hash} is the djb2 hash of the mind database path. Each mind gets a unique socket.
chitta thin client if the socket is unavailable.
/tmp/chitta-{hash}.pid for daemon management. Used by subconscious.sh for start, stop, restart, and health check operations.
Installation
settings.json ▾The smart-install.sh script writes the following hook configuration into ~/.claude/settings.json, wiring each lifecycle event to its dedicated entry-point script.
{ "hooks": { "SessionStart": [{ "type": "command", "command": "~/.claude/hooks/session-start-hook.sh" }], "UserPromptSubmit": [{ "type": "command", "command": "~/.claude/hooks/prompt-hook.sh" }], "Stop": [{ "type": "command", "command": "~/.claude/hooks/stop-hook.sh" }], "PreCompact": [{ "type": "command", "command": "~/.claude/hooks/pre-compact-hook.sh" }], "PreToolUse": [{ "type": "command", "command": "~/.claude/hooks/pre-tool-hook.sh", "timeout": 10 }], "PostToolUse": [{ "type": "command", "command": "~/.claude/hooks/post-bash-hook.sh" }] } }
Native lifecycle and daemon ledger
Since September 15, ordinary prompt, SessionStart and Stop paths use bash/jq and native chitta calls for query cleanup, RPC parsing, registration, heartbeats and task cards. Explicit RLM71 or opt-in background features can still use Python. Measured prompt median fell from 822 to 635 ms and SessionStart from 693 to 599 ms on the loaded test node; these are measurements, not fixed budgets.
ledger_op owns task threads, inbox, artifacts, bindings and leases in the daemon WAL and snapshots. Hooks call session_register, session_heartbeat and ledger_op directly. Python registry and ledger modules remain compatibility clients. Failed heartbeats are queued in the private mind's queue.jsonl.
CHITTA_SOCKET_PATH selects the daemon. The default socket is derived from the mind path and runtime directory. Test runs must isolate HOME, runtime, mind, queue and socket together. See HOOKS.md for routing, enforcement, environment variables and full latency evidence.
References
- Alex L. Zhang, Tim Kraska, and Omar Khattab. Recursive Language Models. arXiv:2512.24601 (2025; revised 2026). https://arxiv.org/abs/2512.24601