code-graph-rag

vitali87MIT活跃维护

面向 monorepo 的代码检索增强生成工具,用知识图谱和 AST 解析多语言代码库,支持自然语言查询、理解与编辑代码。

The ultimate RAG for your monorepo. Query, understand, and edit multi-language codebases with the power of AI and knowledge graphs

v0.6.30发布于 2026-11-09 16:53 UTC5,347star +5 / 7 天712fork同步于 2026-11-10 11:36 UTC

怎么上手

由 README 提炼,执行前请确认
uv tool install "code-graph-rag[treesitter-full,ast-grep,semantic]"
cgr start --repo-path /path/to/repo --update-graph
硬件要求按 README 说明

README 未说明显存或 GPU 要求;图谱默认存为本地嵌入式 SQLite 文件,无需额外服务器。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用知识图谱索引多语言 monorepo,让你用自然语言查询和修改代码

面向 monorepo 的代码检索增强生成工具,用知识图谱和 AST 解析多语言代码库,支持自然语言查询、理解与编辑代码。

核心能力

  • 用 Tree-sitter 解析多语言代码并构建统一知识图谱
  • 把自然语言转成 Cypher 查询,检索真实代码结构
  • 基于 AST 做精准补丁编辑,改动前先预览 diff
  • 从入口点沿调用边遍历,找出死代码
  • 用 cgr trace 把运行时调用合并进图谱

容易踩的坑

