Code-Graph-RAG parses a multi-language codebase with tree-sitter, stores its structure as a knowledge graph in Memgraph, and lets you query, edit, and optimise that code in plain English. A monorepo of mixed languages lands in one graph under a single language-agnostic schema, with functions, classes, methods, modules, imports, and call relationships as nodes and edges.
The system has two parts: a tree-sitter parser that ingests the codebase into the graph, and an interactive command-line RAG layer that translates a natural-language question into a Cypher query, retrieves the matching code, and drives editing and optimisation. Edits are AST-based and surgical, with a diff preview before anything is written.
Beyond question answering, the graph supports dead-code detection by walking call and reference edges from entry points, structural search and replace by AST pattern with ast-grep, data-flow edges that follow values from sources to I/O sinks, and dynamic tracing that merges calls observed in a test run or in production eBPF profiles into the graph to reveal dispatch static analysis misses.
Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, and Dart are fully supported. Scala is in development, and Ruby, Kotlin, Swift, Elixir, Haskell, Solidity, Bash, and Nix have structural support — modules, functions, classes where the language has them, and imports — through a pluggable ast-grep tier.
Three version lines differ by design: git tags mark every merge, while GitHub Releases and PyPI publish every fiftieth version plus any security fix, which ships immediately rather than waiting for the cadence. The published package needs Python 3.12 or newer, plus Docker for Memgraph, cmake, and ripgrep.
Features
- Knowledge graph: functions, classes, methods, modules, and their relationships stored in Memgraph under one schema across languages
- Natural-language queries: questions translated to Cypher and answered from the real structure of the code
- AI code editing: AST-targeted replacement of a function or block, with a visual diff before the change lands
- Code optimisation: passes against language-specific conventions or your own coding standards, with an interactive approval workflow
- Structural search and replace: AST-pattern matching and rewriting with ast-grep rather than text or regex
- Dead-code detection: unreachable functions and methods found by walking call and reference edges from entry points, with a CI-friendly failure mode
- Data-flow edges: FLOWS_TO edges follow values through assignments, calls, and returns to I/O sinks
- Dynamic tracing: cgr trace merges calls from a test run or production eBPF profiles into the graph
- MCP server: 15 tools for indexing, querying, editing, and searching from an MCP client, honouring .cgrignore and .gitignore
- Packaged daemon: cgr daemon up starts Memgraph and Qdrant without a compose file, and the graph is shared across indexed repositories
- Python SDK: graph loader, Cypher generator, and semantic search available as libraries
Integrates with
Claude Code
Terminal-based agentic coding tool that reads your codebase and runs tasks through natural-language commands
Model Context Protocol
Open protocol plus SDKs for connecting agents to tools and data sources.
Qdrant
Open-source vector database and similarity-search engine with filtering, hybrid search and a managed cloud.
