Code-Graph-RAG: The Open-Source Tool With 2,700+ GitHub Stars That Turns Your Monorepo Into a Queryable Knowledge Graph
Code-Graph-RAG parses multi-language codebases with Tree-sitter, builds a knowledge graph in Memgraph, and lets you query, edit, and optimize code using natural language—making monorepo navigation effortless.
If you've ever worked in a large monorepo, you know the pain: hundreds of files, multiple languages, tangled dependencies, and that sinking feeling when someone asks "where does this function get called?" or "what breaks if I change this API?"
Traditional tools like grep, IDE search, and even LLM-powered assistants struggle with the complexity of modern codebases. They search text, not structure. They find matches, not relationships.
Code-Graph-RAG takes a fundamentally different approach. It parses your entire codebase—regardless of language—builds a knowledge graph of its structure, and lets you query that graph in natural language. Think of it as giving your codebase a brain.
What Is Code-Graph-RAG?
Code-Graph-RAG is an open-source project that combines three powerful technologies:
- Tree-sitter — A parser generator that extracts functions, classes, methods, and modules from source code across 13+ languages
- Memgraph — A graph database that stores your codebase as an interconnected knowledge graph
- RAG (Retrieval-Augmented Generation) — An AI system that translates natural language questions into Cypher queries and retrieves relevant code
The result? You can ask questions like "Show me all functions that call the payment API" or "Find dead code in the authentication module" and get accurate, structure-aware answers.
How It Works: From Source Code to Knowledge Graph
Here's the magic behind Code-Graph-RAG:
Source Code → Tree-sitter Parser → AST Analysis → Memgraph Knowledge Graph
↓
User Query → AI Model (Cypher Gen) → Cypher Query → Graph Results → Response
Step 1: Parsing — Tree-sitter reads every source file and extracts structural information: functions, classes, methods, imports, and relationships between them.
Step 2: Graph Building — The extracted data is ingested into Memgraph as nodes and edges. A function becomes a node; a call to another function becomes an edge. The entire codebase becomes a queryable graph.
Step 3: Querying — When you ask a question in natural language, the AI model translates it into a Cypher query (Memgraph's query language), executes it against the graph, and returns the results with relevant source code.
Key Features That Set Code-Graph-RAG Apart
1. Multi-Language Support Under One Schema
Code-Graph-RAG supports 13+ languages with full parsing capabilities:
- Python, TypeScript, TSX, JavaScript
- Rust, Go, Java, C, C++, C#
- PHP, Lua, Dart
- Ruby (via pluggable ast-grep tier)
All languages share a unified graph schema. A Python function and a TypeScript function are both represented as Function nodes, making cross-language queries seamless.
2. Natural Language Code Queries
Instead of writing complex regex or memorizing file paths, you ask questions in plain English:
- "What functions does the UserService class have?"
- "Show me all imports in the payment module"
- "Which functions call the deprecated API endpoint?"
- "Find all classes that inherit from BaseModel"
The AI translates these into precise Cypher queries and returns actual source code.
3. Structural Search & Replace
Traditional find-and-replace works on text. Code-Graph-RAG works on structure. Using ast-grep integration, you can:
- Find all functions with a specific signature pattern
- Replace all instances of a deprecated API call with the new one
- Rewrite code patterns across the entire codebase while preserving semantics
This is especially powerful for large-scale refactoring.
4. Dead Code Detection
Dead code accumulates over time—unused functions, abandoned modules, orphaned utilities. Code-Graph-RAG walks the call graph from entry points and identifies code that's never reached:
cgr start --repo-path /path/to/repo
> Find dead code in this project
The system traces all call and reference edges, flagging functions and classes with zero incoming connections.
5. Data-Flow Tracing
New in recent versions: FLOWS_TO edges that track how data moves through your code. This is invaluable for security audits:
- Trace user input from HTTP request to database query
- Find all code paths that touch sensitive data
- Identify potential injection vulnerabilities
Currently supports C#, Java, C, and Go, with more languages coming.
6. MCP Integration for AI Coding Agents
Code-Graph-RAG runs as a Model Context Protocol (MCP) server, allowing AI coding assistants like Claude Code to query and edit your codebase directly. Your AI assistant gains deep structural understanding of your project.
Real-World Example: Refactoring a Legacy Monorepo
Imagine you're working on a 5-year-old e-commerce platform with:
- Backend: Python (Django) + Go microservices
- Frontend: TypeScript (React)
- Mobile: Dart (Flutter)
- Shared utilities in C++
Your task: migrate from a deprecated payment API to a new one. With traditional tools, you'd:
- Grep for the old API endpoint (misses dynamic calls)
- Manually check each result
- Hope you didn't miss anything
- Pray tests catch the rest
With Code-Graph-RAG:
cgr start --repo-path /path/to/ecommerce-platform --update-graph
> Find all code that calls the old payment API
The system returns every function across all languages that directly or indirectly calls the deprecated endpoint, with full context and source code.
> Replace all calls to oldPaymentAPI.process() with newPaymentAPI.charge()
Code-Graph-RAG performs structural search and replace, showing you a diff preview before anything changes. You review, approve, and commit.
Total time: 30 minutes instead of 3 days.
Getting Started in 5 Minutes
Install Code-Graph-RAG:
# Install 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 database:
cgr daemon up
Parse your repository:
cgr start --repo-path /path/to/your/repo --update-graph
Start querying:
cgr start --repo-path /path/to/your/repo
> Show me all classes in the auth module
That's it. Your codebase is now a queryable knowledge graph.
Key Benefits
- Understand large codebases fast — Query structure, not text. Find relationships, not just matches.
- Multi-language support — One tool for Python, TypeScript, Go, Rust, Java, C++, and more.
- AI-powered queries — Ask questions in natural language, get precise answers with source code.
- Dead code detection — Automatically find unused functions and modules.
- Structural refactoring — Search and replace by AST pattern, not regex.
- Data-flow analysis — Track how data moves through your code for security audits.
- MCP integration — Works seamlessly with Claude Code and other AI coding agents.
- Open source — MIT licensed, free to use, with optional enterprise support.
Frequently Asked Questions
1. What is Code-Graph-RAG and how does it work?
Code-Graph-RAG is an open-source tool that parses your codebase using Tree-sitter, builds a knowledge graph in Memgraph, and lets you query it using natural language. It translates your questions into Cypher queries and returns relevant source code with full context.
2. Which programming languages does Code-Graph-RAG support?
Code-Graph-RAG fully supports Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, and Dart. Ruby is supported via a pluggable ast-grep tier. Scala is in development.
3. Can Code-Graph-RAG work with monorepos containing multiple languages?
Yes! Code-Graph-RAG is designed specifically for multi-language monorepos. All languages share a unified graph schema, so you can query across languages seamlessly. A Python function calling a Go service will be fully represented in the graph.
4. How does Code-Graph-RAG compare to traditional code search tools?
Traditional tools like grep or IDE search work on text—they find string matches. Code-Graph-RAG works on structure—it understands functions, classes, calls, and imports as a graph. This means you can ask "what calls this function?" or "find dead code" and get accurate, relationship-aware answers.
5. Is Code-Graph-RAG free to use?
Yes, Code-Graph-RAG is open source under the MIT license and completely free to use. For organizations that need managed cloud hosting, on-premise deployment, or enterprise support, paid plans are available at code-graph-rag.com/enterprise.
6. Can Code-Graph-RAG detect dead code?
Yes! Code-Graph-RAG can detect dead code by walking the call graph from entry points and identifying functions and classes with no incoming references. Just ask "Find dead code in this project" and it will analyze the entire codebase.
7. Does Code-Graph-RAG integrate with AI coding assistants?
Yes, Code-Graph-RAG runs as a Model Context Protocol (MCP) server, allowing AI coding assistants like Claude Code to query and edit your codebase directly. This gives your AI assistant deep structural understanding of your project.
8. How do I install and set up Code-Graph-RAG?
Install with uv tool install "code-graph-rag[treesitter-full,semantic]" or pipx, then run cgr daemon up to start the graph database, and cgr start --repo-path /path/to/repo --update-graph to parse your codebase. Full installation guide is available in the documentation.
Code-Graph-RAG represents a paradigm shift in how developers interact with large codebases. Instead of searching through text, you query structure. Instead of guessing at relationships, you see them clearly in a knowledge graph.
Whether you're maintaining a legacy monorepo, onboarding new team members, or refactoring at scale, Code-Graph-RAG gives you the tools to understand and manage complexity.
Ready to turn your monorepo into a queryable knowledge graph? Check out Code-Graph-RAG on GitHub and start exploring your codebase in a whole new way.
Want to level up your development skills? Explore CoddyKit's interactive courses and master modern programming with hands-on projects.