code-review-graph is a persistent, incrementally-updated knowledge graph for token-efficient code reviews with Claude Code. It parses codebases using Tree-sitter, builds a structural graph in SQLite, and exposes it via MCP tools and prompts.
When using code-review-graph MCP tools, follow these rules:
- First call:
get_minimal_context(task="<description>")— costs ~100 tokens, gives you the full picture. - All subsequent calls: use
detail_level="minimal"unless you need more. - Prefer
query_graphwith a specific target over broadlist_*calls. - The
next_tool_suggestionsfield in every response tells you the optimal next step. - Target: ≤5 tool calls per task, ≤800 total tokens of graph context.
-
Core Package:
code_review_graph/(Python 3.10+)parser.py— Tree-sitter multi-language AST parser (19 languages including Vue SFC, Solidity, Dart, R, Perl, Lua + Jupyter/Databricks notebooks)graph.py— SQLite-backed graph store (nodes, edges, BFS impact analysis)tools.py— 22 MCP tool implementationsmain.py— FastMCP server entry point (stdio transport), registers 22 tools + 5 promptsincremental.py— Git-based change detection, file watchingembeddings.py— Optional vector embeddings (Local sentence-transformers, Google Gemini, MiniMax)visualization.py— D3.js interactive HTML graph generatorcli.py— CLI entry point (install, build, update, watch, status, visualize, serve, wiki, detect-changes, register, unregister, repos, eval)flows.py— Execution flow detection and criticality scoringcommunities.py— Community detection (Leiden algorithm or file-based grouping) and architecture overviewsearch.py— FTS5 hybrid search (keyword + vector)changes.py— Risk-scored change impact analysis (detect-changes)refactor.py— Rename preview, dead code detection, refactoring suggestionshints.py— Review hint generationprompts.py— 5 MCP prompt templates (review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check)wiki.py— Markdown wiki generation from community structureskills.py— Skill definitions for Claude Code pluginregistry.py— Multi-repo registry with connection poolmigrations.py— Database schema migrations (v1-v5)tsconfig_resolver.py— TypeScript path alias resolution
-
VS Code Extension:
code-review-graph-vscode/(TypeScript)- Separate subproject with its own
package.json,tsconfig.json - Reads from
.code-review-graph/graph.dbvia SQLite
- Separate subproject with its own
-
Database:
.code-review-graph/graph.db(SQLite, WAL mode)
# Development
uv run pytest tests/ --tb=short -q # Run tests (572 tests)
uv run ruff check code_review_graph/ # Lint
uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
# Build & test
uv run code-review-graph build # Full graph build
uv run code-review-graph update # Incremental update
uv run code-review-graph status # Show stats
uv run code-review-graph serve # Start MCP server
uv run code-review-graph wiki # Generate markdown wiki
uv run code-review-graph detect-changes # Risk-scored change analysis
uv run code-review-graph register <path> # Register repo in multi-repo registry
uv run code-review-graph repos # List registered repos
uv run code-review-graph eval # Run evaluation benchmarks- Line length: 100 chars (ruff)
- Python target: 3.10+
- SQL: Always use parameterized queries (
?placeholders), never f-string values - Error handling: Catch specific exceptions, log with
logger.warning/error - Thread safety:
threading.Lockfor shared caches,check_same_thread=Falsefor SQLite - Node names: Always sanitize via
_sanitize_name()before returning to MCP clients - File reads: Read bytes once, hash, then parse (TOCTOU-safe pattern)
- No
eval(),exec(),pickle, oryaml.unsafe_load() - No
shell=Truein subprocess calls _validate_repo_root()prevents path traversal via repo_root parameter_sanitize_name()strips control characters, caps at 256 chars (prompt injection defense)escH()in visualization escapes HTML entities including quotes and backticks- SRI hash on D3.js CDN script tag
- API keys only from environment variables, never hardcoded
tests/test_parser.py— Parser correctness, cross-file resolutiontests/test_graph.py— Graph CRUD, stats, impact radiustests/test_tools.py— MCP tool integration teststests/test_visualization.py— Export, HTML generation, C++ resolutiontests/test_incremental.py— Build, update, migration, git opstests/test_multilang.py— 19 language parsing tests (including Vue, Solidity, Dart, R, Perl, XS, Lua)tests/test_embeddings.py— Vector encode/decode, similarity, storetests/test_flows.py— Execution flow detection and criticalitytests/test_communities.py— Community detection, architecture overviewtests/test_changes.py— Risk-scored change analysistests/test_refactor.py— Rename preview, dead code, suggestionstests/test_search.py— FTS5 hybrid searchtests/test_hints.py— Review hint generationtests/test_prompts.py— MCP prompt template teststests/test_wiki.py— Wiki generationtests/test_skills.py— Skill definitionstests/test_registry.py— Multi-repo registrytests/test_migrations.py— Database migrationstests/test_eval.py— Evaluation frameworktests/test_tsconfig_resolver.py— TypeScript path resolutiontests/test_integration_v2.py— v2 pipeline integration testtests/fixtures/— Sample files for each supported language
- lint: ruff on Python 3.10
- type-check: mypy
- security: bandit scan
- test: pytest matrix (3.10, 3.11, 3.12, 3.13) with 50% coverage minimum