repo-brain
Offline-first, persistent repository memory for coding agents. Provides MCP tools for repository scanning, searching, context, and impact analysis, helping agents navigate and edit code efficiently.
README
Repo Brain
Persistent repository memory for coding agents.
English · Português do Brasil · 简体中文
Repo Brain is an offline-first skill, CLI, SQLite memory and MCP server that helps a coding agent find the right place to work without rereading an entire repository at the start of every task.
Memory guides discovery. Current source code determines truth.
What the skill does
The repo-brain skill teaches an agent a repeatable, evidence-first workflow:
- Check the repository health and run an incremental scan.
- Search the memory for the task and rank likely files, symbols, tests and dependencies.
- Read the current source through an auditable
readoperation before editing. - Check stale analyses, direct dependents and architectural decisions.
- Create a persistent plan for a feature, refactor, migration, security change or multi-module bug.
- Make the change, run project tests and scan again.
- Refresh the analysis using the new source hash and finish the session.
The skill never grants permission to edit from an old summary. When a file hash changes, its analysis becomes stale; direct dependents can become needs_review. An agent must reread the current file before a critical change.
Directory-scoped memory and token economy
Memory is partitioned by normalized repository directory. Every indexed file belongs to its immediate directory, while each directory also carries subtree counts, a compact summary, responsibilities, entry points, risks and freshness state. A directory analysis never replaces source reading: it is a short routing layer that tells the agent where to look first.
Start with the directory map, then keep retrieval scoped:
repo-brain directories --json
repo-brain directory src/auth --json
repo-brain context "rotate password reset tokens" --directory src/auth --limit 8 --token-budget 2200 --json
repo-brain analyze-directory src/auth --json-file auth-directory.json
context returns groups separated by directory, directory summaries and states, an intentional read_order, stale warnings and estimated_tokens. The token budget is approximate and defaults to [ranking] token_budget in .repo-brain/config.toml (3,000 tokens). Prefer one directory per retrieval, a small limit and a budget appropriate to the task; this avoids sending unrelated summaries to the agent and makes the result a ready-to-use discovery handoff. Use the returned paths with repo-brain read, then verify the current hashes before editing.
The local UI keeps the same boundary: its sidebar and scope selector show one directory at a time (including descendants), while an all-directories search remains visibly grouped instead of mixing files into one list.
Requirements
- Python 3.11 or newer.
- SQLite 3 with WAL support (included with Python).
- Git is optional. Git repositories share a database between worktrees; non-Git projects store data under
.repo-brain/. - No API key, cloud account, external database, model or internet connection is required during normal use.
- FTS5 is used when available. A deterministic SQL/ranking fallback keeps search working when FTS5 is unavailable.
Install
From a published package:
python -m pip install repo-brain
From this repository while developing:
python -m pip install -e ".[dev]"
Then install the agent integrations in the project you want to remember:
cd /path/to/your-project
repo-brain install --all
repo-brain init
install --codex creates .agents/skills/repo-brain/SKILL.md and a managed block in AGENTS.md. install --claude creates the Claude skill and a managed block in CLAUDE.md. Existing user content is preserved. Use --dry-run to preview changes.
First run and database location
repo-brain init creates configuration, applies migrations, inventories files, calculates hashes, extracts static symbols and dependencies, fills the bootstrap queue and generates .repo-brain/INDEX.md.
To see the exact database path:
repo-brain db path
For a Git repository, the default is <git-common-dir>/repo-brain/brain.db, so worktrees use the same memory. For a non-Git project, it is .repo-brain/brain.db. The database and WAL sidecars should not be committed; .repo-brain/INDEX.md is a compact human dashboard and can be generated whenever needed.
Daily agent workflow
status → scan → context → read current code → plan (if needed)
→ edit → tests → scan → analysis refresh → index/session finish
Typical commands:
repo-brain status
repo-brain scan
repo-brain context "change password reset token expiration and email flow"
repo-brain read src/auth/password_reset.py
repo-brain impact src/auth/token.py --depth 3
repo-brain analyze src/auth/password_reset.py --json-file analysis.json
repo-brain scan
Use --json on status, context, search, coverage, reads, changes, graph, bootstrap and other commands when an agent or script consumes the result.
What is stored
SQLite stores repository identity, relative paths, normalized paths, file hashes, language/category, line counts, analysis states, directory partitions, directory analyses, symbols, dependency edges, modules, sessions, reads, changes, plans, decisions, observations and tags. Agent analyses are versioned in analysis_history; directory analyses are versioned in directory_analyses with a source fingerprint.
Repo Brain does not store full source files by default. Secret-looking files (.env, keys, certificates, credentials and similar patterns) are excluded from semantic analysis. Read and write hooks record paths, hashes, tools, sessions and timestamps—not raw write content.
Core commands
| Area | Commands |
|---|---|
| Setup | init, install, uninstall, migrate, doctor |
| Health | status, coverage, stale, index, db path, db check, db vacuum |
| Discovery | search, context, directories, directory, file, symbols, modules |
| Graph | deps FILE, dependents FILE, impact FILE --depth N |
| Audit | read FILE, reads, changes, history |
| Agent memory | session, analyze, analyze-directory, plan, decision |
| Bootstrap | bootstrap status, claim, complete, fail |
| Portability | export, import |
| Integrations | mcp serve, ui, integrate codex, integrate claude |
Run repo-brain COMMAND --help for the exact arguments.
Bootstrap mode
Large projects can be analyzed cooperatively:
repo-brain bootstrap claim --limit 10
repo-brain read path/to/file.py --purpose bootstrap
repo-brain analyze path/to/file.py --json-file analysis.json
repo-brain bootstrap complete path/to/file.py
Claims have leases, so two agents do not receive the same active item. A failed worker can leave an item to be reclaimed after the lease expires.
Analyses and evidence
An agent can persist a concise factual analysis such as:
{
"summary": "Creates and rotates password-reset tokens.",
"responsibilities": ["validate expiry", "prevent replay"],
"security_notes": ["invalidate the previous token after rotation"],
"risks": ["replay if rotation is not atomic"],
"tags": ["auth", "security"],
"confidence": 0.9
}
Important observations should include the file, source hash, line range and confidence. Do not store private model reasoning or secrets.
MCP server
Start the local stdio server:
repo-brain mcp serve
It exposes tools for status, scan, context, search, file reads, symbols, dependencies, impact, sessions, analysis, plans, decisions, bootstrap and index refresh. brain_read_file validates the path, reads a line range, records the read and returns the current hash and analysis state.
Configure an MCP host to run repo-brain with arguments mcp serve. The repository also includes a Claude plugin manifest and .mcp.json template.
Local interface
The dependency-free local dashboard is served by the same application layer:
repo-brain ui --host 127.0.0.1 --port 8765
Open http://127.0.0.1:8765. It shows file counts, semantic coverage, fresh/stale state and contextual search results. The server is local-only unless you deliberately bind it to another interface.
Codex and Claude Code
The canonical skill is skills/repo-brain/SKILL.md. The Claude distributable plugin is under integrations/claude-plugin/; it contains a skill, hook configuration, safe hook script and MCP configuration. Hooks are best-effort: a Repo Brain failure must never block the user's edit.
Configuration
repo-brain init creates .repo-brain/config.toml. Configure include/exclude patterns, maximum file size, allowed/ignored extensions, secret patterns, ranking limits and bootstrap lease duration. Keep the database, WAL sidecars and local logs out of version control.
Export and import
repo-brain export
repo-brain import .repo-brain/export/snapshot.jsonl
Snapshots contain sanitized metadata, hashes, analyses, relationships and decisions—not full source. Imported facts are tied to their original hashes and must be treated as stale when the current source differs.
Security and privacy
- Offline-first and no telemetry.
- Canonical path validation prevents traversal and repository-root escapes.
- Parameterized SQL prevents query injection.
- Secret, binary and oversized files are not loaded for semantic analysis.
- WAL, foreign keys, busy timeouts and short transactions support concurrent agents.
- Current source always outranks memory.
Read docs/SECURITY_MODEL.md for the threat model.
Demo and development
The acceptance example is in examples/demo-project/. Try:
repo-brain --root examples/demo-project init
repo-brain --root examples/demo-project context "change password reset token expiration and update its email flow"
Run the test and build checks:
python -m pip install -e ".[dev]"
python -m pytest
python -m ruff check src tests
python -m build
More detail is available in docs/ARCHITECTURE.md, docs/DATABASE.md, docs/MCP.md, docs/CODEX.md, docs/CLAUDE.md and docs/TROUBLESHOOTING.md.
License
Apache License 2.0. See LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。