█

AI/TLDR

Buy me a coffee
Buy me a coffee

Code-Graph-RAG

Parse a monorepo into a knowledge graph, then query and edit it in plain English

Code Indexing & SearchOpen source
Language
Python
License
MIT
IN SHORT

What is Code-Graph-RAG?

Code-Graph-RAG parses a multi-language codebase with Tree-sitter, builds a knowledge graph of its structure in Memgraph, and lets you query, edit and optimise that code in plain English. It sits in the Code Indexing & Search category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed MIT.

Overview

Code-Graph-RAG parses a multi-language codebase with Tree-sitter, builds a knowledge graph of its structure in Memgraph, and lets you query, edit and optimise that code in plain English. A monorepo of mixed languages ends up under one unified graph schema, so a question can cross language boundaries the way the code itself does.

Point the `cgr` CLI at a repository and it reads every source file, extracts functions, classes, methods and modules together with the relationships between them, and stores the result as an interconnected graph. Once the graph exists you can ask natural-language questions grounded in the real structure, retrieve the source of any symbol by name or by intent, find dead code by walking call and reference edges from entry points, and search or rewrite structurally by AST pattern with ast-grep.

It also edits. Changes go through AST-based surgical patching with a diff preview before anything is written, and the tool can optimise code against language best practices or your own coding standards. Beyond static structure, `cgr trace` overlays runtime behaviour — trace a test run, or pull production eBPF profiles — and merges the calls that actually happened into the graph, exposing dynamic dispatch that static analysis alone cannot see.

The project runs as an MCP server as well, so Claude Code and other MCP clients can query and edit your codebase through the same graph. Recent work added Neo4j as an alternative graph backend through a pluggable dialect seam, and a Gloss node for agent-authored notes that can be written and read over MCP.

What it does

  • Tree-sitter parsing of mixed-language monorepos into one unified Memgraph graph schema
  • Natural-language questions answered against the real call and reference structure, not text similarity
  • AST-based surgical editing with a diff preview before any file changes
  • Dead-code detection by walking call and reference edges out from entry points
  • Structural search and rewrite by AST pattern via ast-grep
  • `cgr trace` merges real runtime calls (test runs or production eBPF profiles) into the graph
  • MCP server so Claude Code and other MCP clients can query and edit through the graph
  • Pluggable graph backend — Memgraph or Neo4j

Getting started

`cgr` is published to PyPI. You need Python 3.12+, Docker (for Memgraph), cmake and ripgrep. Install with the treesitter-full extra for all languages and semantic for vector search.

Install the CLI

uv is the recommended installer; pipx works too. Both give you the newest PyPI release.

bashbash
# with uv (recommended)
uv tool install "code-graph-rag[treesitter-full,semantic]"

# or with pipx
pipx install "code-graph-rag[treesitter-full,semantic]"

Start the graph stack

This brings up the packaged Memgraph and Qdrant services — you do not need to write a compose file.

bashbash
cgr daemon up

Index a repository, then query it

The first command parses the repo into the graph; the second opens querying against it. Repeat the parse for each repository you want indexed — the graph is shared and syncing one project leaves the others alone.

bashbash
cgr start --repo-path /path/to/repo --update-graph
cgr start --repo-path /path/to/repo

Run ahead of the release cadence (optional)

PyPI publishes every 50th version plus security fixes, so the newest git tag usually runs ahead of the newest release. Install from git to track main.

bashbash
uv tool install "code-graph-rag[treesitter-full,semantic] @ git+https://github.com/vitali87/code-graph-rag@main"

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Answer 'who calls this and what breaks if I change it' across a monorepo that spans several languages
  • Give a coding agent structural context over your codebase through the MCP server instead of raw file dumps
  • Find genuinely unreachable code by walking the call graph from real entry points
  • Catch dynamic dispatch that static analysis misses by merging a traced test run into the graph
  • Apply a coding standard across a large codebase with AST patching and a diff preview per change

How Code-Graph-RAG compares

Code-Graph-RAG alongside other open-source code indexing & search tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
CodeGraph★ 79.3kBuilds a local SQLite knowledge graph of a codebase with a Rust tree-sitter kernel, keeps it in sync through a file watcher, and serves symbols, call paths and blast radius to coding agents over MCP.
codebase-memory-mcp★ 49.4kA native MCP server that indexes a repository into a persistent tree-sitter knowledge graph of functions, call chains and routes, queried by agents through 15 tools.
GitNexus★ 49kIndexes a codebase into a knowledge graph of dependencies, call chains and execution flows, then exposes it to Claude Code, Cursor and Codex through MCP tools.
code-review-graph★ 33kA local-first code intelligence graph built with Tree-sitter that serves precise, incrementally-updated structural context to AI coding tools over MCP, so they read only the code a task needs.
XERJ★ 22.9kSingle-binary, Elasticsearch-compatible search engine whose autoindex command turns any folder of code, docs, logs or PDFs into typed indices that AI coding agents query via CLI or MCP instead of grepping.
Claude Context★ 12.7kAn MCP server that indexes your codebase into a vector database so AI coding agents can find relevant code by meaning instead of loading whole folders.
Graft★ 11.6kBuilds a persistent knowledge graph of your codebase as linked markdown files, then feeds the matching nodes to coding agents so they stop re-exploring the repo on every task.
Code-Graph-RAG★ 5.5kParse a monorepo into a knowledge graph, then query and edit it in plain English