io.github.thebasedcapital/brainbox

编码与调试

by thebasedcapital

为 AI agents 提供 Hebbian memory,学习文件模式、预测下一步工具选择,并通过记忆复用节省 tokens。

什么是 io.github.thebasedcapital/brainbox

为 AI agents 提供 Hebbian memory,学习文件模式、预测下一步工具选择,并通过记忆复用节省 tokens。

README

BrainBox

<p align="center"> <img src="assets/brainbox-hero.png" alt="BrainBox — AI with muscle memory" width="800" /> </p> <p align="center"> <a href="https://www.npmjs.com/package/brainbox-hebbian"><img src="https://img.shields.io/npm/v/brainbox-hebbian.svg" alt="npm version" /></a> <a href="https://github.com/thebasedcapital/brainbox/stargazers"><img src="https://img.shields.io/github/stars/thebasedcapital/brainbox?style=social" alt="GitHub stars" /></a> <a href="https://github.com/thebasedcapital/brainbox/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" /></a> </p>

Hebbian memory for AI coding agents. Learns which files you access together, which errors lead to which fixes, and which tool chains you use most — then recalls them instantly.

Not a vector database. Not RAG. Procedural memory.

If BrainBox saved you tokens, give it a star — it helps others find it. Built by @thebasedcapital

code
Session 1:  agent greps for auth.ts, reads it, edits it (2000 tokens)
Session 5:  agent recalls auth.ts directly, skips search (500 tokens saved)
Session 20: auth.ts is a superhighway — instant recall, zero search cost

Install

bash
npm install brainbox-hebbian

That's it. The postinstall script automatically:

  1. Adds PostToolUse hook to ~/.claude/settings.json (learns from every file read/edit/search)
  2. Adds UserPromptSubmit hook (injects neural recall into prompts automatically)
  3. Registers the MCP server via claude mcp add (6 tools for manual recall/recording)
  4. Creates ~/.brainbox/ database directory

BrainBox learns passively from your next Claude Code session. No configuration needed.

What does NOT happen automatically

The macOS daemon (system-wide FSEvents file watcher) is completely separate and opt-in:

bash
# Only if you want BrainBox to learn from VS Code, Xcode, vim, shell, etc.
brainbox daemon install   # installs LaunchAgent, starts watching
brainbox daemon status    # check if running
brainbox daemon uninstall # remove completely

The daemon watches file changes across all your editors — not just Claude Code. It requires explicit opt-in because it registers a LaunchAgent and monitors your configured project directories.

Uninstall

bash
brainbox uninstall  # removes hooks + MCP server, preserves database

Seed from git history (recommended)

Kill cold start by bootstrapping from your existing git history:

bash
brainbox bootstrap --repo /path/to/project --imports

This seeds the neural network from git commit co-changes and import graphs so BrainBox starts with knowledge instead of from zero.

How It Works

BrainBox implements neuroscience-inspired learning:

  • Neurons — files, tools, and errors you interact with
  • Synapses — connections formed when things are accessed together ("neurons that fire together wire together")
  • Myelination — frequently-used paths get faster (like muscle memory)
  • Spreading activation — recalling one file activates related files
  • Decay — unused connections weaken naturally, keeping the network clean
<details> <summary><strong>Hebbian Learning in Action</strong> (click to play)</summary>

https://github.com/thebasedcapital/brainbox/raw/main/assets/brainbox-animation.mp4

</details> <details> <summary><strong>Spreading Activation</strong> — recalling one file activates related files through synaptic connections</summary>

https://github.com/thebasedcapital/brainbox/raw/main/assets/brainbox-spreading.mp4

</details> <details> <summary><strong>Superhighway Formation</strong> — frequently-used pathways become instant-recall superhighways</summary>

https://github.com/thebasedcapital/brainbox/raw/main/assets/brainbox-superhighway.mp4

</details> <details> <summary><strong>Error-Fix Immune System</strong> — remembers which files fixed which errors</summary>

https://github.com/thebasedcapital/brainbox/raw/main/assets/brainbox-immune.mp4

</details>

Other Integrations

MCP Server (any agent)

If you're not using Claude Code, you can run the MCP server standalone:

bash
# 6 tools: record, recall, error, predict_next, stats, decay
npx tsx node_modules/brainbox-hebbian/src/mcp.ts

