Code-Graph-RAG
Knowledge-graph RAG for multi-language codebases: index, query and edit code in natural language.
ماذا يمكنك أن تفعل مع Code-Graph-RAG؟
- Ask questions about the codebase in natural language and get answers grounded in the real structure.
- Retrieve the actual source of any function, class, or method by name or by intent.
- Edit code through the agent with AST-based surgical patching and a diff preview before anything changes.
- Optimise code against language best practices or your own coding standards.
- Find dead code by walking call and reference edges from entry points.
- Search and rewrite structurally by AST pattern with ast-grep.
- Overlay runtime behaviour: trace a test run (or pull production eBPF profiles) with
cgr traceand merge the calls that actually happened into the graph, exposing dispatch that static analysis cannot see.
التثبيت
أضف هذا إلى إعدادات MCP في عميلك (Claude Desktop: claude_desktop_config.json، وCursor: .cursor/mcp.json، ويستخدم VS Code وغيره الصيغة نفسها «mcpServers»).
code-graph-ragclaude mcp add code-graph-rag -e 'ORCHESTRATOR_PROVIDER=ollama' -e 'ORCHESTRATOR_MODEL=llama3.2' -e 'ORCHESTRATOR_API_KEY=<your orchestrator_api_key>' -e 'CYPHER_PROVIDER=ollama' -e 'CYPHER_MODEL=llama3.2' -e 'CYPHER_API_KEY=<your cypher_api_key>' -e 'MEMGRAPH_HOST=localhost' -e 'MEMGRAPH_PORT=7687' -e 'TARGET_REPO_PATH=<TARGET_REPO_PATH>' -- uvx code-graph-rag==0.4.19 mcp-server
{
"mcpServers": {
"code-graph-rag": {
"command": "uvx",
"args": [
"code-graph-rag==0.4.19",
"mcp-server"
],
"env": {
"ORCHESTRATOR_PROVIDER": "ollama",
"ORCHESTRATOR_MODEL": "llama3.2",
"ORCHESTRATOR_API_KEY": "<your orchestrator_api_key>",
"CYPHER_PROVIDER": "ollama",
"CYPHER_MODEL": "llama3.2",
"CYPHER_API_KEY": "<your cypher_api_key>",
"MEMGRAPH_HOST": "localhost",
"MEMGRAPH_PORT": "7687",
"TARGET_REPO_PATH": "<TARGET_REPO_PATH>"
}
}
}
}
متغيرات البيئة
ORCHESTRATOR_PROVIDERLLM provider for the orchestrator agent (openai, anthropic, google, azure, cohere, ollama)ORCHESTRATOR_MODELModel name for the orchestrator agentORCHESTRATOR_API_KEYسري API key for the orchestrator LLM provider (not needed for the default local ollama provider)CYPHER_PROVIDERLLM provider for Cypher query generation (openai, anthropic, google, azure, cohere, ollama)CYPHER_MODELModel name for Cypher query generationCYPHER_API_KEYسري API key for the Cypher LLM provider (not needed for the default local ollama provider)MEMGRAPH_HOSTHostname of the Memgraph databaseMEMGRAPH_PORTPort of the Memgraph databaseTARGET_REPO_PATHPath to the repository to analyze (auto-detected from working directory if not set)
التوثيق
مأخوذ من ملف README للمشروع على GitHub ويُحدَّث أسبوعيًا. تفتح الروابط على GitHub.
المحتويات
Code-Graph-RAG
Code-Graph-RAG parses a multi-language codebase with Tree-sitter, sharpened by compiler-grade frontends and runtime traces where available, builds a knowledge graph of its structure in an embedded graph database that needs no server, and lets you query, edit, and optimise that code in plain English. It works across a monorepo of mixed languages under one unified graph schema.
1. Index: cgr start --update-graph parses a repository into a knowledge graph (sped up)
2. Ask: cgr start answers questions and edits code, grounded in that graph
Latest News 🔥
- Quiet Mode Enhancement: The
--quietflag for the CLI now suppresses the scanning line for dead code and duplicates, providing a cleaner output. - Context Budget Fix: The system now correctly handles cases where a target doesn't fit within the allocated budget, preventing unexpected behaviour.
- Code Quality: Changes have been made to report decorator and modifier changes that affect method calls and to ensure submodule grammars are loaded correctly.
- CGR Prune Feature: A new
cgr prunefunctionality has been added to remove projects where the root no longer exists.
See NEWS.md for the full history.
What It Does
Point Code-Graph-RAG at a repository and it reads every source file, extracts functions, classes, methods, modules, and the relationships between them, and stores the result as an interconnected graph. Once the graph exists you can:
- Ask questions about the codebase in natural language and get answers grounded in the real structure.
- Retrieve the actual source of any function, class, or method by name or by intent.
- Edit code through the agent with AST-based surgical patching and a diff preview before anything changes.
- Optimise code against language best practices or your own coding standards.
- Find dead code by walking call and reference edges from entry points.
- Search and rewrite structurally by AST pattern with ast-grep.
- Overlay runtime behaviour: trace a test run (or pull production eBPF profiles) with
cgr traceand merge the calls that actually happened into the graph, exposing dispatch that static analysis cannot see.
How It Works
The system has two components:
- Multi-language parser. A Tree-sitter based parser reads the codebase and ingests functions, classes, methods, modules, and their relationships into the graph under a single language-agnostic schema. Where a toolchain is available, compiler-grade frontends layer exact facts on top (libclang for C/C++,
go/typesfor Go, and opt-in Roslyn,javacand Jedi for C#, Java and Python), and dynamic tracing merges calls observed at runtime. Tree-sitter stays the backbone: a trace only sees code that ran, and a compiler frontend only covers what its toolchain can build. - RAG system (
codebase_rag/). An interactive CLI that turns natural language into Cypher queries, retrieves matching code, and drives AI-powered editing and optimisation.
Source Code -> Tree-sitter Parser -> AST Analysis -> Knowledge Graph
|
User Query -> AI Model (Cypher Gen) -> Cypher Query -> Graph Results -> Response
The graph is stored in an embedded SQLite file by default. Memgraph and Neo4j are opt-in backends that run the same Cypher; Graph Backends compares them.
See the Architecture Overview and Graph Schema for the full picture.
Supported Languages
Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, Dart, and Julia 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 the pluggable ast-grep tier. See the Language Support matrix for per-language capabilities.
Installation
cgr is published to PyPI. Install it system-wide with the treesitter-full (tree-sitter grammars), ast-grep (Ruby, Kotlin, Swift, Elixir, Haskell, Solidity, Bash, Nix) and semantic (vector search) extras:
# with uv (recommended)
uv tool install "code-graph-rag[treesitter-full,ast-grep,semantic]"
# or with pipx
pipx install "code-graph-rag[treesitter-full,ast-grep,semantic]"
Which version am I getting?
Three version lines exist and they intentionally differ:
| where | what it tracks |
|---|---|
| git tags | every version, one per merge |
| GitHub Releases (binaries, signatures) | every 50th version, plus any security fix, breaking change or merge labelled release now |
| PyPI | every 50th version, plus any security fix, breaking change or merge labelled release now |
So the newest tag on main usually runs ahead of the newest release, often by
tens of patch versions; they coincide only just after a release. Nothing is
stuck, the cadences differ by design. A security fix, a breaking change or a
merge a maintainer labels release now does NOT wait for the cadence: each ships
a release and a PyPI upload immediately.
uv tool install and pipx install give you the newest PyPI version, which is the
newest RELEASE, not the newest tag. Interim tags exist so every merge is
addressable; binaries and PyPI uploads follow the cadence above.
To run code newer than the latest release, install from git:
uv tool install "code-graph-rag[treesitter-full,ast-grep,semantic] @ git+https://github.com/vitali87/code-graph-rag@main"
To upgrade an existing install, run uv tool upgrade code-graph-rag (with pipx, pipx upgrade code-graph-rag, or pipx reinstall code-graph-rag for a git install). Upgrade covers the other install methods.
You also need Python 3.12+ and ripgrep. The graph lives in an embedded SQLite file by default, so there is no database server to run: no Docker and no cmake. Memgraph and Neo4j remain available as opt-in backends (Graph Backends). Full prerequisites, source installs, and environment setup are in the Installation guide.
[!NOTE] The wheel is pure Python (
py3-none-any), so it installs on any platform with Python 3.12 or newer. Older system interpreters (Debian Bookworm ships 3.11) need the interpreter pinned explicitly; see Installation for the commands.
Quick Start
# Parse a repository into the graph, then query it
cgr start --repo-path /path/to/repo --update-graph
cgr start --repo-path /path/to/repo
The graph is written to ~/.cgr/graph.sqlite (set SQLITE_GRAPH_PATH to move it).
To use Memgraph instead, install the driver with the memgraph extra, set
GRAPH_BACKEND=memgraph, and start the packaged Memgraph + Qdrant stack with
cgr daemon up.
Repeat the first command for each repository you want indexed; the graph is
shared, and syncing one project leaves the others alone. To start over from an
empty graph, add --clean — it deletes every project in the shared graph,
not just this one, and asks for confirmation first when other
projects would be destroyed.
A default index leaves out the opt-in capture groups; add them with --capture or CGR_CAPTURE.
The Quick Start guide walks through parsing, querying, and exporting in five minutes.
MCP Server
Code-Graph-RAG runs as an MCP server so Claude Code and other MCP clients can query and edit your codebase directly. See the MCP Server guide for setup.
Documentation
Getting Started
User Guide
- CLI Reference
- Interactive Querying
- Code Optimisation
- Dead Code Detection
- Dynamic Call Tracing
- Graph Export
- Real-Time Updates
- C/C++ Semantic Mode
- MCP Server
- Porting Between Languages
Architecture
Python SDK
Advanced
Enterprise Services
Code-Graph-RAG is open source and free to use. For organisations that need more, we offer fully managed cloud-hosted solutions and on-premise deployments:
- Cloud-Hosted Deployment: Managed cloud infrastructure for both the graph database and the AI agent connection. Zero infrastructure overhead, so we handle scaling, updates, and availability while your team focuses on building.
- On-Premise & Air-Gapped Deployment: Deploy Code-Graph-RAG entirely within your own environment, including air-gapped networks. Full data sovereignty for regulated industries and security-sensitive organisations.
We also offer custom development, integration consulting, technical support contracts, and team training.
View plans & pricing at code-graph-rag.com
Contributing
Please see CONTRIBUTING.md for contribution guidelines. Good first PRs come from the TODO issues.
Support
For issues or questions, check the Troubleshooting guide first, then open an issue.
If cgr is useful to you, please consider pledging support on GitHub Sponsors. cgr links the page under cgr --version and, in a terminal, after most commands finish; set CGR_SPONSOR_PLEDGE=false to hide that line.
Accessibility
ACCESSIBILITY.md describes what cgr and its documentation support for people using assistive technology or alternative settings, the known limitations and their workarounds, and how to report a barrier.
License
MIT. See LICENSE.
Third-party components and their licences are credited on the Credits page.
الأسئلة الشائعة
ما هو Code-Graph-RAG؟
Knowledge-graph RAG for multi-language codebases: index, query and edit code in natural language.
كيف أثبّت Code-Graph-RAG؟
يعمل على جهازك. في Claude Code: claude mcp add code-graph-rag -e 'ORCHESTRATOR_PROVIDER=ollama' -e 'ORCHESTRATOR_MODEL=llama3.2' -e 'ORCHESTRATOR_API_KEY=<your orchestrator_api_key>' -e 'CYPHER_PROVIDER=ollama' -e 'CYPHER_MODEL=llama3.2' -e 'CYPHER_API_KEY=<your cypher_api_key>' -e 'MEMGRAPH_HOST=localhost' -e 'MEMGRAPH_PORT=7687' -e 'TARGET_REPO_PATH=<TARGET_REPO_PATH>' -- uvx code-graph-rag==0.4.19 mcp-server. وفي العملاء الآخرين، الصق إعداد JSON من هذه الصفحة في إعدادات MCP الخاصة بهم.
هل يحتاج Code-Graph-RAG إلى مفتاح API؟
نعم. يتطلب ORCHESTRATOR_API_KEY, CYPHER_API_KEY، وتضبطها في إعداداته.
هل Code-Graph-RAG مفتوح المصدر؟
نعم. شيفرته متاحة على GitHub بترخيص MIT.
من يصون Code-Graph-RAG؟
ينشره vitali87. يدرجه AI.tn لكنه لا يصونه ولا يوصي به.
من سجل MCP الرسمي. الإدراج ليس توصية: راجع شيفرة الخادم وصلاحياته قبل منحه الوصول إلى بياناتك.