安装时需带上 treesitter-full、ast-grep、semantic 等 extras,否则部分语言解析和向量搜索不可用;--clean 会删除共享图谱中的所有项目而非仅当前项目;默认图谱写在 ~/.cgr/graph.sqlite,需用 SQLITE_GRAPH_PATH 改路径。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.6.30
  1. v0.6.30最新正式版2026-11-09 · 2026-11-09 16:53 UTC

    🔒 Security

    Pydantic AI: Concurrency-limited models can keep their slot when a streamed request ends early (high severity, CVSS 7.5), dependency advisory GHSA-6fqq-452j-qhrp / CVE-2026-107286.

    Upgrading is strongly recommended.

    Highlights

    • Type Handling: Improved handling of type context managers, walrus operators, and match binding targets in both Python and TypeScript.
    • Rename Refinement: Prevented Go renames from unexporting names used by other packages.
    • Profile Naming: Corrected the naming of pprof profiles to avoid "malformed" errors when no samples are present.
    • Output Budget: Increased the Anthropic output budget to improve the default thinking experience.
    • Module Resolution: Resolved issues with module resolution in various scenarios, including ES module default imports and bare name bindings.
    • Dead Code Elimination: Removed dead code roots associated with IPython rich-display methods.
    • Incremental Refresh: Improved incremental refresh to ensure callers are updated when dispatch targets change.

    What's Changed

  2. v0.6.02026-11-08 · 2026-11-08 13:07 UTC
    查看更新说明

    ⚠️ Breaking changes

    code-graph-rag now requires its Rust extension, cgr-graph-rs, on every platform, and no longer runs without it: import codebase_rag stops with an error that says how to get it. The extension ships as wheels for CPython 3.12 or newer on Linux x86_64 and aarch64 (glibc and musl), macOS (Intel and Apple silicon) and Windows x64. On any other platform (PyPy, 32-bit or other architectures such as armv7, s390x and ppc64le, Windows on ARM), installing code-graph-rag now fails, where it used to install and run the pure-Python engine.

    There is no setting that keeps the old behaviour on those platforms. To keep using cgr there, pin code-graph-rag below this release.

    Existing installs on the supported platforms already have the extension and see no change in behaviour. They install fewer packages: defusedxml and tomli-w are gone (cgr reads XML project files and writes workspace files in the extension now), and huggingface-hub, with hf-xet, fsspec, tqdm, filelock and packaging, is installed only by the semantic extra, the one part of cgr that uses it. See The Rust extension.

    Highlights

    • Continuous Integration Improvements: Enhanced release cadence tracking and ensured accurate green status for deferred releases.
    • Dependency Updates: Updated Golang version in the /.oss-scanner dependency and declared httpx in the codebase.
    • Code Quality & Clarity: Resolved several code style and correctness issues including foreach loop variable typing and Python method receiver handling.
    • Build Process Refinement: Reduced the default install package count and improved makefile functionality for host/port watching.
    • Feature Control: Prevented the use of --no-endpoint-roots when endpoint data is absent.

    What's Changed

    **Full Changel

  3. v0.5.02026-11-03 · 2026-11-03 03:26 UTC
    查看更新说明

    ⚠️ Breaking changes

    The MCP server and the agent's file tools refuse three things they used to do:

    • No file tool writes inside a .git directory any more, or inside the git directory a .git file points to (git init --separate-git-dir, a worktree), in the CLI or over MCP. Git runs the commands its config and hooks name, so a write there could run code on your machine. Change git's own files with git.
    • MCP write_file and surgical_replace_code no longer change files that look like credentials (.env, .env.*, private keys, .aws/credentials, and the rest of the list MCP read_file already refuses). .env.example and other templates are still written. To keep the old behaviour, export CGR_ALLOW_SENSITIVE_WRITES=true in the environment the server starts with (a .env file cannot set it). The CLI agent already asks before every write and is unchanged.
    • cgr mcp-server no longer starts in a directory that holds your home directory, or in a disk root such as /, unless TARGET_REPO_PATH names it (a client that names a narrower project in CLAUDE_PROJECT_ROOT gets that project served instead). A client that launches the server without TARGET_REPO_PATH from such a directory now gets a configuration error at start-up. Set TARGET_REPO_PATH to the project's directory in the client's server configuration, as the MCP setup guide shows.

    The HTTP transport without MCP_HTTP_AUTH_TOKEN now also refuses requests whose Host or Origin header names anything other than 127.0.0.1, localhost or [::1] on the server's port. Local clients are unaffected. With a token nothing changes.

    Existing installs: a server configured with TARGET_REPO_PATH set to a project, as the setup guide shows, starts as before. See Credential files and the MCP server guide.

    Highlights

    • Rust Upgrade: Updated Rust to version 1.99.1-slim-trixie.
    • Security Improvements: Enhanced security by determining the target Git directory for writes and hardening the MCP server's file tools and HTTP transport.
    • Signature Functionality: Added support for reading and writing JavaScript headers for change signatures, including the ability to change the signature of JavaScript functions or methods.
    • Benchmark Enhancement: Added ColGrep to the retrieval benchmark for improved evaluation.
    • Dependency Updates: Updated several dependencies including anthropics/claude-code-action, click, zensical, ty and eclipse-temurin.
    • CI Improvements: Introduced a check to fail the merge if Greptile scores the head commit below 5/5.
    • macOS Compatibility: The build now leaves macOS-14 support.

    What's Changed

  4. v0.4.192026-11-01 · 2026-11-01 20:01 UTC
    查看更新说明

    🔒 Security

    This release contains a security fix; see the Security Advisories page.

    Upgrading is strongly recommended.

    Highlights

    • Dependency Updates: Several dependencies have been updated, including protobuf to 7.36.2, transformers to 5.21.0, and python to 3.15-slim, bringing in various bug fixes and new features.
    • Quiet Mode Enhancement: The --quiet flag for the CLI now suppresses the scanning line for dead code and duplicates, providing a cleaner output.
    • Signature Change Tests: Comprehensive acceptance, transaction, and mapping tests have been added for the change_signature feature, ensuring robust functionality.
    • Context Budget Fix: The system now correctly handles cases where a target doesn't fit within the allocated budget, preventing unexpected behaviour.
    • Performance Improvements: Optimisations have been made to improve performance, including indexing file definitions and returning registry trie results directly.
    • 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 prune functionality has been added to remove projects where the root no longer exists.

    New Contributors

    Full Changelog: https://github.com/vitali87/code-graph-rag/compare/v0.4.5...v0.4.19

    What's Changed

  5. v0.4.52026-10-30 · 2026-10-30 11:01 UTC
    查看更新说明

    ⚠️ Breaking changes

    A repository's .cgr.md no longer reaches the agent's system prompt until you approve its content. cgr start and cgr optimize show the file and ask (the default is no), and remember the approval until the file changes. cgr start -a and the MCP server's ask_agent cannot ask, so they skip a .cgr.md you have not approved and log why. Your own ~/.cgr.md loads as before.

    To keep the old behaviour, approve each repository's file once in cgr start, or export CGR_TRUST_PROJECT_INSTRUCTIONS=true in your shell or CI environment to load every repository's file without asking (a .env file cannot set it, since it usually belongs to the repository). Use the variable only for repositories you control, such as CI on your own code.

    Existing installs: nothing is approved yet, so the first cgr start in each repository with a .cgr.md asks once. Until then, non-interactive runs work without the file. See Project instructions.

    Highlights

    • Dependencies Updated: Several dependencies have been updated to the latest versions, including neo4j, qdrant-client, and memgraph/lab, bringing in bug fixes and new features.
    • Rust Performance Improvements: Optimisations have been made to the Rust indexer, including hashing definitions and computing interface fingerprints more efficiently.
    • CLI Enhancements: The change_signature operation is now accessible through the CLI and MCP, with improved handling for partial graphs.
    • Security Focus: Enhanced security measures include approving .cgr.md files, prompting before reading credential files, and annotating MCP tools.
    • Graph-RS Testing: Expanded fuzz testing for the Graph-RS component with new targets and improved input decoding.
    • MiniMax Models Added: Current MiniMax text models have been included.
    • CI Improvements: Various CI updates include running CodeQL on all pull requests and streamlining cache management.

    What's Changed

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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.

    Latest News 🔥

    • Continuous Integration Improvements: Enhanced release cadence tracking and ensured accurate green status for deferred releases.
    • Code Quality & Clarity: Resolved several code style and correctness issues including foreach loop variable typing and Python method receiver handling.
    • Build Process Refinement: Reduced the default install package count and improved makefile functionality for host/port watching.
    • Feature Control: Prevented the use of --no-endpoint-roots when endpoint data is absent.

    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 trace and merge the calls that actually happened into the graph, exposing dispatch that static analysis cannot see.

    How It Works

    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 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/types for Go, and opt-in Roslyn, javac and 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.
    2. 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:

    wherewhat it tracks
    git tagsevery version, one per merge
    GitHub Releases (binaries, signatures)every 50th version, plus any security fix, breaking change or merge labelled release now
    PyPIevery 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] cgr requires its native extension, cgr-graph-rs, which ships for CPython 3.12 or newer on Linux (x86_64, aarch64), macOS and Windows x64, so it installs on those platforms only. 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

    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.