Kilo / OpenCode (native plugin)

Add to ~/.config/kilo/config.json:

json
{
  "plugin": ["node_modules/brainbox-hebbian/src/kilo-plugin.ts"]
}

OpenClaw (NeuroVault)

BrainBox can be deployed as an OpenClaw memory slot plugin. See NeuroVault for the reference implementation.

AspectClaude CodeOpenClaw
Tool namesPascalCase (Read)Lowercase (read)
Context injectionUserPromptSubmit hookbefore_agent_start lifecycle
Learning triggerPostToolUse hookafter_tool_call lifecycle
Embeddingsall-MiniLM-L6-v2Keyword-only (lower confidence gate)

CLI

bash
brainbox recall "authentication login"
brainbox record src/auth.ts --context "authentication"
brainbox stats
brainbox error "TypeError: cannot read 'token'"
brainbox predict Read
brainbox embed          # add vector embeddings for semantic recall
brainbox hubs           # most connected neurons
brainbox stale          # decaying superhighways
brainbox projects       # list project tags
brainbox sessions       # recent sessions with intents
brainbox streaks        # anti-recall ignore streaks
brainbox graph          # ASCII neural network
brainbox highways       # show superhighways
brainbox decay          # weaken unused connections

Key Features

Hebbian Learning

Files accessed together form synapses. Access auth.ts then session.ts 10 times and BrainBox learns they're related — recalling one activates the other.

Error-Fix Immune System

When you fix a bug, BrainBox remembers which files fixed which errors. Next time a similar error appears, it suggests the fix files immediately.

Tool Sequence Prediction

After 20 Grep-Read-Edit chains, BrainBox predicts you'll Read after Grep and pre-loads likely files.

SNAP Plasticity

Strong synapses resist further strengthening (like real neural synapses). Prevents any single connection from dominating the network.

Anti-Recall Escalation

Files recalled but never opened get progressively stronger decay. Consecutive ignores escalate: 1st = 10%, 2nd = 19%, 3rd = 27%. Opening the file resets the streak.

Hub Detection & Staleness Alerts

Identify the most-connected neurons in your network and detect decaying superhighways before they fade.

Project Tagging

Auto-tag file neurons by project. Recall scoped to current project reduces cross-project noise.

Architecture

code
src/
  hebbian.ts     # Core engine: record, recall, decay, SNAP, BCM, spreading activation
  db.ts          # SQLite schema: neurons, synapses, access_log, sessions
  embeddings.ts  # Optional vector embeddings (all-MiniLM-L6-v2, 384 dims)
  installer.ts   # Auto-installer: adds hooks + MCP to ~/.claude/settings.json
  mcp.ts         # MCP server (6 tools)
  hook.ts        # Claude Code PostToolUse hook
  prompt-hook.ts # Claude Code UserPromptSubmit hook
  kilo-plugin.ts # Kilo/OpenCode native plugin
  bootstrap.ts   # Git/vault/import seeder
  daemon.ts      # FSEvents file watcher (macOS, opt-in)
  cli.ts         # CLI interface
  test.ts        # 59 tests, all passing

Algorithm Details

ComponentMechanism
Synapse formationSequential window (25 items), positional decay
StrengtheningSNAP sigmoid plasticity (midpoint 0.5, steepness 8)
MyelinationBCM sliding threshold + diminishing returns, 0.95 ceiling
ConfidenceMultiplicative: contextScore * (1 + myelin + recency + path)
Spreading2-hop BFS, fan-out cap 10, fan effect 1/sqrt(degree)
DecayActivation -15%, synapses -2%, myelination -0.5% per cycle
Error learning2x boosted learning rate for error neurons
Anti-recallCompound decay: 1 - (1 - 0.1)^streak, floor at 0.1

Full details in WHITEPAPER.md.

Tests

bash
npm test  # 59 tests, ~2s

Requirements

  • Node.js 18+
  • macOS or Linux (FSEvents daemon is macOS-only, everything else is cross-platform)

License

MIT

常见问题

io.github.thebasedcapital/brainbox 是什么?

为 AI agents 提供 Hebbian memory,学习文件模式、预测下一步工具选择,并通过记忆复用节省 tokens。

相关 Skills

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描164.6k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描164.6k

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描164.6k

相关 MCP Server

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
88.1k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
58.6k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
49.4k

评论