
Codebase Brain
io.github.Nomannazir由 GitHub 账号 Nomannazir 发布v0.2.1更新于 Nov 7, 2026
Cited, searchable memory of a codebase: hybrid search, git history, impact analysis, doc drift.
发布方自己的服务:BrainDog
概览
为本地或公开 git 代码库建立索引,让助手能检索代码、追溯 git 历史、分析改动影响并发现过期文档,结果均带路径与行号引用。
- 可以做什么
- 索引本地目录或公开 https git 地址,显示进度并支持增量重建索引
- 按精确名称或自然语言描述检索代码与文档,可按路径和分块类型过滤,并为问题返回带引用的来源
- 追溯函数或行范围的提交历史,含差异、作者与拉取请求标题,也可按提交信息搜索提交
- 列出函数或类的直接与间接调用方以及相关测试
- 检测与代码不再匹配的文档,并按严重程度排序
- 读取引用对应的具体代码行,并列出已索引的仓库
- 适用场景
- 适合助手面对无法通读的既有代码库、需要可核验答案的场景:代码为何如此、改动会破坏什么、文档是否仍然准确。对 Python、JavaScript 和 TypeScript 项目效果最好,其他语言按行窗口索引。
- 运行要求
- 通过 uvx 以 stdio 在本地运行(需安装 uv),无需账号或 API 密钥。索引与克隆存放在 CODEBASE_BRAIN_HOME(默认 ~/.codebase-brain)。可选 GITHUB_TOKEN 可提高 GitHub 拉取请求查询的速率上限。首次运行会下载本地嵌入模型;索引约需 1.2 GB 内存。
安装
在 SourceWeft 中
- 打开 控制台中的 Codebase Brain,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Codebase Brain MCP
[CI] [License: MIT] [Python 3.12+]
An MCP server that gives AI assistants a cited, searchable memory of a
codebase, including its history. Point it at a local folder or a public git URL. Claude, Cursor or any MCP client
can then answer questions about the code with exact path:start-end citations.
[Claude Code using Codebase Brain to explain the history, impact and docs of a function]
Claude Code asks why TimestampSigner.unsign looks the way it does, what breaks if it changes, and whether its
docs are current. Codebase Brain answers with commits, callers, tests and doc findings, all cited. (Waiting time
sped up.)
The problem
AI coding assistants are good at writing new code but struggle to understand code that already exists:
- They can't see the whole project. A real codebase has thousands of files. The assistant reads a few and guesses the rest, so it misses the function that matters or invents one that doesn't exist.
- You can't check their answers. "Expiry is handled in the auth module" is no use if you can't see where. Without file and line references, you have to trust the answer or re-read the code yourself.
- They don't know why code is the way it is. The code shows what it does. The reasons ("we added this check because it crashed on Windows") live in git history and pull requests, which assistants never read. So they "clean up" code that exists for a reason and bring old bugs back.
- They don't know what a change will break, or whether the documentation still matches the code.
- Many tools send your code to someone else's server to make it searchable.
What Codebase Brain gives you
A plug-in for any AI assistant that turns a codebase into something it can actually look things up in:
- Answers with proof. Every result points to the exact file and lines, and the assistant can open them.
- Search that understands code. It finds code whether you type the exact name (
calculate_invoice_total) or describe it in plain words ("how are invoices totalled?"). - The story behind the code. For any function, it shows every change made to it, who made it, why (from the commit message and pull request), and what the change was.
- What breaks if you change something. Everything that uses a function, directly or indirectly, and the tests that cover it.
- Out-of-date docs, found automatically. Documentation that mentions functions, files or settings that no longer exist, or shows examples that would no longer work.
- Private by design. Everything runs on your machine. No API keys, and your code never leaves your computer.
Why it's different (technical)
- Code-aware chunking. Python (with
ast) and JavaScript / TypeScript / JSX / TSX (with tree-sitter) are split by function, class, method, arrow function, interface, type and enum, with their doc comments. Markdown is split by heading. Each chunk knows its symbol (TimestampSigner.unsign,Ky.#retry) and exact lines, so citations point at real code. Other languages are indexed in overlapping line windows. - Hybrid retrieval. SQLite FTS5 BM25 (with
camelCase/snake_caseidentifier splitting) plus local embeddings, merged with reciprocal-rank fusion. Exact names and fuzzy questions both work. - Local and free. Embeddings run on your machine (
fastembed, ONNX). No API keys, and no code leaves your computer. - Incremental. Re-indexing only re-embeds files whose content changed. On a 42-file repo, a re-index with no changes takes about 2 seconds.
- History-aware.
explain_historyfollows a function's lines back through git (git log -L), shows who wrote the current lines, and links the pull requests behind each change. So agents can answer "why is it built this way?", not just "what does it do?". - Impact analysis.
impact_of_changelists everything that uses a function, directly and transitively, plus the tests that exercise it, before an agent changes anything. It works across Python, JavaScript and TypeScript files, and follows a constructor to the code that builds its class. - Doc-drift detection.
find_doc_driftchecks Markdown and reStructuredText docs against the code. It finds files, functions, settings and flags that don't exist; examples passing parameters a function doesn't take; imports that would fail; and sections last edited long before the code they describe changed. Each finding cites the doc section and suggests a fix ("Was it renamed tocheckout_total?"). - Agent-friendly output. Structured tool results, read-only tool annotations, progress notifications while indexing, and clear error messages the model can act on.
Tools
Also included: the resource brain://repos, and the prompt answer_with_citations.
Install
Codebase Brain runs on your own machine, so there's no server or account, and it's free. It works with any
MCP-compatible assistant. All you need is uv, and every client runs the same command:
uvx codebase-brain-mcp.
Claude Code
Cursor: ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project)
Claude Desktop: Settings → Developer → Edit Config (claude_desktop_config.json), then restart the app
VS Code (GitHub Copilot agent mode): .vscode/mcp.json
Windsurf: ~/.codeium/windsurf/mcp_config.json. Gemini CLI: ~/.gemini/settings.json. Both use the same
mcpServers block as Cursor.
OpenAI Codex CLI
Tool doesn't start? Desktop apps often don't see your shell's
PATH. Runwhich uvxand put that full path in"command", for example"/Users/you/.local/bin/uvx".
Optional: install the skill.
It tells the agent which tool fits which question, to cite every claim, to check history before removing odd code,
and to run impact analysis before editing. For Claude Code, run the commands below. Other agents that read
SKILL.md files take the same file in their own skills folder.
Quick start
Ask why it looks like that. explain_history(symbol="TimestampSigner.unsign") returns its line-by-line history:
Use a local checkout instead (for development)
Run it as a remote server (Streamable HTTP)
Clients connect to http://<host>:8765/mcp with Authorization: Bearer <token>. GET /healthz is open for load
balancers. Remote mode is locked down by default:
- No token, no public port. The server refuses to listen beyond localhost without a token of at least 24 characters. Tokens are compared in constant time.
- Remote clients can't read the server's disk. Only public
https://git URLs can be indexed, not local paths, unless you setCODEBASE_BRAIN_ALLOW_LOCAL_PATHS=1. - Big repos are refused above
CODEBASE_BRAIN_MAX_FILES(default 20,000), and every git command has a timeout. - DNS-rebinding protection is on for localhost, and for any hosts listed in
CODEBASE_BRAIN_ALLOWED_HOSTS.
Docker
The image runs as a non-root user and includes the embedding model, so it starts fast and needs no download at
runtime. It has a health check, and keeps indexes in the /data volume. Indexing uses about 1.2 GB of memory, so
give the container 2 GB.
Configuration
Doc drift, tested honestly
On a well-maintained project (itsdangerous), find_doc_drift reports no false alarms. It only reports three
"worth a look" sections whose docs date from 2020 while the code they describe changed in 2024–2025. On docs with
planted mistakes, it catches every one: a moved file, a renamed function (with the right suggestion), an unknown
setting and flag, a keyword argument the function doesn't take, and an import that would fail. Changelogs are skipped,
because they're supposed to mention removed things.
Evaluation
Does search actually put the right code in front of the model? codebase-brain eval answers that with a benchmark.
There are two, each with 32 questions pinned to one commit, and each question lists the code or docs a good answer
must come from. The questions were written by reading the code before any results were measured, and haven't been
changed since.
Python: pallets/itsdangerous
32 questions about pallets/itsdangerous at commit 672971d, in
evals/datasets/itsdangerous.toml.
What this shows:
- Hybrid finds a right answer in the top 3 for 88% of questions, against 75% and 72% for either method alone. The gain comes from questions written in plain words and questions about the docs. When the question names the code, every mode finds it.
- It's honest about uncertainty. With 32 questions, the confidence intervals for MRR overlap, so hybrid is better on this set but not yet proven in general. Per question, hybrid beats keyword-only on 8 questions and loses on 4.
- It has known misses. Four questions describing behaviour in very different words from the code don't reach
the top 5. They're listed in
evals/results/itsdangerous.mdand are the next thing to improve. A larger, held-out question set will come first, so any tuning isn't fitted to these 32.
TypeScript: sindresorhus/ky
32 questions about sindresorhus/ky at commit 3541888, in
evals/datasets/ky.toml.
The readme is one 2,000-line file, so docs questions must find the right section, not just the file.
What this shows:
- Naming the code or asking about the docs works well: 91–100% in the top 5.
- Describing behaviour in plain words is the weak spot (36%). ky has about 25,000 lines of tests next to
5,000 lines of source, and the tests describe the same behaviour in plain words, so they outrank the source.
Every miss is listed in
evals/results/ky.md. - Hybrid is not better than vector-only here. The intervals overlap heavily (hybrid beats vector on 5 questions and loses on 9), so neither is proven better. Keyword-only is clearly worst: hybrid beats it on 12 questions and loses on none.
- These results are published as measured. Tuning (for example, ranking source above tests) will be checked against a new held-out set, so it isn't fitted to these questions.
Reproduce either benchmark (the first run downloads the repo and the embedding model):
How it's measured:
- Hit@k: a relevant result is in the top k.
- MRR: 1 / rank of the first relevant result.
- nDCG@10: each target is credited once, so duplicate chunks don't inflate the score.
- Confidence intervals: 95% bootstrap over questions, seeded.
- Relevance: a result is relevant if it's in the target file and, when the target names a symbol, is that symbol
or one of its methods. A docs target can name a section (
FAQ > How do I stop retrying early?), and then that section or one of its subsections counts. - Dataset rot: the harness fails if a target no longer exists at the pinned commit.
How it works
Security
- Clones are blobless (
--filter=blob:none): full history, with file contents fetched only when needed. - Commit authors are shown by name only; email addresses are never stored or returned.
- Only
https://clone URLs are accepted. Git runs withGIT_ALLOW_PROTOCOL=https:fileand no terminal prompts. read_linesresolves paths and refuses anything outside the indexed repository.- Repo names are validated, so they can't escape the index directory.
- All query tools are marked read-only.
- In HTTP mode: a required bearer token (constant-time check), git URLs only, repo size limits, DNS-rebinding protection, and a non-root container.
Development
Roadmap
- Git history and PR discussions:
explain_history,search_history - Symbol references and transitive dependents:
impact_of_change -
find_doc_drift: Markdown and reStructuredText, signatures, imports, settings, flags, staleness - JavaScript and TypeScript (tree-sitter): chunking, references, impact analysis
- More languages (Go, Rust, Java) with tree-sitter
- Retrieval evals with confidence intervals (
codebase-brain eval) - Larger held-out eval set, then retrieval tuning (reranking, query expansion)
- Streamable HTTP with bearer-token auth, Docker image
- PyPI package, MCP Registry listing
- Hosted demo
- OpenTelemetry tracing
来源:README.md,提交 2e88839
工具
0版本历史
1- v0.2.1最新Nov 7, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
其他 Brain 集成

BrainDog
dog.brain官方发布者
BrainDog 是一个托管记录库,集中保存项目、决策与资金,接入的 AI 代理在开工前读取、结束后写入。

Personal Brain
由 GitHub 账号 zhang-liz 发布
为 AI 助手提供职业人脉记忆,数据以图的形式存放在 FalkorDB 中,可查询联系人、按话题找人并记录你见过的人。

Second Brain
由 GitHub 账号 ara-5 发布
面向AI智能体的共享Graph-RAG记忆:markdown vault、wikilink召回、任务、消息传递。AI 翻译

Make0 Brain
由 GitHub 账号 make0-official 发布
本地离线运行的 MCP 记忆服务器,让多个 AI 代理共享同一份带版本记录的事实与短笔记,可搜索、读取和更新。

Thinking Brain School — Teaching MCP
由 GitHub 账号 ariaxhan 发布
远程 MCP 端点,让 AI 助手围绕家庭已解锁的 Thinking Brain School 课程进行引导式练习。