Your agent should not rediscover the same codebase every session. BrainBox watches the work: files read and edited together, recurring tool chains, and the edits that turn a failing command into a passing one. On a later task, those traces help it suggest where to start.
The core is a Hebbian graph, not a hosted retrieval service. The v0.2 implementation adds local hybrid snippet search, structural code hints, recall attribution and a learned injection policy. No GPU or paid API is required; project memory stays on your machine. Optional embedding models are downloaded separately and run locally.
Source and installation guide · Paper (v0.2): doi:10.5281/zenodo.23250505 · npm package
The learning loop
Claude Code's PostToolUse hook records activity. Before the next prompt, UserPromptSubmit retrieves candidates and chooses whether to inject zero, one, three or five files. SessionEnd scores recall outcomes and compiles procedures. A contextual UCB1 policy balances useful suggestions against their token cost.
Ignored recalls weaken the specific edge that produced them. Deleted files are excluded from injection. The brainbox-explain MCP tool exposes recall provenance so a suggestion can be inspected rather than taken on trust.
Fire together, wire together
The graph records which files occur together, while directional learning distinguishes what tends to come next. Recall combines lexical matches, Hebbian evidence, snippet matches, frequency, recency, ACT-R base-level activation and recurrence through weighted reciprocal-rank fusion. Query matching remains important: a habitual file should not displace an explicit request for another topic.
Recall a file, find its neighbours
Tree-sitter import, call and inheritance edges provide weak structural hints for TypeScript/JavaScript, Python, Rust, Swift and Go. Learned co-access can outrank these priors. Code search uses syntax-aware chunks, SQLite FTS5 BM25 and sqlite-vec nearest-neighbour search, merged by rank fusion. Indexing is incremental by content hash.
The default code embedding model is jina-embeddings-v2-base-code. Until a model is cached, hooks fall back to lexical retrieval rather than downloading inside the hook. Set BRAINBOX_EMBEDDINGS=off for keyword-only operation.
Familiar routes become faster
Tool prediction uses the longest supported suffix of the recent tool sequence, up to three tools, rather than only the last tool. Consolidation replays episodic memory and compiles recurring patterns into procedures.
Remember the fix, not just the error
BrainBox mines failed command → edits → passing rerun sequences and repeated multi-session workflows. Helpful and harmful outcomes are tracked. Generic read/edit loops are not promoted as useful advice, and remembered content is presented as historical evidence rather than a command to execute.
What the evaluation shows
The offline harness replays real agent trajectories chronologically. Each task receives a fresh in-memory database trained only on earlier tasks from the same repository. Baselines include recency, frequency, BM25, EdgeBank and random ranking; paired 95% bootstrap confidence intervals are resampled by trajectory.
Ranking weights were fit on development repositories, not the test repositories. The reported test cohort contains 40 SWE tasks from Pillow and conan; the local cohort contains 97 sessions across five projects. These runs have embeddings disabled.
The clear win is next-tool prediction. Both cohorts beat their best simple baseline. Read-file retrieval improves over v0.1, but the result is not a universal win: local edited-file recall regresses and remains below frequency-only ranking. Next-file prediction is statistically tied with recency. These are retrieval measurements, not proof of higher task-completion rates or measured token savings.
A separate 30-query code-search check reports Recall@5 of 0.867 for Jina code embeddings versus 0.667 for MiniLM. That small check is not the trajectory replay benchmark and should not be read as a broad generalisation claim.
Install and use
Requires Node.js 22 or newer. The package's install script registers Claude Code hooks and MCP, creates the local database and starts an embedding-model download. See the repository for the current package release; the research changes described here are in the v0.2 source tree on main.
npm install brainbox-hebbian
Seed memory from a repository's history and structure, then inspect recall:
brainbox bootstrap --repo /path/to/project --imports
brainbox recall "authentication login"
brainbox stats
brainbox procedures list
For the v0.2 source checkout:
git clone https://github.com/thebasedcapital/brainbox.git
cd brainbox
npm install
npm run build
Existing databases with older MiniLM vectors need re-indexing for the new model:
brainbox embed
brainbox extract-snippets --force
Integrations: Claude Code hooks; an MCP server with eight tools (record, recall, explain, error, resolve, predict_next, stats, decay); a native Kilo/OpenCode plugin; and OpenClaw through NeuroVault. The system-wide macOS file watcher is opt-in, not part of the default installation. Integration and configuration instructions.
Research behind the implementation
- Ranking: ACT-R hybrid memory, Base3 and temporal-graph heuristics.
- Code chunks: cAST.
- Injection and attribution: MemCon, MemTrace and FastContext.
- Procedures: ACE and Memᵖ.
- Replay data: SWE-rebench OpenHands trajectories, plus local agent sessions.
BrainBox is MIT-licensed. Read the implementation and full results, the paper (v0.2): doi:10.5281/zenodo.23250505, or report an issue.
Cite this entry
@misc{tbc_brainbox,
title = {BrainBox: muscle memory for coding agents},
author = {{TBC Research}},
note = {F-002, catalogue version 2},
howpublished = {\url{https://tbcresearch.org/research/brainbox/}},
doi = {10.5281/zenodo.23250505}
}