hindbrain
The reflex-and-memory layer beneath the model's cortex. hindbrain is a Claude Code plugin that gives the agent persistent, retrieval-gated memory via lifecycle hooks. On the read side, before and around operations a local SQLite store is searched and results surface in three tiers: inject (full note placed in context), remind (a one-line pointer plus a fetch verb), or deny (a hazard-flagged memory blocks a consequential command). On the write side nothing is auto-extracted: observers watch for signals (a failure followed by a fix, a correction, an explicit "remember this"), queue candidates, and the Stop hook nudges the agent with pre-drafted mem save commands — the agent authors every memory, the hooks only guarantee the ask.
An offline consolidator dedupes, promotes, expires, detects contradictions, and proposes graduations to CLAUDE.md (it never writes CLAUDE.md itself). Everything fails open: a broken memory system degrades to "Claude Code without memory," never to a broken session.
Requirements
- Python ≥ 3.11 (stdlib only — no third-party packages, ever, on the hot path).
- Linux or macOS. Windows is out of scope for v1 (
fcntl locking and POSIX paths; the import is guarded, so a future port degrades to lock-free, but v1 is untested there).
Install
Path 1 — plugin (preferred)
This repository hosts its own single-plugin marketplace (.claude-plugin/marketplace.json with source: "./"), so installation is two commands:
claude plugin marketplace add https://github.com/RobertCoop/hindbrain
claude plugin install hindbrain@hindbrain
(Or interactively: /plugin → browse the hindbrain marketplace.) The exact flow tracks the live plugin documentation (see the Substrate compatibility checklist, item V1). Once installed, hooks register from the plugin's hooks/hooks.json automatically and data lives under ${CLAUDE_PLUGIN_DATA}.
Path 2 — settings.json fallback (no plugin infrastructure)
Clone this repo anywhere (example below uses /home/you/hindbrain) and register the same hooks in ~/.claude/settings.json with absolute paths:
{
"hooks": {
"SessionStart": [
{ "matcher": "startup|resume|clear|compact|fork",
"hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/session_start.py"], "timeout": 10 } ] }
],
"UserPromptSubmit": [
{ "hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/prompt_gate.py"], "timeout": 5 } ] }
],
"PreToolUse": [
{ "matcher": "Edit|Write|MultiEdit|NotebookEdit",
"hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/pretool_gate.py"], "timeout": 5 } ] },
{ "matcher": "Bash",
"hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/pretool_gate.py"], "timeout": 5 } ] }
],
"PostToolUse": [
{ "matcher": "Bash|Edit|Write|MultiEdit|Task|WebFetch|WebSearch",
"hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/observer.py"], "async": true } ] }
],
"PostToolUseFailure": [
{ "matcher": "Bash|Edit|Write|MultiEdit|Task",
"hooks": [
{ "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/failure_gate.py"], "timeout": 5 },
{ "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/observer.py"], "async": true }
] }
],
"Stop": [
{ "hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/stop_gate.py"], "timeout": 10 } ] }
],
"PreCompact": [
{ "matcher": "auto|manual",
"hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/precompact_salvage.py"], "async": true } ] }
],
"SessionEnd": [
{ "hooks": [ { "type": "command", "command": "python3",
"args": ["/home/you/hindbrain/scripts/session_end.py"], "timeout": 2 } ] }
]
}
}
Add hindbrain/bin to PATH (or symlink bin/mem into a directory on it) so the agent can run the mem CLI. Nothing in the scripts assumes a plugin install — all paths resolve through lib/paths.py.
Data directory
Resolution order: $HINDBRAIN_DATA → $CLAUDE_PLUGIN_DATA (plugin install) → ~/.claude/hindbrain (settings install). Layout:
<data>/
├── hindbrain.db # SQLite store (WAL)
├── config.toml # your config; created from config.default.toml on first run
├── sessions/ # per-(session,agent) state JSON
├── drafts/ # overflow bodies
├── reports/ # consolidator reports (contradictions-, promotions-<date>.md)
├── logs/
│ ├── errors.log
│ └── metrics.jsonl
└── consolidator.lock