Code Project Brain
Provides AI agents with a governed, three-layer project memory (guide, code facts, and knowledge) through namespaced MCP tools for code search, context compilation, impact analysis, and proposal-driven documentation updates.
README
Code Project Brain (CPB)
A project-level second brain that grows in sync with a code repository. A Development Guide (first-class context) sits over CodeGraph (facts) and Project KB (digested knowledge), compiled into task-specific context for Claude Code — with a governed Change → Proposal loop that keeps knowledge correct without ever letting an AI silently rewrite it.
CPB implements the v3.0 design: the Development
Guide is the first citizen — the project mental model an Agent loads first.
A Context Compiler assembles a ContextPlan in the fixed order
Guide → KB → CodeGraph; a Concept hub links the three domains by
canonical_id; a Code Anchor layer keeps the Guide honest against the code.
Development Guide (context / first-class)
│ describes / governs (via Concept hub)
▼
CodeGraph (facts) · Project KB (digested knowledge)
└──────────────► Context Compiler ► Claude Code
Change → Impact → (Guide stale?) → Guide Proposal → Validate → Approve → Apply
New here? Read
docs/OVERVIEW.md— a single-entry tour of the architecture, implementation, design choices, and roadmap. v2.0 history lives inUpdateGuide2.0.md.
The three layers (v3.0, update3.0 §1)
The fixed load order is Guide → KB → CodeGraph, never the reverse (§3):
- Development Guide = Context — what the project is, why it's designed
this way, and the rules to follow. The mental model an Agent loads first.
Sits in
guide/as a skeleton00-overview → 06-decisions(§14). - CodeGraph = Facts — code parsed by tree-sitter into a SQLite graph of symbols and call/reference edges (WAL + FTS5). The Ground Truth Adapter that verifies the Guide's Code Anchors (§9). WHAT IS.
- Project KB = Knowledge — digested requirements / bugs / decisions (ADRs) / external sources / lessons. The detailed, historical layer reached only after the Guide. WHAT WAS LEARNED.
The Concept hub (§21/§22) links Guide sections, KB docs, and CodeGraph
symbols by canonical_id, so a code change can trace
symbol → concept → guide section and flag the Guide stale.
The governed loop (§11/§13/§24)
A code or KB change never silently edits the Guide. Instead:
Change → Impact → Concept impact → Guide stale? → Guide Proposal (draft)
→ Validate → Approve → Apply
The engine proposes; a human (or Claude, as reviewer) validates and
approves before apply. KB knowledge can be promoted into the Guide through
the same governed proposal (§13 Knowledge Promotion). cpb sync drafts
pending proposals; cpb proposals <id> --approve|… dispositions them.
What it does
- Development Guide — indexes
guide/Markdown (skeleton frontmatter + Code Anchors), verifies anchors against CodeGraph, flags stale ones. - CodeGraph — per-file incremental sync of symbols + edges.
- Project KB — indexes
project-kb/Markdown with typed frontmatter; digests intokb_digests; dedup/merge of duplicate digests (§13). - Context Compiler —
cpb context "<task>"→ aContextPlan(Guide → KB → Code, Progressive Disclosure Level 0-6, token-budgeted) (§18). - Impact Engine — blast radius + affected constraints/decisions and affected concepts / Guide sections (§22).
- Concept hub — canonical_id linking Guide / KB / CodeGraph (§21).
- Claude Code Skills — eight workflows:
/project-init,/project-context,/project-feature,/project-impact,/project-update-docs,/project-review,/project-knowledge,/project-sync.
Tech
Node/TypeScript, node:sqlite (built-in, WAL+FTS5, Node ≥ 22),
web-tree-sitter (WASM grammars for C/C++/TS/JS/Python/Rust/Go/Java). No
native builds, no vector DB (by design, §19). Engine v3.0.0 / protocol 2.
Quick start
# inside a code repository
cpb init # create .project-brain/ + guide/ + project-kb/
cpb index # build codegraph + knowledge + guide + concepts + git
cpb status # summary: engine/protocol/guide sections/stale anchors
cpb context FrameQueue # ContextPlan (Guide → KB → CodeGraph)
cpb concept camera/capture-pipeline # the Concept hub: 3-domain graph
cpb guide list # the Guide skeleton (Level 0)
cpb guide validate # Guide well-formedness (§17 validator)
cpb impact FrameQueue # blast radius + affected concepts/guide
cpb kb dedup # find duplicate KB digests (§13); --apply to merge
cpb sync # detect changes → draft Guide/Update proposals
cpb proposals # list / validate / approve / apply proposals
Self-host
CPB indexes its own source and the included guide/ + project-kb/:
git init && cpb init && cpb index && cpb status
MCP (the AI interface)
CPB exposes namespaced MCP tools — the sole AI interface:
code.*—code.searchcode.symbolcode.callerscode.calleescode.dependenciescode.impactdocs.*—docs.getdocs.searchdocs.relateddocs.constraintsdocs.validatedocs.applykb.*—kb.searchkb.requirementkb.bugkb.decisionkb.referencekb.ingestkb.promotekb.digestkb.promote-guidekb.dedupguide.*—guide.indexguide.sectionguide.staleguide.validateconcept.*—concept.graphconcept.forSymbolproject.*—project.contextproject.impactproject.changesproject.syncproject.proposalsproject.status
See USAGE.md for the install config and full tool reference.
As a Claude Code Plugin
CPB ships as a Claude Code plugin (cpb-claude-plugin/) that is the adapter
layer over the Engine. The Engine (this repo, cpb/cpb-mcp CLI) stays a
standalone runtime; the plugin binds via the MCP protocol, not an npm import —
so the Engine can evolve independently. See docs/plans/archi.md for the
rationale and cpb-claude-plugin/README.md for
full install steps.
# 1. Engine on PATH (once)
npm install -g @cpb/engine # or: npm link (from this repo)
# 2. In Claude Code
/plugin marketplace add /path/to/CPB
/plugin install cpb@cpb
Then /cpb:status, /cpb:context, /cpb:sync, … — or just describe the task
and the skills auto-activate.
The demo project
demo-src/camera/ is a small C++ camera pipeline (CameraDevice → FrameQueue → VideoEncoder) with a full v3.0 doc set — guide/
(overview + architecture + a constraint + an ADR) and project-kb/ (ADR,
requirement, bug, lesson, external V4L2/FFmpeg notes, test evidence). It is
dogfood: CPB indexes, explores, drift-checks, and runs the change→proposal
loop on it.
Layout
src/
core/ types (domain model: Guide/Concept/ContextPlan + structured objects)
db/ sqlite adapter + schema.sql + migrate.ts (versioned migrations)
engine/
codegraph/ tree-sitter extractor, grammars, parser, orchestrator, queries
guide/ Development Guide: indexer, anchor, query, validator (§17)
concept/ Concept hub: index + query (§21)
knowledge/ KB: frontmatter, indexer, recall, freshness, entities, external, ingestion, promotion, dedup
docs/ structured reads: constraints, decisions (Guide-seeded)
git/ commit index + ADR mining + gitDiff
impact/ blast radius + affected knowledge/concepts/guide (§22)
context/ Context Compiler (§18) + builder (v2, cpb explain) + explain/explore
sync/ semantic-diff, changeset, proposal, pipeline (change→proposal loop)
mcp/ namespaced MCP tools (code.*/docs.*/kb.*/guide.*/concept.*/project.*) + stdio server
bin/cpb.ts CLI
guide/ CPB's own Development Guide (self-hosted, v3.0 skeleton)
cpb-claude-plugin/ the Claude Code adapter (skills + commands + MCP declaration)
Design boundaries (per §19/§23/§25)
Not built: auto-rewriting all docs, auto-generating all knowledge, vector/ embedding search (§19 — local-first, SQLite+FTS5), a full IDE, or an enterprise knowledge graph. The engine never embeds an LLM (§29) — Claude thinks via MCP; the engine holds facts and the state machine. Knowledge stays human-controlled (§11/§14); the Guide is a governed asset — every edit goes through a Proposal. Code is the highest source of truth (§9).
License
MIT.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。