Skip to content
Dev Tools·9 min read·

Code-Graph-RAG: Query Your Entire Monorepo in Plain English With AI and Knowledge Graphs (2026 Guide)

Code-Graph-RAG is a free, open source tool that parses multi-language codebases with Tree-sitter, builds a knowledge graph in Memgraph, and lets you query, edit, and optimize code in natural language. MCP server included.

By Abdul Rauf Azhar

Understanding a large codebase is hard. You grep for function names, trace call chains manually, read files you do not need to read, and still miss important connections. When you ask an AI agent to help, it either hallucinates relationships that do not exist or reads every file in the repo, burning through your token budget. For monorepos with multiple languages (Python, TypeScript, Go, Rust, Java), there is no unified way to query the codebase structure.

Code-Graph-RAG, developed by Vitali Avagyan, is a free, open source tool that parses a multi-language codebase with Tree-sitter, builds a knowledge graph of its structure in Memgraph, and lets you query, edit, and optimize that code in plain English. It works across a monorepo of mixed languages under one unified graph schema. Includes an MCP server so Claude Code and other MCP clients can query and edit your codebase directly. 2,900+ stars on GitHub.

In this guide, you'll learn what Code-Graph-RAG is, how it works, and how to set it up for your monorepo.

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 optimize that code in plain English. It works across a monorepo of mixed languages under one unified graph schema.

The system has two components:

  1. Multi-language parser: A Tree-sitter based parser reads the codebase and ingests functions, classes, methods, modules, and their relationships into Memgraph under a single language-agnostic schema.

  2. RAG system: An interactive CLI that turns natural language into Cypher queries, retrieves matching code, and drives AI-powered editing and optimization.

Once the graph exists, you can ask questions about the codebase in natural language and get answers grounded in the real structure. You can retrieve the actual source of any function, class, or method by name or by intent. You can edit code through the agent with AST-based surgical patching and a diff preview before anything changes. You can find dead code by walking call and reference edges from entry points. You can search and rewrite structurally by AST pattern with ast-grep.

Who is it for?

  • Developers working in large monorepos: If your codebase has thousands of files across multiple languages and you spend more time navigating than coding, Code-Graph-RAG gives you a natural language interface to the entire structure.
  • AI agent power users: If you use Claude Code or other MCP clients and want them to understand your codebase structure (not just read individual files), the MCP server lets agents query the graph directly.
  • Teams doing code cleanup: Find dead code by walking call and reference edges from entry points. Optimize code against language best practices or your own coding standards.
  • New team members onboarding: Instead of reading hundreds of files to understand the architecture, new developers can ask questions in plain English and get answers grounded in the actual code structure.

What makes Code-Graph-RAG different from grep or standard RAG?

  • Knowledge graph, not text search: grep finds text matches. Code-Graph-RAG understands relationships. It knows that function A calls function B, that class C extends class D, that module E imports module F. You can ask "what calls the authentication function?" and get the actual call chain, not just files that mention "authentication."
  • Multi-language under one schema: Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, and Dart are fully supported. Ruby has structural support through ast-grep. All languages are stored in the same graph with the same schema, so you can query cross-language relationships.
  • AST-based surgical patching: When the agent edits code, it uses AST-based patching with a diff preview before anything changes. This is not a string replacement. It is a structural edit that preserves the code's syntax tree.
  • Data-flow tracing: New FLOWS_TO taint edges follow values through assignments, function calls, and I/O sinks, with coverage across C#, Java, C, and Go. You can trace how data flows through your codebase.
  • Structural search and replace: Find and rewrite code by AST pattern with ast-grep, exposed as agent tools. Match and transform structure across the whole codebase instead of relying on text or regex.
  • Real-time updates: The graph updates in real-time as you edit code. A watch mode keeps the graph in sync with file changes, serialized behind one transaction lock.
  • MCP server: Runs as an MCP server so Claude Code and other MCP clients can query and edit your codebase directly. Your AI agent has direct access to the knowledge graph.
  • Free and open source: MIT license. 2,900+ stars, 45 contributors. Enterprise support available for cloud-hosted and on-premise deployments.

What you need before you start

  • Docker: Required for Memgraph (the graph database) and Qdrant (vector search).
  • Python 3.10+: For the Code-Graph-RAG CLI and parser.
  • cmake and ripgrep: Build dependencies for Tree-sitter grammars and fast file search.
  • An LLM: For the natural language to Cypher query generation. Any OpenAI-compatible endpoint works, including local models via Ollama.
  • An MCP client (optional): Claude Code, Cursor, or any MCP-compatible client for direct agent integration.

Step-by-step installation

Step 1: Install Code-Graph-RAG

Install via uv (recommended) or pipx:

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

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

The treesitter-full extra installs all language parsers. The semantic extra installs vector search support.

Step 2: Start the graph database

# Start the packaged Memgraph + Qdrant stack (no compose file needed)
cgr daemon up

Step 3: Parse your repository into the graph

# Parse a repository into the graph
cgr start --repo-path /path/to/your/repo --update-graph

Repeat this command for each repository you want indexed. The graph is shared, and syncing one project leaves the others alone.

Step 4: Query your codebase in natural language

cgr query

This opens an interactive session where you can ask questions like:

  • "What functions call the authentication middleware?"
  • "Find all dead code that is never called from any entry point"
  • "Show me the call chain from the API endpoint to the database query"

Step 5: Connect Claude Code via MCP

Add Code-Graph-RAG as an MCP server in your Claude Code configuration:

{
  "mcpServers": {
    "code-graph-rag": {
      "command": "cgr",
      "args": ["mcp", "serve"]
    }
  }
}

Your AI agent can now query the knowledge graph directly, retrieve code by name or intent, and make AST-based surgical edits with diff previews.

Common errors and how to fix them

Error What it means How to fix it
Memgraph connection failed The Memgraph Docker container is not running or the port is occupied. Run cgr daemon up to start the graph database. Check Docker is running with docker ps.
Language not supported You are trying to parse a language that Code-Graph-RAG does not support yet. Check the language support matrix. 12 languages are fully supported. Ruby has structural support via ast-grep. You can add new languages through the pluggable ast-grep tier.
Graph is empty after parsing The parser did not find any source files, or the ignore patterns excluded everything. Check your ignore patterns. Ensure the repo path is correct. Run cgr start with --verbose to see what files were parsed.
Cypher query generation fails The LLM could not generate a valid Cypher query from your natural language input. Rephrase your question more specifically. Ensure your LLM endpoint is working. Try simpler queries first to verify the graph has data.

Code-Graph-RAG vs grep vs standard RAG

Feature Code-Graph-RAG grep Standard RAG
Understands relationships Yes (call chains, imports, inheritance) No (text match only) Partial (chunk retrieval)
Multi-language 12+ languages, one schema Yes (text) Yes (text)
Dead code detection Yes (walk call edges from entry points) No No
AST-based editing Yes (surgical patch with diff preview) No No
Data-flow tracing Yes (FLOWS_TO taint edges) No No
MCP server Yes (Claude Code integration) No Rarely
Real-time updates Yes (watch mode) N/A No (re-index required)
Best for Understanding and editing large multi-language codebases Quick text searches Document Q&A

Bottom line: Code-Graph-RAG is the most sophisticated open source tool for understanding large codebases with AI. By building a knowledge graph of your code's structure (functions, classes, methods, call relationships, data flows) and letting you query it in natural language, it eliminates the grep-and-read cycle that wastes hours on large monorepos. The MCP server integration means your AI agent can query the graph directly instead of reading files one by one. If you work in a monorepo with multiple languages and want your AI tools to actually understand the codebase structure, this is the best free open source option available.

3 alternatives worth checking out

  • Sourcegraph Cody (sourcegraph.com/cody): A commercial AI coding assistant that uses Sourcegraph's code graph for context. Cody is excellent but requires a Sourcegraph instance and a paid plan for large codebases. Code-Graph-RAG is the open source alternative that builds its own graph locally.
  • Aider (aider.chat): An AI pair programming CLI that uses a repo map to understand code structure. Aider's repo map is simpler (a tree of files and functions) but does not build a full knowledge graph with call relationships and data flows. Use Aider for quick edits, Code-Graph-RAG for deep codebase understanding.
  • Continue (continue.dev): An open source AI coding assistant for VS Code and JetBrains. Continue supports codebase indexing with embeddings for retrieval, but it does not build a structural knowledge graph. Use Continue for inline code completion, Code-Graph-RAG for architectural queries.

Found this guide useful? Check out more developer tools and AI tools on Sudo Scout.

Share:

Related posts