กลับไปหน้า Tools

GetNotes Tools

tirth8205/code-review-graph

Tool นี้คืออะไร

`code-review-graph` เป็นเครื่องมือที่ช่วยให้ AI ตรวจสอบโค้ดได้อย่างมีประสิทธิภาพมากขึ้น โดยสร้างแผนผังโครงสร้างของโค้ดและติดตามการเปลี่ยนแปลง เพื่อให้ AI ได้รับบริบทที่แม่นยำและลดการใช้โทเค็นที่ไม่จำเป็น เหมาะสำหรับนักพัฒนาที่ใช้ AI ในการรีวิวโค้ดในโปรเจกต์ขนาดใหญ่หรือ monorepo

ข้อมูลโปรเจกต์

ดาว

19.8K

Forks

2.1K

License

MIT

อัปเดต GitHub ล่าสุด

18 ก.ค. 2569

เพิ่มใน GetNotes

18 ก.ค. 2569

Repository

tirth8205/code-review-graph

รูปแบบ

CLI / Terminal

เหมาะกับงาน

AI และ AgentsCoding Agents

เหมาะกับอาชีพ

Ecosystem

Python

แปลและเรียบเรียงโดย AI

เนื้อหาฉบับภาษาไทย

ใช้อ่านเพื่อทำความเข้าใจเบื้องต้น โปรดตรวจสอบรายละเอียดสำคัญกับเอกสารต้นฉบับด้านล่าง

code-review-graph

หยุดเผาผลาญโทเค็น เริ่มรีวิวอย่างชาญฉลาดขึ้น

English | 简体中文 | 日本語 | 한국어 | हिन्दी

PyPI Downloads Stars MIT Licence CI Python 3.10+ MCP Website Discord

การใช้งาน · คำสั่ง · คำถามที่พบบ่อย · การแก้ไขปัญหา · GitHub Action · การทำซ้ำเกณฑ์มาตรฐาน · แผนงาน

เครื่องมือ AI สำหรับการเขียนโค้ดอาจต้องอ่านโค้ดส่วนใหญ่ใน codebase ของคุณซ้ำไปซ้ำมาในงานรีวิว code-review-graph แก้ปัญหานั้นได้ โดยจะสร้างแผนผังโครงสร้างของโค้ดของคุณด้วย Tree-sitter ติดตามการเปลี่ยนแปลงทีละน้อย และให้บริบทที่แม่นยำแก่ผู้ช่วย AI ของคุณผ่าน MCP เพื่อให้อ่านเฉพาะส่วนที่สำคัญเท่านั้น


เริ่มต้นอย่างรวดเร็ว

bash
pip install code-review-graph                     # or: pipx install code-review-graph
code-review-graph install          # auto-detects and configures all supported platforms
code-review-graph build            # parse your codebase

คำสั่งเดียวก็ตั้งค่าทุกอย่างได้ install จะตรวจจับเครื่องมือ AI สำหรับการเขียนโค้ดที่คุณมี เขียนการกำหนดค่า MCP ที่ถูกต้องสำหรับแต่ละเครื่องมือ ติดตั้ง hooks/skills ที่เป็น native ของแพลตฟอร์มที่รองรับ และแทรกคำแนะนำที่เข้าใจกราฟลงในกฎของแพลตฟอร์มของคุณ โดยจะตรวจจับโดยอัตโนมัติว่าคุณติดตั้งผ่าน uvx หรือ pip/pipx และสร้างการกำหนดค่าที่ถูกต้อง รีสตาร์ท editor/tool ของคุณหลังจากติดตั้ง

หากต้องการกำหนดเป้าหมายแพลตฟอร์มเฉพาะ:

bash
code-review-graph install --platform codex       # configure only Codex
code-review-graph install --platform cursor      # configure only Cursor
code-review-graph install --platform claude-code  # configure only Claude Code
code-review-graph install --platform gemini-cli   # configure only Gemini CLI
code-review-graph install --platform kiro         # configure only Kiro
code-review-graph install --platform copilot      # configure only GitHub Copilot (VS Code)
code-review-graph install --platform copilot-cli  # configure only GitHub Copilot CLI
code-review-graph install --platform codebuddy    # configure only CodeBuddy Code

ต้องใช้ Python 3.10+ เพื่อประสบการณ์ที่ดีที่สุด ให้ติดตั้ง uv (การกำหนดค่า MCP จะใช้ uvx หากมี มิฉะนั้นจะกลับไปใช้คำสั่ง code-review-graph โดยตรง)

หากต้องการลบ CRG ออกจากโปรเจกต์ Git หรือ SVN ให้ใช้คำสั่ง uninstall ที่สมมาตรจากที่ใดก็ได้ภายใน working tree ของโปรเจกต์ เป้าหมายจะถูกปรับให้เป็น working tree root และไดเรกทอรีที่ไม่ใช่ repository จะถูกปฏิเสธ โดยจะลบเฉพาะไฟล์และรายการที่ CRG เป็นเจ้าของเท่านั้น เซิร์ฟเวอร์ MCP, hooks, skills และคอมเมนต์ JSONC ที่ไม่เกี่ยวข้องจะยังคงอยู่ การเปลี่ยนแปลงการกำหนดค่าที่ใช้ร่วมกันจะใช้การแทนที่แบบ atomic ดังนั้นหากการเขียนล้มเหลว ไฟล์ต้นฉบับจะยังคงอยู่

bash
code-review-graph uninstall --dry-run    # preview every action; write nothing
code-review-graph uninstall              # preview, ask for confirmation, then apply
code-review-graph uninstall --yes        # apply without prompting
code-review-graph uninstall --all-repos  # also clean every registered repository
code-review-graph uninstall --keep-data  # remove integrations but keep graph databases
code-review-graph uninstall --keep-user-configs --repo .  # clean this project only

จากนั้นเปิดโปรเจกต์ของคุณและถามผู้ช่วย AI ของคุณ:

code
Build the code review graph for this project

การสร้างครั้งแรกใช้เวลาประมาณ 10 วินาทีสำหรับโปรเจกต์ที่มี 500 ไฟล์ หลังจากนั้น โหมด watch และ hooks ที่รองรับสามารถอัปเดตกราฟได้โดยอัตโนมัติ

วิธีการทำงาน

repository ของคุณจะถูกแยกวิเคราะห์เป็น AST ด้วย Tree-sitter จัดเก็บเป็นกราฟของโหนด (ฟังก์ชัน, คลาส, การนำเข้า) และเอดจ์ (การเรียก, การสืบทอด, การครอบคลุมการทดสอบ) จากนั้นจะถูกสอบถามในเวลาที่รีวิวเพื่อคำนวณชุดไฟล์ขั้นต่ำที่ผู้ช่วย AI ของคุณจำเป็นต้องอ่าน

การวิเคราะห์ Blast-radius

เมื่อไฟล์มีการเปลี่ยนแปลง กราฟจะติดตามผู้เรียก, ผู้พึ่งพา และการทดสอบทั้งหมดที่อาจได้รับผลกระทบ นี่คือ "blast radius" ของการเปลี่ยนแปลง AI ของคุณจะอ่านเฉพาะไฟล์เหล่านี้แทนที่จะสแกนทั้งโปรเจกต์

การอัปเดตแบบเพิ่มขึ้นในเวลา < 2 วินาที

เมื่อเปิดใช้งาน hooks หรือโหมด watch การบันทึกไฟล์และ commit hooks ที่รองรับจะกระตุ้นการอัปเดตแบบเพิ่มขึ้น กราฟจะเปรียบเทียบไฟล์ที่เปลี่ยนแปลง ค้นหาผู้พึ่งพาผ่านการตรวจสอบแฮช SHA-256 และแยกวิเคราะห์เฉพาะส่วนที่เปลี่ยนแปลงเท่านั้น โปรเจกต์ที่มี 2,900 ไฟล์จะถูกจัดทำดัชนีใหม่ในเวลาไม่ถึง 2 วินาที

ปัญหา monorepo ได้รับการแก้ไขแล้ว

monorepo ขนาดใหญ่คือจุดที่การสิ้นเปลืองโทเค็นเจ็บปวดที่สุด กราฟจะตัดผ่านความยุ่งเหยิง — ไฟล์กว่า 27,700 ไฟล์ถูกยกเว้นจากบริบทการรีวิว มีเพียงประมาณ 15 ไฟล์เท่านั้นที่ถูกอ่านจริง

การรองรับภาษาที่หลากหลาย + Jupyter notebooks

การรองรับ Parser ครอบคลุมฟังก์ชัน, คลาส, การนำเข้า, call sites, การสืบทอด และการตรวจจับการทดสอบทั่วทั้งพื้นผิว parser ปัจจุบัน โดยใช้ Tree-sitter เมื่อมี และ fallbacks ที่กำหนดเป้าหมายเมื่อจำเป็น การรองรับปัจจุบันรวมถึง Python, JavaScript/TypeScript/TSX, Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin, Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL, โครงสร้าง Terraform/OpenTofu (.tf; ไฟล์ .hcl ทั่วไปจะถูกรู้จักเป็นโหนดไฟล์), Ansible playbooks/roles/tasks, Vue/Svelte SFCs, ไฟล์ Astro ที่แยกวิเคราะห์ผ่าน TypeScript parser, Jupyter/Databricks notebooks (.ipynb) และไฟล์ Perl XS (.xs) Generic YAML ไม่ถือว่าเป็นซอร์สโค้ด

โปรเจกต์ PHP ยังได้รับการแก้ไข Composer PSR-4 ที่จำกัด repository, การอ้างอิง Blade template และเอดจ์เชิงความหมายของ Laravel Route/Eloquent เมื่อซอร์สโค้ดมีการนำเข้าเฟรมเวิร์กที่ชัดเจน, การสืบทอดโมเดล และหลักฐาน receiver

เพิ่มภาษาของคุณเอง (ไม่ต้อง Fork)

หาก repo ของคุณใช้ภาษาที่ตัวแยกวิเคราะห์ยังไม่รองรับ คุณสามารถวางไฟล์ languages.toml ลงใน .code-review-graph/ เพื่อแมปนามสกุลไฟล์เข้ากับไวยากรณ์ใดๆ ที่รวมอยู่ใน tree_sitter_language_pack รวมถึงประเภทโหนด tree-sitter สำหรับฟังก์ชัน, คลาส, การนำเข้า และการเรียก:

toml
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
class_node_types = ["record_decl"]
import_node_types = ["import_attribute"]
call_node_types = ["call"]

ตัวเดิน tree-sitter ทั่วไปจะจัดการการดึงข้อมูลจากตรงนั้น — ไม่มีการเปลี่ยนแปลงโค้ด และภาษาในตัวไม่สามารถถูกเขียนทับได้ ดู docs/CUSTOM_LANGUAGES.md สำหรับการอ้างอิง Schema, กฎการตรวจสอบ และตัวอย่างการทำงานแบบครบวงจร

การรีวิว PR ที่มีการให้คะแนนความเสี่ยงใน CI (GitHub Action)

การวิเคราะห์เดียวกันนี้ทำงานเป็น GitHub Action แบบคอมโพสิต — และยังคงเป็นแบบ local-first: กราฟความรู้ถูกสร้างและสอบถามทั้งหมดบน CI runner ของคุณ โดยไม่มีการส่งซอร์สโค้ดไปยังบริการภายนอกใดๆ ในแต่ละ pull request แอคชันจะโพสต์คอมเมนต์แบบ sticky เพียงหนึ่งเดียวพร้อมฟังก์ชันที่ให้คะแนนความเสี่ยง, โฟลว์การทำงานที่ได้รับผลกระทบ และช่องว่างในการทดสอบ ซึ่งจะอัปเดตในตำแหน่งเดิมทุกครั้งที่ push อินพุต fail-on-risk ที่เป็นทางเลือกจะเปลี่ยนการรีวิวให้เป็นเกตการรวม (merge gate)

yaml
# .github/workflows/code-review-graph.yml
on:
  pull_request:

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: tirth8205/code-review-graph@v2.3.6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

ดู docs/GITHUB_ACTION.md สำหรับอินพุต, ระดับความเสี่ยง และรายละเอียดการแคช หรือเวิร์กโฟลว์ dogfood ที่ repo นี้รันบนตัวเองใน .github/workflows/pr-review.yml


เกณฑ์มาตรฐาน

ตัวเลขสำคัญ: การลดโทเค็นต่อคำถามโดยเฉลี่ยใน 6 repos อยู่ที่ประมาณ 82 เท่า (เทียบกับฐานข้อมูลทั้งหมดกับการสอบถามกราฟ) 528 เท่าที่ถูกอ้างถึงบ่อยครั้งคือค่าสูงสุด — repo ที่ดีที่สุดเพียงหนึ่งเดียว (fastapi) — ไม่ใช่ผลลัพธ์ทั่วไป

ตัวเลขทั้งหมดมาจากการรันการประเมินอัตโนมัติกับ 6 repositories โอเพนซอร์สจริง (รวม 13 คอมมิต) ทุกการกำหนดค่าจะตรึง SHA อัปสตรีม, ตัวตรวจจับชุมชน Leiden ทำงานด้วย seed ที่กำหนด และการฝังข้อมูลเป็นแบบกำหนดได้บน CPU — ดังนั้นการรันสองครั้งบนเครื่องที่ต่างกันจะให้ตัวเลขที่เหมือนกัน สูตรการทำซ้ำทั้งหมดพร้อมเอาต์พุตที่คาดหวังอยู่ใน docs/REPRODUCING.md การรันแบบรายงานเท่านั้นรายสัปดาห์บนการกำหนดค่าที่เล็กที่สุดสองรายการอยู่ใน .github/workflows/eval.yml

สำหรับคำถามทั่วไปของเอเจนต์ ("การยืนยันตัวตนทำงานอย่างไร", "จุดเริ่มต้นหลักคืออะไร", เป็นต้น) กราฟจะส่งคืนผลการค้นหาที่ตรงเป้าหมายประมาณ 2,000–3,500 โทเค็น + ขอบของเพื่อนบ้าน แทนที่จะบังคับให้เอเจนต์อ่านไฟล์ต้นฉบับทุกไฟล์ ตารางด้านล่างเป็นค่าเฉลี่ยจาก 5 คำถามตัวอย่างที่กำหนดไว้ใน code_review_graph/token_benchmark.py

RepoSnapshot SHAnaive_corpus_tokensavg graph_tokensReduction
fastapi0227991a951,0712,169528.4x
code-review-graph84bde354208,8212,49593.0x
gin5c00df8a166,8681,99091.8x
flaska29f88ce125,0221,98671.4x
expressb4ab7d65135,9553,46540.6x
httpxb55d463589,4922,43838.0x

การลดโทเค็นต่อคำถามโดยเฉลี่ยใน 6 repos: ~82 เท่า ช่วงคือ 38x – 528x โดยที่ 528x คือกรณีที่ดีที่สุด (fastapi ซึ่งเป็น corpus ที่ใหญ่ที่สุด) ไม่ใช่ตัวเลขหลัก

ฐานข้อมูลทั้งหมดข้างต้นเป็นขอบเขตบนที่ไม่มีเอเจนต์จริงจ่าย: เอเจนต์ที่มีความสามารถจะค้นหาตัวระบุและอ่านเฉพาะไฟล์ที่ตรงกันที่สุด เกณฑ์มาตรฐานการประเมิน agent_baseline วัดฐานข้อมูลที่สมจริงนั้น — การค้นหา grep แบบ pure-python ทั่วทั้ง corpus, ไฟล์ 3 อันดับแรกตามจำนวนการจับคู่, นับโทเค็นและเปรียบเทียบกับต้นทุนการสอบถามกราฟ (evaluate/results/<repo>_agent_baseline_*.csv)

เกณฑ์มาตรฐาน eval/benchmarks/token_efficiency.py อย่างเป็นทางการวัดสถานการณ์ที่แตกต่างกัน — JSON get_review_context() แบบเต็มเทียบกับเนื้อหาไฟล์ที่เปลี่ยนแปลงของคอมมิต — และรายงานอัตราส่วนที่ต่ำกว่า 1 สำหรับคอมมิตขนาดเล็ก เนื่องจากผลตอบรับของบริบทการรีวิวมีขอบรัศมีผลกระทบพร้อมกับส่วนย่อยของซอร์สโค้ดที่เกินกว่า diff ไฟล์เดียวเล็กๆ นั่นไม่ใช่ข้อผิดพลาด; เกณฑ์มาตรฐานทั้งสองตอบคำถามที่แตกต่างกัน ดู docs/REPRODUCING.md สำหรับระเบียบวิธีวิจัยฉบับเต็ม

ตั้งแต่ v2.3.4 เครื่องมือรีวิวและผลกระทบจะแนบการประมาณค่า context_savings ที่กระชับ เพื่อให้ไคลเอนต์ MCP สามารถเห็นบริบทโดยประมาณที่บันทึกไว้ต่อการเรียก ใน v2.3.5 CLI จะแสดงสิ่งนี้เป็นแผง Token Savings ที่มีกรอบสี่เหลี่ยมที่แสดงด้านบน (ดู "แผง Token Savings" ในส่วนการใช้งาน) และเพิ่ม --verify เพื่อตรวจสอบกับ tokenizer cl100k_base ของ OpenAI ข้อมูลการปรับเทียบใน docs/REPRODUCING.md แสดงให้เห็นว่าการประมาณค่าอยู่ภายใน ~1% ของโทเค็น GPT-4 จริงโดยรวมในไฟล์ตัวอย่าง 222 ไฟล์

การวิเคราะห์รัศมีผลกระทบกู้คืนทุกไฟล์ใน ground truth ในคอมมิตการประเมินทั้ง 13 รายการ — แต่ให้อ่านว่าเป็นขอบเขตบน ไม่ใช่ "recall 100%": ในโหมดนี้ ground truth (ไฟล์ที่เปลี่ยนแปลง + ไฟล์ที่มีขอบการเรียก/การนำเข้าเข้าสู่ไฟล์เหล่านั้น) ได้มาจากกราฟเดียวกันกับที่ตัวทำนายใช้ ดังนั้นจึงเป็นแบบวงกลมโดยโครงสร้าง การทำนายเกินที่เห็นได้ในคอลัมน์ precision เป็นการแลกเปลี่ยนที่จงใจ: การแจ้งเตือนไฟล์มากเกินไปดีกว่าการพลาดการพึ่งพาที่เสียหาย

RepoCommitsAvg F1Avg PrecisionRecall (graph-derived upper bound)
httpx20.8640.7861.0
fastapi20.8340.7501.0
code-review-graph20.7340.5841.0
express20.6670.5001.0
flask20.6280.4811.0
gin30.6090.4391.0
Average130.7140.5781.000

เกณฑ์มาตรฐานยังรัน โหมด co-change ที่ซื่อสัตย์: ตัวทำนายจะถูกตั้งค่าเริ่มต้นด้วยไฟล์ที่เปลี่ยนแปลงเพียงไฟล์เดียวและให้คะแนนเทียบกับไฟล์ อื่นๆ ที่ผู้เขียนได้แก้ไขจริงในคอมมิตเดียวกัน — หลักฐานที่เป็นอิสระจากประวัติ Git ไม่ใช่จากกราฟ ทั้งสองโหมดจะปรากฏเคียงข้างกันในไฟล์ CSV ผลลัพธ์ (คอลัมน์ ground_truth_mode) ตัวเลข co-change จะถูกเพิ่มไปยังสถิติที่เป็นทางการเมื่อถูกบันทึกโดย eval runner; เราจะไม่อ้างอิงตัวเลขเหล่านั้นก่อนที่จะทำการวัด

RepoFilesNodesEdgesFlow DetectionSearch Latency
express1411,91017,553106ms0.7ms
fastapi1,1226,28527,117128ms1.5ms
flask831,4467,97495ms0.7ms
gin991,28616,762111ms0.5ms
httpx601,2537,89696ms0.4ms

ข้อจำกัดและจุดอ่อนที่ทราบ

  • "Recall 1.0" ของผลกระทบได้มาจากกราฟและเป็นแบบวงกลม: ground truth ทางประวัติศาสตร์มาจากขอบกราฟเดียวกันกับที่ตัวทำนายใช้ ดังนั้นจึงเป็นขอบเขตบนโดยโครงสร้าง โหมด co-change ที่ซื่อสัตย์ (ให้คะแนนเทียบกับไฟล์ที่ถูกเปลี่ยนแปลงร่วมกันจริงในคอมมิตเดียวกัน) ถูกวัดควบคู่กันไป; คาดว่าตัวเลขเหล่านั้นจะต่ำกว่าอย่างมาก
  • การเปลี่ยนแปลงไฟล์เดียวขนาดเล็ก: บริบทของกราฟสามารถเกินกว่าการอ่านไฟล์แบบธรรมดาสำหรับการแก้ไขเล็กน้อย (ดูผลลัพธ์ของ express ด้านบน) ค่าใช้จ่ายเพิ่มเติมคือข้อมูลเมตาเชิงโครงสร้างที่ช่วยให้สามารถวิเคราะห์หลายไฟล์ได้
  • คุณภาพการค้นหา (MRR 0.35): การค้นหาด้วยคีย์เวิร์ดพบผลลัพธ์ที่ถูกต้องใน 4 อันดับแรกสำหรับคำค้นส่วนใหญ่ แต่การจัดอันดับยังต้องปรับปรุง คำค้นของ express คืนค่า 0 ผลลัพธ์เนื่องจากการตั้งชื่อรูปแบบโมดูล
  • การตรวจจับโฟลว์ (recall 33%): รูปแบบการเข้าใช้งานของเฟรมเวิร์กและแบบทั่วไปแข็งแกร่งที่สุดสำหรับ Python และ PHP/Laravel การตรวจจับโฟลว์ของ JavaScript และ Go ยังต้องปรับปรุง
  • การแลกเปลี่ยนระหว่าง Precision กับ Recall: การวิเคราะห์ผลกระทบถูกออกแบบมาให้ระมัดระวังโดยเจตนา มันจะแจ้งเตือนไฟล์ที่ อาจ ได้รับผลกระทบ ซึ่งหมายถึงการมี false positives บางส่วนในกราฟการพึ่งพาขนาดใหญ่

คุณสมบัติ

คุณสมบัติรายละเอียด
การอัปเดตแบบเพิ่มหน่วยแยกวิเคราะห์เฉพาะไฟล์ที่เปลี่ยนแปลง การอัปเดตครั้งต่อไปจะเสร็จสิ้นภายใน 2 วินาที
รองรับภาษาและโน้ตบุ๊กหลากหลายPython, JavaScript/TypeScript/TSX, Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin, Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL, โครงสร้าง Terraform/OpenTofu (.tf; ไฟล์ .hcl ทั่วไปเป็นแบบไฟล์เท่านั้น), Ansible playbooks/roles/tasks, Vue/Svelte SFCs, ไฟล์ Astro ที่แยกวิเคราะห์ผ่าน TypeScript parser, Jupyter/Databricks (.ipynb), และ Perl XS (.xs)
การแยกวิเคราะห์ PHP ที่รับรู้เฟรมเวิร์กการนำเข้า Composer PSR-4 ที่จำกัดตาม Repository, การอ้างอิงเทมเพลต Blade, และขอบ Laravel Route-to-controller และ Eloquent relationship ที่มีหลักฐานยืนยัน
การวิเคราะห์รัศมีผลกระทบแสดงฟังก์ชัน, คลาส และไฟล์ที่น่าจะได้รับผลกระทบจากการเปลี่ยนแปลง
Auto-update hooksHooks และ watch mode สามารถอัปเดตกราฟเมื่อบันทึกไฟล์และ commit hooks ที่รองรับ
การค้นหาเชิงความหมายการฝังเวกเตอร์เสริมผ่าน sentence-transformers, Google Gemini, MiniMax, หรือปลายทางที่เข้ากันได้กับ OpenAI (OpenAI จริง, Azure, new-api, LiteLLM, vLLM, LocalAI)
การแสดงผลแบบโต้ตอบกราฟ D3.js แบบ force-directed พร้อมการค้นหา, สลับตำนานชุมชน และโหนดที่ปรับขนาดตามดีกรี
การตรวจจับ Hub & Bridgeค้นหาโหนดที่มีการเชื่อมต่อมากที่สุดและจุดคอขวดทางสถาปัตยกรรมผ่าน betweenness centrality
การให้คะแนนความประหลาดใจตรวจจับการเชื่อมโยงที่ไม่คาดคิด: ข้ามชุมชน, ข้ามภาษา, ขอบจากส่วนปลายไปยังศูนย์กลาง
การวิเคราะห์ช่องว่างความรู้ระบุโหนดที่แยกตัว, จุดร้อนที่ไม่ได้ทดสอบ, ชุมชนที่บาง และจุดอ่อนเชิงโครงสร้าง
คำถามแนะนำคำถามรีวิวที่สร้างขึ้นอัตโนมัติจากการวิเคราะห์กราฟ (bridges, hubs, surprises)
ความเชื่อมั่นของขอบการให้คะแนนความเชื่อมั่นสามระดับ (EXTRACTED/INFERRED/AMBIGUOUS) พร้อมคะแนนทศนิยมบนขอบ
การสำรวจกราฟการสำรวจ BFS/DFS แบบอิสระจากโหนดใดๆ ด้วยความลึกและงบประมาณโทเค็นที่กำหนดค่าได้
รูปแบบการส่งออกGraphML (Gephi/yEd), Neo4j Cypher, Obsidian vault พร้อม wikilinks, กราฟ SVG แบบคงที่
Graph diffเปรียบเทียบสแนปช็อตกราฟเมื่อเวลาผ่านไป: โหนด/ขอบใหม่/ที่ถูกลบ, การเปลี่ยนแปลงชุมชน
การวัดประสิทธิภาพโทเค็นวัดโทเค็น corpus เต็มรูปแบบแบบ naive เทียบกับโทเค็นการสอบถามกราฟด้วยอัตราส่วนต่อคำถาม
การประมาณการประหยัดบริบทเมตาเดตา context_savings ที่กระชับบนเอาต์พุตการรีวิว MCP/CLI ที่เกี่ยวข้อง โดยระบุว่าเป็นค่าประมาณและเก็บไว้ในสามฟิลด์เล็กๆ
Memory loopเก็บผลลัพธ์ Q&A เป็น markdown เพื่อนำกลับมาใช้ใหม่ เพื่อให้กราฟเติบโตจากการสอบถาม
การแยกชุมชนอัตโนมัติชุมชนที่มีขนาดใหญ่เกินไป (>25% ของกราฟ) จะถูกแยกซ้ำๆ ผ่าน Leiden
โฟลว์การทำงานติดตามสายการเรียกจากจุดเริ่มต้น จัดเรียงตามความสำคัญถ่วงน้ำหนัก
การตรวจจับชุมชนจัดกลุ่มโค้ดที่เกี่ยวข้องผ่านอัลกอริทึม Leiden พร้อมการปรับขนาดความละเอียดสำหรับกราฟขนาดใหญ่
ภาพรวมสถาปัตยกรรมแผนที่สถาปัตยกรรมที่สร้างขึ้นอัตโนมัติพร้อมคำเตือนการเชื่อมโยง
การรีวิวที่ให้คะแนนความเสี่ยงdetect_changes แมป diffs ไปยังฟังก์ชัน, โฟลว์ และช่องว่างการทดสอบที่ได้รับผลกระทบ
ภาษาที่กำหนดเองเพิ่มภาษาใหม่ผ่าน .code-review-graph/languages.toml — ไม่ต้อง fork หรือเปลี่ยนแปลงโค้ด
GitHub Actionคอมเมนต์รีวิว PR ที่ให้คะแนนความเสี่ยงแบบ sticky ใน CI พร้อมเกตการรวม fail-on-risk ที่เป็นทางเลือก
เครื่องมือ Refactoringดูตัวอย่างการเปลี่ยนชื่อ, การตรวจจับโค้ดที่ไม่ได้ใช้งานที่รับรู้เฟรมเวิร์ก, คำแนะนำที่ขับเคลื่อนโดยชุมชน
การสร้าง Wikiสร้าง markdown wiki อัตโนมัติจากโครงสร้างชุมชน
Multi-repo registryลงทะเบียนหลาย repo, ค้นหาข้ามทั้งหมด
Multi-repo daemoncrg-daemon ตรวจสอบหลาย repo เป็น child processes พร้อมการตรวจสอบสุขภาพและการรีสตาร์ทอัตโนมัติ
MCP prompts5 เทมเพลตเวิร์กโฟลว์: review, architecture, debug, onboard, pre-merge
การค้นหาข้อความเต็มการค้นหาแบบไฮบริดที่ขับเคลื่อนโดย FTS5 ซึ่งรวมการค้นหาด้วยคีย์เวิร์ดและความคล้ายคลึงของเวกเตอร์
ที่เก็บข้อมูลในเครื่องไฟล์ SQLite ใน .code-review-graph/ การจัดเก็บกราฟหลักไม่จำเป็นต้องมีฐานข้อมูลภายนอกหรือบริการคลาวด์
Watch modeการอัปเดตกราฟอย่างต่อเนื่องในขณะที่คุณทำงาน

การใช้งาน

คำสั่งคำอธิบาย
/code-review-graph:build-graphสร้างหรือสร้างกราฟโค้ดใหม่
/code-review-graph:review-deltaตรวจสอบการเปลี่ยนแปลงตั้งแต่คอมมิตล่าสุด
/code-review-graph:review-prตรวจสอบ PR แบบเต็มพร้อมการวิเคราะห์ขอบเขตผลกระทบ
bash
code-review-graph install          # ตรวจจับและกำหนดค่าแพลตฟอร์มทั้งหมดโดยอัตโนมัติ
code-review-graph install --platform <name>  # กำหนดเป้าหมายแพลตฟอร์มที่เฉพาะเจาะจง
code-review-graph uninstall --dry-run  # ดูตัวอย่างการลบอาร์ติแฟกต์ที่ติดตั้งอย่างปลอดภัย
code-review-graph build            # แยกวิเคราะห์โค้ดเบสทั้งหมด
code-review-graph update           # อัปเดตแบบเพิ่มหน่วย (เฉพาะไฟล์ที่เปลี่ยนแปลง)
code-review-graph status           # สถิติกราฟ
code-review-graph watch            # อัปเดตอัตโนมัติเมื่อไฟล์เปลี่ยนแปลง
code-review-graph visualize        # สร้างกราฟ HTML แบบโต้ตอบ
code-review-graph visualize --format json      # ส่งออกข้อมูลกราฟภายในเป็น JSON
code-review-graph visualize --format graphml   # ส่งออกเป็น GraphML
code-review-graph visualize --format svg       # ส่งออกเป็น SVG
code-review-graph visualize --format obsidian  # ส่งออกเป็น Obsidian vault
code-review-graph visualize --format cypher    # ส่งออกเป็น Neo4j Cypher
code-review-graph wiki             # สร้าง markdown wiki จากคอมมูนิตี้
code-review-graph detect-changes --brief         # แผงความเสี่ยง + การประหยัดโทเค็น (อ่านอย่างเดียว)
code-review-graph update --brief                 # รีเฟรชกราฟ + แผงเดียวกัน
code-review-graph detect-changes --brief --verify  # ตรวจสอบข้ามกับ tiktoken
code-review-graph register <path>  # ลงทะเบียน repo ใน multi-repo registry
code-review-graph unregister <id>  # ลบ repo ออกจาก registry
code-review-graph repos            # แสดงรายการ repositories ที่ลงทะเบียน
code-review-graph daemon start     # เริ่ม daemon สำหรับ multi-repo watch
code-review-graph daemon stop      # หยุด daemon
code-review-graph daemon status    # แสดงสถานะ daemon และ repos
code-review-graph eval             # รันการประเมินประสิทธิภาพ
code-review-graph serve            # เริ่มต้น MCP server

การส่งออก JSON จะยังคงอยู่ในไดเรกทอรีข้อมูลกราฟภายใน ซึ่ง Git จะละเว้นโดยค่าเริ่มต้น ไฟล์เหล่านี้อาจมีพาธแบบสัมบูรณ์และเมตาดาต้าโครงสร้างโค้ด ดังนั้นโปรดตรวจสอบและทำความสะอาดไฟล์ที่ส่งออกก่อนที่จะเผยแพร่ภายนอกเครื่องของคุณ

ทั้งสองคำสั่งจะแสดงแผงขนาดกะทัดรัดเดียวกันที่แสดงจำนวนโทเค็นที่กราฟช่วยคุณประหยัดได้เมื่อเทียบกับการส่งไฟล์ที่เปลี่ยนแปลงไปยังเอเจนต์โดยตรง ทั้งสองคำสั่งแตกต่างกันใน สิ่งเดียว: กราฟจะถูกรีเฟรชก่อนหรือไม่

text
┌─────────────────────── Token Savings ────────────────────────┐
│ Full context would be:     12,921 tokens                     │
│ Graph context used:           762 tokens                     │
│ Saved:                     12,159 tokens (~94%)              │
│ Breakdown: Functions 244 · Tests 191 · Risk 244 · Other 83   │
└──────────────────────────────────────────────────────────────┘
คำสั่งสิ่งที่ทำเมื่อไหร่ที่ควรใช้
detect-changes --briefอ่านอย่างเดียว ดูการเปลี่ยนแปลงปัจจุบันของคุณ, สอบถามกราฟ ที่มีอยู่, แสดงแผง ~1 วินาทีส่วนใหญ่แล้ว — hooks (หรือ crg-daemon) จะรักษากราฟให้สดใหม่อยู่เบื้องหลัง ดังนั้นแค่นี้ก็เพียงพอแล้ว
update --briefแยกวิเคราะห์ไฟล์ที่เปลี่ยนแปลงของคุณลงในกราฟก่อน จากนั้นแสดงแผงเดียวกัน ~5 วินาทีหลังจากการ rebase, ชุดการเปลี่ยนแปลงขนาดใหญ่ หรือเมื่อใดก็ตามที่คุณสงสัยว่ากราฟไม่เป็นปัจจุบัน

ทั้งสองคำสั่งจะจบลงด้วย แผงเดียวกัน เนื่องจากทั้งสองเรียกใช้ขั้นตอน analyze_changes() เดียวกันในตอนท้าย ความแตกต่างคือตัวกราฟเองได้รับการรีเฟรชก่อนที่จะทำการวิเคราะห์นั้นหรือไม่

เพิ่ม --verify ในคำสั่งใดก็ได้เพื่อตรวจสอบตัวเลขที่แสดงกับ tokenizer cl100k_base ของ OpenAI (ตระกูล GPT-4) ต้องใช้ pip install tiktoken ค่าประมาณจะอยู่ภายใน ~1% ของโทเค็นจริงในการเปลี่ยนแปลงทั่วไป — ดู docs/REPRODUCING.md สำหรับข้อมูลการปรับเทียบ

เมตาดาต้า context_savings เดียวกันนี้ยังแนบโดยอัตโนมัติกับการตอบกลับ JSON ของเครื่องมือ MCP get_impact_radius, get_review_context, detect_changes และ get_architecture_overview ดังนั้นเอเจนต์ AI จึงสามารถแสดงการประหยัดให้มนุษย์เห็นในการแชทได้โดยไม่ต้องมีการแจ้งเตือนเพิ่มเติม

หากเอดิเตอร์ของคุณไม่รองรับ hooks (เช่น Cursor, OpenCode) หรือคุณเพียงต้องการให้กราฟของคุณอัปเดตอยู่เบื้องหลังโดยไม่ต้องมีการรวมเข้ากับเอดิเตอร์ใดๆ daemon นี้เหมาะสำหรับคุณ มันจะเฝ้าดู repo ของคุณเพื่อตรวจจับการเปลี่ยนแปลงไฟล์และสร้างกราฟใหม่โดยอัตโนมัติ — ไม่จำเป็นต้องใช้คำสั่ง build หรือ update ด้วยตนเอง

daemon รวมอยู่ใน code-review-graph แล้ว — ไม่ต้องติดตั้งแยกต่างหาก

การตั้งค่าอย่างรวดเร็ว:

bash
# 1. ลงทะเบียน repo ที่คุณต้องการเฝ้าดู
crg-daemon add ~/project-a --alias proj-a
crg-daemon add ~/project-b

# 2. เริ่ม daemon (ทำงานอยู่เบื้องหลัง)
crg-daemon start

# 3. แค่นั้นเอง — กราฟจะอัปเดตโดยอัตโนมัติ
crg-daemon status                 # ตรวจสอบสถานะ daemon และ watcher ของแต่ละ repo
crg-daemon logs --repo proj-a -f  # ดู log สำหรับ repo ที่เฉพาะเจาะจง
crg-daemon stop                   # หยุด daemon และกระบวนการ watcher ทั้งหมด

นอกจากนี้ยังมีให้ใช้งานในรูปแบบ code-review-graph daemon start|stop|status|...

ภายใต้เบื้องหลัง crg-daemon add จะเขียนลงในไฟล์คอนฟิก TOML ที่ ~/.code-review-graph/watch.toml คุณยังสามารถแก้ไขไฟล์นี้ได้โดยตรง:

toml
[[repos]]
path = "/home/user/project-a"
alias = "proj-a"

[[repos]]
path = "/home/user/project-b"
alias = "project-b"

daemon จะตรวจสอบไฟล์คอนฟิกนี้เพื่อหาการเปลี่ยนแปลงและเริ่ม/หยุดกระบวนการ watcher โดยอัตโนมัติเมื่อมีการเพิ่มหรือลบ repo การตรวจสอบสุขภาพทุก 30 วินาทีจะรีสตาร์ท watcher ที่หยุดทำงาน ไม่จำเป็นต้องมี dependency ภายนอก

ดู docs/COMMANDS.md สำหรับการอ้างอิงคอนฟิกแบบเต็มและตัวเลือกทั้งหมดที่มี

ผู้ช่วย AI ของคุณจะใช้สิ่งเหล่านี้โดยอัตโนมัติเมื่อสร้างกราฟแล้ว

เครื่องมือคำอธิบาย
build_or_update_graph_toolสร้างหรืออัปเดตกราฟแบบเพิ่มหน่วย
run_postprocess_toolรันการตรวจจับ flow, การตรวจจับ community และการทำดัชนี FTS ซ้ำ
get_minimal_context_toolบริบทที่กะทัดรัดเป็นพิเศษ (~100 โทเค็น) — เรียกใช้สิ่งนี้ก่อน
get_impact_radius_toolขอบเขตผลกระทบของไฟล์ที่เปลี่ยนแปลง
get_review_context_toolบริบทการรีวิวที่ปรับให้เหมาะสมกับโทเค็นพร้อมสรุปโครงสร้าง
query_graph_toolการสอบถามผู้เรียก, ผู้ถูกเรียก, การทดสอบ, การนำเข้า, การสืบทอด
traverse_graph_toolการสำรวจ BFS/DFS จากโหนดใดๆ ด้วยงบประมาณโทเค็น
semantic_search_nodes_toolค้นหาเอนทิตีโค้ดตามชื่อหรือความหมาย
embed_graph_toolคำนวณ vector embeddings สำหรับการค้นหาเชิงความหมาย
list_graph_stats_toolขนาดและสถานะของกราฟ
get_docs_section_toolดึงส่วนเอกสาร
find_large_functions_toolค้นหาฟังก์ชัน/คลาสที่เกินเกณฑ์จำนวนบรรทัด
list_flows_toolแสดงรายการ execution flows ที่เรียงตามความสำคัญ
get_flow_toolรับรายละเอียดของ execution flow เดียว
get_affected_flows_toolค้นหา flows ที่ได้รับผลกระทบจากไฟล์ที่เปลี่ยนแปลง
list_communities_toolแสดงรายการ code communities ที่ตรวจพบ
get_community_toolรับรายละเอียดของ community เดียว
get_architecture_overview_toolภาพรวมสถาปัตยกรรมจากโครงสร้าง community
detect_changes_toolการวิเคราะห์ผลกระทบการเปลี่ยนแปลงที่ให้คะแนนความเสี่ยงสำหรับการรีวิวโค้ด
get_hub_nodes_toolค้นหาโหนดที่มีการเชื่อมต่อมากที่สุด (จุดร้อนทางสถาปัตยกรรม)
get_bridge_nodes_toolค้นหาจุดคอขวดผ่าน betweenness centrality
get_knowledge_gaps_toolระบุจุดอ่อนเชิงโครงสร้างและจุดร้อนที่ยังไม่ได้ทดสอบ
get_surprising_connections_toolตรวจจับการเชื่อมโยงข้าม community ที่ไม่คาดคิด
get_suggested_questions_toolคำถามรีวิวที่สร้างขึ้นโดยอัตโนมัติจากการวิเคราะห์
refactor_toolดูตัวอย่างการเปลี่ยนชื่อ, การตรวจจับโค้ดที่ไม่ได้ใช้, คำแนะนำ
apply_refactor_toolใช้การ refactoring ที่เคยดูตัวอย่างไว้ก่อนหน้านี้
generate_wiki_toolสร้าง markdown wiki จาก communities
get_wiki_page_toolดึงหน้า wiki ที่เฉพาะเจาะจง
list_repos_toolแสดงรายการ repositories ที่ลงทะเบียน
cross_repo_search_toolค้นหาข้าม repositories ที่ลงทะเบียนทั้งหมด

MCP Prompts (5 เทมเพลตเวิร์กโฟลว์): review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check

หากต้องการยกเว้นพาธจากการทำดัชนี ให้สร้างไฟล์ .code-review-graphignore ใน root ของ repository ของคุณ:

code
generated/**
*.generated.ts
vendor/**
node_modules/**

หมายเหตุ: ใน git repos เฉพาะไฟล์ที่ถูกติดตามเท่านั้นที่จะถูกทำดัชนี (git ls-files) ดังนั้นไฟล์ที่ถูก gitignore จะถูกข้ามโดยอัตโนมัติ ใช้ .code-review-graphignore เพื่อยกเว้นไฟล์ที่ถูกติดตามหรือเมื่อ git ไม่พร้อมใช้งาน

กลุ่มการพึ่งพาเสริม:

bash
pip install "code-review-graph[embeddings]"          # การฝังเวกเตอร์ในเครื่อง (sentence-transformers)
pip install "code-review-graph[google-embeddings]"   # การฝัง Google Gemini
pip install "code-review-graph[communities]"         # การตรวจจับชุมชน (igraph)
pip install "code-review-graph[enrichment]"          # การเสริมการแก้ไขการเรียกใช้ Python (Jedi)
pip install "code-review-graph[eval]"                # เกณฑ์การประเมิน (matplotlib)
pip install "code-review-graph[wiki]"                # การสร้าง Wiki ด้วยสรุป LLM (ollama)
pip install "code-review-graph[all]"                 # การพึ่งพาเสริมทั้งหมด

ตัวแปรสภาพแวดล้อม

ตัวแปรคำอธิบายค่าเริ่มต้น
CRG_GIT_TIMEOUTระยะเวลาหมดเวลาเป็นวินาทีสำหรับการดำเนินการ Git30
CRG_DATA_DIRไดเรกทอรีสำหรับแทนที่ฐานข้อมูลกราฟและสิ่งประดิษฐ์กราฟที่สร้างขึ้น-
CRG_EMBEDDING_MODELโมเดลเริ่มต้นสำหรับการฝังเวกเตอร์all-MiniLM-L6-v2
CRG_ACCEPT_CLOUD_EMBEDDINGSระงับคำเตือนการส่งออกข้อมูลการฝังบนคลาวด์

เอกสารโปรเจกต์

อ่านเอกสารต้นฉบับ

README วิธีติดตั้ง วิธีใช้งาน และข้อกำหนดจาก repository ต้นฉบับ

ดูไฟล์บน GitHub
tirth8205%2Fcode-review-graph | Trendshift
PyPIDownloadsStarsMIT LicenceCIPython 3.10+MCPWebsiteDiscord

AI coding tools often re-read large parts of a codebase to review a change. code-review-graph builds a structural map of the code with Tree-sitter, keeps it updated incrementally, and serves compact context over MCP, so the assistant reads only the files a change touches.

The Token Problem: reading flask

What it does

  • Maps your code. Functions, classes, imports, calls and tests become one graph.
  • Shows what a change can break. The callers, dependents and tests it can reach, with a risk score.
  • Stays up to date. Hooks and watch mode parse again only the files that changed.
  • Works with your AI tools. One install sets up each tool it finds.
  • Stays on your machine. One SQLite file, no cloud service; cloud embeddings are opt-in.

Quick Start

Requires Python 3.10+.

bash
uv tool install code-review-graph      # or: pipx install / pip install code-review-graph
code-review-graph install              # set up the AI coding tools found on this machine
code-review-graph build                # parse the codebase
code-review-graph detect-changes --brief  # see what your last change touches

Restart the editor or tool, then open the project and ask the assistant:

code
Review my changes

Undo everything with code-review-graph uninstall (preview with --dry-run). If something does not work, run code-review-graph doctor: it checks the setup and changes nothing.

install looks for AI coding tools on this machine and sets up only the ones it finds. For each it writes an MCP server entry, installs hooks and skills where the tool supports them, and adds graph instructions to its rules file. It then names the tools it did not find; add one anyway with install --platform NAME.

Nothing is written until install has listed the files it will change and you have answered its question about instruction files. With no terminal, as when an AI agent runs it, it takes the default answer, yes, and says so; --no-instructions skips those files. install --dry-run shows each change as a diff and writes nothing. Restart the editor or tool afterwards.

The MCP entry and every hook run the copy of code-review-graph that ran install. The MCP entry uses poetry run or uv run inside a Poetry or uv project, uvx when install itself ran from uvx or uv tool install, and otherwise the Python that ran install. Hooks name that Python (or uvx), and run the code-review-graph on PATH if it is gone. After an upgrade, run install again.

The files install writes, such as .claude/ and .mcp.json, stay visible to git in case your team commits them. Until git tracks them, build and reviews leave them out, so your first review shows your own change; install lists them in .code-review-graph/install-manifest.json. install --gitignore adds the ones that run created to a marked block in .gitignore; uninstall removes the block.

For Codex, the installer also places a global code-review-graph Skill under $CODEX_HOME/skills/code-review-graph/ (default: ~/.codex/skills/code-review-graph/). It prefers CRG MCP tools and falls back to the bundled read-only CLI when MCP is unavailable; a missing, empty, or stale graph never triggers an implicit build or update. WSL and Windows Codex runtimes have separate CODEX_HOME directories and tool inventories, so install and refresh the runtime that will execute the task.

One install, every platform: detects Codex, Claude Code, CodeBuddy Code, Cursor, Windsurf, Zed, Continue, OpenCode, MiMo Code, Antigravity, Gemini CLI, Qwen Code, Qoder, Kiro, GitHub Copilot, GitHub Copilot CLI, Hermes Agent and DeepSeek Harness

To configure one platform, pass --platform with one of codex, claude-code, cursor, windsurf, zed, continue, opencode, mimo, antigravity, gemini-cli, qwen, kiro, qoder, copilot, copilot-cli, codebuddy, hermes, or dsh:

bash
code-review-graph install --platform cursor
code-review-graph install --platform codebuddy

A platform named this way is set up even when install does not find it. Config file locations are listed in docs/USAGE.md.

uninstall removes CRG-owned files and entries from a Git or SVN working tree and leaves other MCP servers, hooks, skills and JSONC comments alone. Run it from anywhere inside the tree. Shared config files are replaced atomically, so a failed write leaves the original intact. A config file install made, which git does not track and which holds nothing else, is removed along with the empty folders install made. With no terminal it takes the default answer, no, and says to pass --yes.

bash
code-review-graph uninstall --dry-run    # preview only
code-review-graph uninstall              # preview, confirm, apply
code-review-graph uninstall --yes        # apply without prompting
code-review-graph uninstall --all-repos  # also clean every registered repository
code-review-graph uninstall --keep-data  # remove integrations, keep graph databases
code-review-graph uninstall --keep-user-configs --repo .  # this project only

Build time scales with repository size; a cold build of a ~3,000-file repository took about 40 seconds (measured). After that, hooks and watch mode keep the graph updated. If some files fail to parse, the result has status partial and names them in its summary; the CLI also prints a Warning: line on stderr, and those files keep their previous graph rows. A build that finds no source files warns on stderr and asks whether you are in the project root.

bash
pip install -U code-review-graph     # or: pipx upgrade / uv tool upgrade code-review-graph
code-review-graph doctor             # every copy, MCP entry and hook, and the version each runs
code-review-graph install --dry-run  # see what changes, then run install
code-review-graph build              # once: new file types and fixes reach only re-parsed files

Upgrade every copy you have. The MCP entry, the git and editor hooks and crg-daemon can each run a different one, and once 2.4.0 or later has opened the graph, a 2.3.9 copy refuses it and an older 2.3.x copy can break it. Run install again so the entry and the hooks run the new copy, then restart the editor (and run crg-daemon restart if you use the daemon).

The first command of 2.4.0 or later moves the graph to schema 15. If you use the VS Code extension, it needs version 0.4.0 to read that graph. Full list: upgrade notes.

How It Works

The repository is parsed into ASTs with Tree-sitter and stored as a graph of nodes (functions, classes, imports) and edges (calls, inheritance, test coverage). At review time the graph is queried for the smallest set of files the assistant needs to read.

How the assistant uses the graph: the user asks for a review, the assistant calls MCP tools, the graph returns blast radius and risk scores, the assistant reads only the affected files
Architecture pipeline: Repository to Tree-sitter parser to SQLite graph to blast radius to minimal review set

Blast-radius analysis

When a file changes, the graph traces every caller, dependent and test that could be affected. The assistant reads those files instead of scanning the whole project.

Blast radius: a change to login() propagates to callers, dependents, and tests

Incremental updates

Editor hooks, git hooks (pre-commit, post-checkout, post-merge, post-rewrite) and watch mode trigger incremental updates. The hooks update quietly; on each commit the pre-commit hook prints only the short review from detect-changes --brief. The update diffs changed files, finds their dependents through the graph's import and call edges, and re-parses only the files whose SHA-256 hash changed. On a ~3,000-file project (django) a two-file edit re-indexes in about 2.5 seconds on the path the hooks use, of which ~1.4 s is process start-up; a no-op update costs only that start-up. See Incremental update latency.

Incremental update flow: a hook or watch update triggers a git diff, dependents are found through graph edges, and only files whose SHA-256 hash changed are re-parsed

Whole codebase or targeted answer?

Instead of feeding a whole corpus to the model, the graph returns a slice shaped to the question. In the 2026-08-02 capture of this repository at 84bde354, 208,821 source tokens became ~3,190 tokens per question. The repository has grown a lot since that snapshot, so both numbers are larger today.

code-review-graph at the 84bde354 snapshot: 208,821 source tokens funnel down to ~3,190 token graph responses, about 65x fewer tokens per question

Language coverage and notebooks

Language coverage by category: Web, Backend, Systems, Mobile, Scripting, Shells, Domain, Config and Other, plus Jupyter and Databricks notebooks

The parser extracts functions, classes, imports, call sites, inheritance and tests, using Tree-sitter where a grammar exists and targeted fallbacks elsewhere. Supported: Python, JavaScript/TypeScript/TSX (including .mjs, .cjs, .mts and .cts), Go, Rust, Java, C/C++, C#, VB.NET, Ruby, Kotlin (.kt, .kts), Swift, PHP, Scala, Solidity, Dart, R, Perl, Lua/Luau, Objective-C, shell scripts, Elixir, Zig, PowerShell, Julia, ReScript, GDScript, Nix, Verilog/SystemVerilog, SQL/PL/SQL (Oracle) and dbt models, Terraform/OpenTofu (.tf, and Terraform blocks in .hcl files; an .hcl file with no Terraform blocks keeps only a file node), Ansible YAML (playbooks, roles, tasks), Spring Boot application config (application.properties, application.yml, application.yaml and their application-<profile> variants; key names and value types only, never values), value-free generic YAML structure (translation files in folders such as locales/ become file nodes only), XSLT stylesheets (.xsl, .xslt), value-free JSON structure (.json; translation, test, docs, example and data files keep only a file node, and lock files are skipped), Vue/Svelte SFCs, HTML pages (.html, .htm; inline scripts, plus div, section and article blocks with an id as DocSection nodes), Astro files (parsed with the TypeScript grammar), Jupyter and Databricks notebooks (.ipynb, plus Databricks .py exports), Perl XS files (.xs), Robot Framework files (.robot, .resource), and Liquid templates (.liquid). Other .properties files are not treated as source code.

PHP projects also get repository-bounded Composer PSR-4 resolution, Blade template references, and Laravel Route and Eloquent edges when the source shows explicit framework imports, model inheritance and receiver evidence. Static Laravel routes in routes/*.php emit Endpoint nodes and controller HANDLES edges, including literal group prefixes.

Java projects get Spring dependency-injection call resolution, request endpoints and WebFlux routes, scheduled triggers, application-event publisher-to-listener edges, Spring AOP advice-to-target edges, and Temporal workflow and activity edges. Each resolver runs after the parse and needs the injected field, published event or workflow stub to be visible in the repository.

Add your own language

If your repository uses a language the parser does not cover, add a languages.toml to .code-review-graph/ that maps file extensions to any grammar bundled in tree_sitter_language_pack, plus the node types for functions, classes, imports and calls:

toml
[languages.erlang]
extensions = [".erl"]
grammar = "erlang"
function_node_types = ["function_clause"]
class_node_types = ["record_decl"]
import_node_types = ["import_attribute"]
call_node_types = ["call"]

The generic tree-sitter walker does the extraction. Built-in languages cannot be overridden. See docs/CUSTOM_LANGUAGES.md for the schema, validation rules and a worked example.

Risk-scored PR reviews in CI (GitHub Action)

The same analysis runs as a composite GitHub Action. The graph is built and queried on your CI runner; no source code is sent to an external service. On each pull request the action posts one sticky comment with risk-scored functions, affected execution flows and test gaps, updated in place on every push. The optional fail-on-risk input turns it into a merge gate. The optional details input adds more graph context, folded away and capped in size: why each top symbol scored what it did, the communities, hubs and cross-boundary links the change touches, its impact radius, its untested hotspots, and where the graph came from.

yaml
# .github/workflows/code-review-graph.yml
on:
  pull_request:

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: tirth8205/code-review-graph@v2.4.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

See docs/GITHUB_ACTION.md for inputs, risk levels and caching, or the workflow this repository runs on itself in .github/workflows/pr-review.yml.


Benchmarks

The median per-question token reduction across the 6 repositories is about 63x (whole-corpus baseline vs graph query). The 358x maximum is one repository (fastapi, the largest corpus), not the typical result.

Benchmarks across 6 repositories: ~63x median per-question token reduction (358x max), 0.69 average impact F1 against graph-derived ground truth

All numbers come from the evaluation runner against 6 open-source repositories (13 commits). Every config pins an upstream SHA, Leiden runs with a fixed seed, and embeddings are deterministic on CPU, so two runs on different machines produce the same numbers. The reproduction recipe is in docs/REPRODUCING.md. A weekly report-only run on the two smallest configs lives in .github/workflows/eval.yml.

For a typical agent question ("how does authentication work", "what is the main entry point", and so on), the graph returns ~2,200 to 3,900 tokens of search hits plus neighbour edges instead of every source file. The table averages the 5 sample questions defined in code_review_graph/token_benchmark.py.

RepoSnapshot SHAnaive_corpus_tokensavg graph_tokensReduction
fastapi22381558948,7932,653357.6x
flaska29f88ce143,5942,19665.4x
code-review-graph84bde354208,8213,19065.5x
gin5c00df8a166,8682,76660.3x
httpxb55d4635142,3562,66153.5x
expressb4ab7d65136,0523,93634.6x

Captured 2026-08-02 from clean clones at the pinned SHAs (crg 2.3.7, local all-MiniLM-L6-v2 embeddings). These numbers are lower than the 2026-05-25 capture they replace: node embedding text became richer, so avg graph_tokens rose in every repo. fastapi is measured at its current pin 22381558 rather than the retired 0227991a.

The Reduction column is naive_corpus_tokens / avg graph_tokens, so it divides out from the two columns beside it. The benchmark's own average_reduction_ratio averages the five per-question ratios instead, which always reads higher; those per-question figures are in docs/REPRODUCING.md.

The code-review-graph row is a snapshot, not a current measurement. The repository has grown since 84bde354, so its corpus and graph are both much larger today.

The whole-corpus baseline is an upper bound no real agent pays; an agent greps for identifiers and reads the best-matching files. The agent_baseline eval benchmark measures that case (a pure-Python grep over the corpus, top-3 files by match count, token-counted against the graph query cost). Against that realistic baseline the median across 18 questions on 6 repositories is 6.65x (mean 14.8x, range 4.2x to 72.6x), captured 2026-09-22, before search and this baseline began ranking test files lower, so code-review-graph eval --benchmark agent_baseline --embed now gives different numbers until the capture is redone. The full table is in docs/REPRODUCING.md, under "Canonical capture, 2026-09-22".

The ratio tracks repository size, because the graph answer stays flat (2,432 to 4,021 tokens across every repo measured) while the grep baseline grows with the corpus: 4.5x on express, 52x on fastapi. Both figures measure retrieval cost, the tokens needed to locate an answer. An agent that then opens the files the graph named pays the graph on top of its usual reads rather than instead of them; semantic_search_nodes_tool(include_source=True) returns the code with the locations so it does not have to, and measuring that path end-to-end is open work.

The formal token_efficiency benchmark measures a different scenario, the full get_review_context() JSON against only the changed-file content of a commit, and reports ratios below 1 for small commits because the response carries impact-radius edges and source snippets. The two benchmarks answer different questions; see docs/REPRODUCING.md.

Review and impact tools attach a compact context_savings estimate to their responses. The CLI shows the same figures in the Token Savings panel (see Usage below) and --verify compares them with OpenAI's cl100k_base tokenizer. Calibration across 222 sample files puts the estimate within about 1% of real tokens in aggregate (data).

Blast-radius analysis recovers every file in the ground truth on all 13 evaluation commits. Read that as an upper bound, not as "100% recall": the ground truth (changed files plus files with call or import edges into them) comes from the same graph the predictor traverses. The lower precision is deliberate; flagging an extra file costs less than missing a broken dependency.

RepoCommitsAvg F1Avg PrecisionRecall (graph-derived upper bound)
httpx20.8630.7851.0
code-review-graph20.7340.5841.0
fastapi20.6970.5391.0
express20.6670.5001.0
flask20.6330.4851.0
gin30.6090.4391.0
Average130.6930.5461.000

This table is from the 2026-08-02 capture, taken before the path fix described below. That bug also kept real neighbour files out of the graph-derived ground truth, so these numbers will change when the benchmark is re-run.

The benchmark also runs a co-change mode: the predictor is seeded with one changed file and graded against the other files the author touched in the same commit, which is evidence from git history rather than from the graph. Both modes appear in the result CSVs (ground_truth_mode column). In the 2026-08-02 capture co-change mode returned predicted_files = 0 on every graded commit, code seeds included (for example code_review_graph/cli.py and gin's context.go). The cause was a path bug in the benchmark: git diff gives repo-relative paths, the graph stores absolute ones, so the seed never matched a node. That bug is now fixed, but the benchmark has not been re-run yet, so no co-change number is quoted.

From the same 2026-08-02 clean-room build at the pinned SHAs above. Embedding counts are lower than node counts because File nodes are not embedded. The code-review-graph row is that snapshot, not the repository as it stands now.

RepoNodesEdgesEmbeddings
fastapi6,28732,0365,159
express1,99019,4921,849
gin1,58917,2371,491
code-review-graph1,4469,0941,354
flask1,4158,2591,329
httpx1,2638,2361,193

Limitations

  • Impact "recall 1.0" is circular. The historical ground truth comes from the same graph edges the predictor walks, so it is an upper bound by construction. Co-change numbers are not quoted until the benchmark is re-run with the path fix.
  • Small single-file changes. Graph context can exceed a plain file read for trivial edits. The overhead is the structural metadata that makes multi-file analysis possible.
  • Search ranking. Keyword search usually finds the right result near the top, but ranking needs work. Express queries can return no hits because of module-pattern naming.
  • Flow detection. Entry-point detection is strongest for Python and PHP/Laravel. JavaScript and Go flow detection needs work.
  • Precision vs recall. Impact analysis is conservative. It flags files that might be affected, which means false positives in large dependency graphs.

Features

Updates, impact analysis, search, visualisation, CI reviews, refactoring and multi-repo support, all kept on your machine.

FeatureDetails
Incremental updatesRe-parses only files whose hash changed. On a ~3,000-file repo a two-file edit takes ~2.5 s on the hook path (measured).
Language and notebook supportSee Language coverage above.
Framework-aware PHP parsingRepository-bounded Composer PSR-4 imports, Blade template references, evidence-gated Laravel Route-to-controller and Eloquent relationship edges
Framework-aware Java parsingSpring dependency-injection call resolution, request endpoints and WebFlux routes, scheduled triggers, application-event publisher-to-listener edges, Spring AOP advice edges, Temporal workflow and activity edges, and Spring Boot config keys indexed without their values
Blast-radius analysisWhich functions, classes and files are likely affected by a change
Auto-update hooksEditor hooks, git hooks (before each commit, after checkout, merge and rebase) and watch mode update the graph as you work
Semantic searchOptional vector embeddings via sentence-transformers, Google Gemini, MiniMax, Voyage AI, or any OpenAI-compatible endpoint
Interactive visualisationD3.js force-directed graph with search, community legend toggles and degree-scaled nodes, plus a neighbourhood view seeded from a symbol, file, flow or change
Hub and bridge detectionMost-connected nodes and chokepoints (betweenness centrality)
Surprise scoringUnexpected coupling: cross-community, cross-language, peripheral-to-hub edges
Knowledge gap analysisIsolated nodes, untested hotspots, thin communities, import cycles
Suggested questionsReview questions generated from bridges, hubs and surprises
Edge confidenceFour tiers (EXTRACTED, INFERRED, AMBIGUOUS, UNRESOLVED) with float scores on edges, so a call the graph could not bind says so
Graph traversalBFS/DFS from any node with configurable depth and token budget; path_to shows how one symbol reaches another and names the weakest hop
Export formatsGraphML, Neo4j Cypher, Obsidian vault, JSON, and SVG (SVG needs matplotlib from the eval extra)
Token benchmarkingcode_review_graph/token_benchmark.py measures whole-corpus tokens against graph query tokens per question
Estimated context savingscontext_savings metadata (estimated, saved_tokens, saved_percent) on review, impact, detect-changes and architecture responses
Community auto-splitCommunities above 25% of the graph are split recursively with Leiden
Execution flowsCall chains from entry points, sorted by weighted criticality
Community detectionLeiden clustering with resolution scaled to graph size
Architecture overviewCommunity-based architecture map with coupling warnings
Risk-scored reviewsdetect_changes maps diffs to affected functions, YAML and JSON paths, flows and test gaps
Custom languagesNew languages via .code-review-graph/languages.toml, no fork needed
GitHub ActionSticky risk-scored PR review comments in CI, with an optional fail-on-risk merge gate
Refactoring toolsRename preview, framework-aware dead code detection, community-driven suggestions
Wiki generationMarkdown wiki from community structure
Multi-repo registryRegister several repos and search across them
Multi-repo daemoncrg-daemon watches several repos as child processes, with health checks and restart
MCP prompts5 workflow templates: review, architecture, debug, onboard, pre-merge
Full-text searchFTS5 hybrid search combining keyword and vector similarity
Local storageOne SQLite file in .code-review-graph/; no external database or cloud service

Usage

Your assistant uses the graph by itself once it is built. Open a part below for skills, commands, MCP tools and settings.

install writes these four skills for the platforms it sets up that support them (Claude Code, Gemini CLI, CodeBuddy Code, Hermes Agent and Qoder). Ask for one by name.

SkillDescription
explore-codebaseNavigate and understand codebase structure using the knowledge graph
review-changesPerform a structured code review using change detection and impact
debug-issueSystematically debug issues using graph-powered code navigation
refactor-safelyPlan and execute safe refactoring using dependency analysis

Qoder also gets build-graph, review-delta and review-pr from the repository's skills/ directory.

bash
code-review-graph install          # Set up the AI coding tools found on this machine
code-review-graph install --platform <name>  # One platform
code-review-graph install --steering  # Claude Code: graph context beside each search and read
code-review-graph uninstall --dry-run  # Preview removal of installed artifacts
code-review-graph doctor           # Check copies, MCP entries, graph and hooks; changes nothing
code-review-graph build            # Parse the whole codebase
code-review-graph build --follow-symlinks  # Also index symlinked folders
code-review-graph update           # Incremental update (changed files only)
code-review-graph status           # Graph statistics
code-review-graph watch            # Update on file changes
code-review-graph forget <path>    # Drop already-parsed files from the graph
code-review-graph dead-code        # Functions and classes with no callers or tests
code-review-graph query path_to <from> --to <to>  # How one symbol reaches another
code-review-graph impact --detail-level compact  # Blast radius as ranked file paths
code-review-graph visualize        # Interactive HTML graph
code-review-graph visualize --seed-symbol <name>  # Neighbourhood of one symbol
code-review-graph visualize --format json      # Export graph data as JSON
code-review-graph visualize --format graphml   # Export as GraphML
code-review-graph visualize --format svg       # Export as SVG (needs matplotlib)
code-review-graph visualize --format obsidian  # Export as Obsidian vault
code-review-graph visualize --format cypher    # Export as Neo4j Cypher
code-review-graph wiki             # Markdown wiki from communities
code-review-graph detect-changes --brief         # Top 3 to review, risk + token savings (read-only)
code-review-graph detect-changes --brief --base main  # Against the merge base of main and HEAD
code-review-graph update --brief                 # Refresh graph + same panel
code-review-graph detect-changes --brief --verify  # Cross-check against tiktoken
code-review-graph detect-changes --details all  # Add graph context to the JSON
code-review-graph context-history  # Trend of the opt-in savings log (CRG_CONTEXT_HISTORY=1)
code-review-graph register <path>  # Register repo in the multi-repo registry
code-review-graph unregister <path|alias>  # Remove repo from the registry
code-review-graph repos            # List registered repositories
code-review-graph daemon start     # Start the multi-repo watch daemon
code-review-graph daemon stop      # Stop the daemon
code-review-graph daemon status    # Daemon status and repos
code-review-graph eval --all       # Run every evaluation benchmark
code-review-graph serve            # Start the MCP server (stdio)
code-review-graph serve --http     # MCP over Streamable HTTP on localhost:5555
code-review-graph serve --http --multi-repo  # One HTTP server for every registered repo
code-review-graph serve --multi-worktree  # One child server per linked Git worktree

This is a selection. code-review-graph with no command lists every command, in groups, and docs/COMMANDS.md documents their flags. A mistyped command exits 2 and suggests the closest one.

When detect-changes --base names a branch, the diff runs against the merge base of that branch and HEAD. Commit hashes and other revisions are used as given. A base git does not know stops with exit code 1 and says how to check it. In a repository with one commit or none, the default base reviews uncommitted and new files instead, and says so.

visualize --format svg needs matplotlib, which ships in the eval extra (pip install "code-review-graph[eval]"). The other export formats need no extra install.

JSON exports are written inside the local graph data directory, which Git ignores by default. They can contain absolute paths and code-structure metadata, so inspect an export before publishing it.

Both commands print the same panel showing how many tokens the graph saved compared with handing the changed files to an agent raw. They differ in one thing: whether the graph is refreshed first. Above the panel, detect-changes --brief also lists up to three things to review first, each with its file and line, its risk out of 1.00, its callers and its tests.

text
┌─────────────────────── Token Savings ────────────────────────┐
│ Full context would be:     12,921 tokens                     │
│ Graph context used:           762 tokens                     │
│ Saved:                     12,159 tokens (~94%)              │
│ Breakdown: Functions 244 · Tests 191 · Risk 244 · Other 83   │
└──────────────────────────────────────────────────────────────┘
CommandWhat it doesWhen to use
detect-changes --briefRead-only. Queries the existing graph for the current changes and prints the panel.Most of the time; hooks or crg-daemon keep the graph fresh.
update --briefRe-parses the changed files into the graph first, then prints the same panel.After a rebase, a large change set, or whenever the graph may be stale.

Add --verify to either command to compare the figures with OpenAI's cl100k_base tokenizer (needs pip install tiktoken). The estimate is within about 1% of real tokens in aggregate; see docs/REPRODUCING.md.

The same context_savings metadata is attached to the JSON responses of the get_impact_radius, get_review_context, detect_changes and get_architecture_overview MCP tools.

To see these estimates over time, set CRG_CONTEXT_HISTORY=1 (off by default). Each estimate then adds one line to a local log next to graph.db, holding token counts, tool names, a timestamp, a detail level and file and depth counts, never file names, paths or source text, and code-review-graph context-history prints it per day or per tool. See docs/USAGE.md.

If install gives your editor no hooks (for example Windsurf or Zed), or you want the graph kept fresh without editor integration, the daemon watches your repositories and updates their graphs. It ships with code-review-graph; no separate install.

bash
# 1. Register the repos to watch
crg-daemon add ~/project-a --alias proj-a
crg-daemon add ~/project-b

# 2. Start the daemon (runs in the background)
crg-daemon start

# 3. Check on it
crg-daemon status                 # daemon and per-repo watcher status
crg-daemon logs --repo proj-a -f  # tail logs for one repo
crg-daemon stop                   # stop the daemon and all watchers

Also available as code-review-graph daemon start|stop|status|....

crg-daemon add writes to ~/.code-review-graph/watch.toml, which you can also edit directly:

toml
[[repos]]
path = "/home/user/project-a"
alias = "proj-a"

[[repos]]
path = "/home/user/project-b"
alias = "project-b"

The daemon watches this file and starts or stops watcher processes as repos are added or removed. A health check every 30 seconds restarts dead watchers.

See docs/COMMANDS.md for the full config reference.

The assistant uses these once the graph is built. The 25 tools that only read carry readOnlyHint: true, so a client can run them without asking; the five that write (build_or_update_graph_tool, run_postprocess_tool, embed_graph_tool, apply_refactor_tool, generate_wiki_tool) do not.

ToolDescription
build_or_update_graph_toolBuild or incrementally update the graph
run_postprocess_toolRe-run flow detection, community detection and FTS indexing
get_minimal_context_toolCompact context (~100 tokens); call this first
get_impact_radius_toolBlast radius of changed files; detail_level="compact" gives ranked file paths
get_review_context_toolReview context with structural summary
query_graph_toolCallers, callees, tests, imports, inheritance, and path_to between two symbols
traverse_graph_toolBFS/DFS traversal from any node with a token budget
semantic_search_nodes_toolSearch code entities by name or meaning
embed_graph_toolCompute vector embeddings for semantic search
list_graph_stats_toolGraph size and health
get_docs_section_toolRetrieve documentation sections
find_large_functions_toolFunctions, classes or files above a line-count threshold
list_flows_toolExecution flows sorted by criticality
get_flow_toolOne execution flow
get_affected_flows_toolFlows affected by changed files
list_communities_toolDetected code communities
get_community_toolOne community
get_architecture_overview_toolArchitecture overview from community structure
detect_changes_toolRisk-scored change impact analysis
get_hub_nodes_toolMost-connected nodes
get_bridge_nodes_toolChokepoints by betweenness centrality
get_knowledge_gaps_toolStructural weaknesses, untested hotspots and import cycles
get_surprising_connections_toolUnexpected cross-community coupling
get_suggested_questions_toolReview questions generated from the analysis
refactor_toolRename preview, dead code detection, suggestions
apply_refactor_toolApply a previously previewed refactoring
generate_wiki_toolMarkdown wiki from communities
get_wiki_page_toolOne wiki page
list_repos_toolRegistered repositories
cross_repo_search_toolSearch registered repositories; repos limits the search to a subset

MCP prompts (5 workflow templates): review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check

To exclude paths from indexing, create a .code-review-graphignore file in the repository root:

code
generated/**
*.generated.ts
vendor/**
node_modules/**

In git repositories a build reads tracked files plus untracked files git does not ignore (git ls-files and git ls-files --others --exclude-standard), so gitignored files are skipped. Use .code-review-graphignore to exclude other files or when git is not available. The default ignore list is in docs/USAGE.md.

Optional dependency groups:

bash
pip install "code-review-graph[embeddings]"          # Local vector embeddings (sentence-transformers)
pip install "code-review-graph[google-embeddings]"   # Google Gemini embeddings
pip install "code-review-graph[communities]"         # Community detection (igraph)
pip install "code-review-graph[enrichment]"          # Python call resolution with Jedi (then build --enrich)
pip install "code-review-graph[eval]"                # Evaluation benchmarks and SVG export (matplotlib)
pip install "code-review-graph[wiki]"                # ollama client (not used by the current wiki generator)
pip install "code-review-graph[all]"                 # All optional dependencies

Environment Variables

VariableDescriptionDefault
CRG_GIT_TIMEOUTTimeout in seconds for Git operations (build, update, watch)30
CRG_DISCOVERY_TIMEOUTTimeout in seconds for each Git command that discovers what changed, when a review tool or command was not given an explicit file list. Running out reports an error, never "no changes"5, or CRG_GIT_TIMEOUT when you set that explicitly
CRG_DATA_DIRDirectory for graph databases and generated artefacts. install's record of the files it wrote stays in .code-review-graph/ in the repository-
CRG_HOMEFolder for per-user state: the multi-repo registry (registry.json), the daemon's watch.toml, its pid and state files, and logs/~/.code-review-graph
CRG_HOOK_WORKTREESSet to 1 to let the generated git hooks run in linked git worktrees-
CRG_EMBEDDING_MODELDefault model for local vector embeddingsall-MiniLM-L6-v2
CRG_ACCEPT_CLOUD_EMBEDDINGSSet to 1 to suppress the cloud embedding egress warning-
CRG_ALLOW_REMOTE_CODEAllow HuggingFace models that require trust_remote_code=True0
CRG_VECTOR_CACHESet to 1 to keep the decoded embedding vectors in memory between semantic searches instead of reading them all back from SQLite on every query. Costs RAM (vectors × dimensions × 4 bytes per cached index) and one open read connection per cached database for the life of the process: on Windows, graph.db cannot be deleted or replaced while it is open-
CRG_MAX_IMPACT_NODESMaximum nodes in impact analysis500
CRG_MAX_IMPACT_DEPTHSearch depth for blast-radius analysis2
CRG_MAX_BFS_DEPTHMaximum depth for graph traversal15
CRG_MAX_CHANGED_FUNCSMaximum changed functions analysed in one change report500
CRG_MAX_DELETION_FILESMaximum files whose old version is read in one change report, to name the functions and classes a diff deleted100
CRG_MAX_CHANGED_YAML_PATHSMaximum changed YAML paths analysed in one change report, and separately the same number of JSON paths200
CRG_MAX_TRANSITIVE_FRONTIERMaximum callees followed per hop when tests_for and detect-changes look for tests. The first by name are kept, so one graph always gives one answer50
CRG_CALLER_TEST_ROUTE_DEPTHHops to walk up incoming CALLS when looking for a tested caller of an untested changed symbol. Reported as a note, never as coverage2
CRG_CALLER_TEST_ROUTE_MAX_CALLERSMaximum callers examined while looking for that tested caller500
CRG_TOOL_TIMEOUTTimeout in seconds for read-only MCP tools (0 disables). Does not bound the tools that write: build, postprocess, embed, wiki and apply-refactor0
CRG_CHURN_WINDOW_DAYSWindow for detect-changes --churn commit counts90
CRG_CONTEXT_HISTORYSet to 1 to keep a local log of each context_savings estimate in .code-review-graph/context-history.jsonl; read it with code-review-graph context-history. Holds token counts, tool names, a timestamp, a detail level and file and depth counts, never file names, paths or source text, and is never sent anywhere-
CRG_LEIDEN_SEEDSeed for Leiden community detection42
CRG_RECURSE_SUBMODULESInclude git submodules when set to 1, true or yes-
CRG_FOLLOW_SYMLINKSFollow symlinked folders, inside or outside the repository, when set to 1, true, yes or on; same as --follow-symlinks. See Symlinked folders-
CRG_MAX_FOLLOWED_FILESMost files taken through followed symlinked folders10000
CRG_TOOLSComma-separated allowlist of MCP tools to expose when serving-
CRG_READ_ONLYSet to 1 (or true, yes, on) to open the graph read-only. Nothing in the data folder is created, upgraded or logged, and commands that write fail. The Codex skill's read-only CLI sets it-
CRG_BINThe code-review-graph program the Codex skill's read-only CLI runs, when it has another name or is not on PATHthe one on PATH
GOOGLE_API_KEYAPI key for Google Gemini embeddings-
MINIMAX_API_KEYAPI key for MiniMax embeddings-
VOYAGE_API_KEYAPI key for Voyage embeddings-
CRG_VOYAGE_MODELModel for Voyage embeddingsvoyage-code-3
CRG_VOYAGE_OUTPUT_DIMENSIONOutput dimension for Voyage embeddings1024
CRG_VOYAGE_OUTPUT_DTYPEOutput dtype for Voyage embeddingsfloat
CRG_VOYAGE_BASE_URLVoyage embeddings endpointhttps://api.voyageai.com/v1
CRG_VOYAGE_BATCH_SIZEBatch size for Voyage requests100
CRG_VOYAGE_MIN_INTERVAL_SECMinimum delay between Voyage requests0
CRG_OPENAI_BASE_URLOpenAI-compatible embeddings endpoint-
CRG_OPENAI_API_KEYAPI key for OpenAI-compatible embeddings-
CRG_OPENAI_MODELModel for OpenAI-compatible embeddings-
CRG_OPENAI_DIMENSIONPin the embedding dimension (v3 models support reduction)-
CRG_OPENAI_BATCH_SIZEBatch size for OpenAI-compatible requests100
NO_COLORDisable ANSI colours in the terminal-
CRG_SERIAL_PARSESet to 1 to disable parallel parsing (for debugging)-
CRG_ENABLE_ENRICHMENTSet to 1 to resolve Python method calls with Jedi on every build and update (needs the enrichment extra; about a second more per Python file). Same as build --enrichoff
CRG_DISABLE_ENRICHMENTSet to 1 to never run Jedi, even when asked for-

OpenAI-compatible embeddings need no extra install. Set the variables and pass provider="openai" to embed_graph:

bash
export CRG_OPENAI_BASE_URL=http://127.0.0.1:3000/v1     # or https://api.openai.com/v1
export CRG_OPENAI_API_KEY=sk-...
export CRG_OPENAI_MODEL=text-embedding-3-small          # whatever your gateway serves
# optional:
export CRG_OPENAI_DIMENSION=1536                        # pin dim (v3 models support reduction)
export CRG_OPENAI_BATCH_SIZE=100                        # lower for gateways with tight limits

The cloud-egress warning is skipped when the base URL points at localhost (127.0.0.1, localhost, 0.0.0.0, ::1).

Voyage embeddings need no extra install. Set VOYAGE_API_KEY and pass provider="voyage" to embed_graph; the default model is voyage-code-3:

bash
export VOYAGE_API_KEY=pa-...
export CRG_ACCEPT_CLOUD_EMBEDDINGS=1
code-review-graph embed --provider voyage --model voyage-code-3

Model selection. Avoid -preview, -beta or -exp model IDs for an index you plan to keep; preview models can change weights (a different dimension forces a full re-embed) or be withdrawn. Prefer GA releases such as text-embedding-3-small / text-embedding-3-large (OpenAI) or gemini-embedding-001 (native Gemini provider, which needs GOOGLE_API_KEY).

The embedding text is identifiers, signatures, structural context, and a bounded first-paragraph docstring or doc-comment summary. Function bodies are not sent. Graphs created before documentation extraction was added need one full code-review-graph build before re-embedding. Routine builds never refresh embeddings; to refresh after a build, pass both --embedding-provider and --embedding-model. Cloud providers receive this source-derived text and may charge for it.

Tool Filtering

CRG exposes 30 MCP tools by default. To limit the server to a subset, use --tools or the CRG_TOOLS environment variable:

bash
# CLI flag
code-review-graph serve --tools query_graph_tool,semantic_search_nodes_tool,detect_changes_tool

# Environment variable
CRG_TOOLS=query_graph_tool,semantic_search_nodes_tool code-review-graph serve

The flag takes precedence over the variable. When neither is set, all tools are available. In an MCP client config:

json
{
  "mcpServers": {
    "code-review-graph": {
      "command": "code-review-graph",
      "args": ["serve", "--tools", "query_graph_tool,semantic_search_nodes_tool,detect_changes_tool,get_review_context_tool"]
    }
  }
}

Run with Docker or Podman

No image is published. Build one from a release tag; a plain clone gives the staging branch, which can hold changes not yet released:

bash
git clone --branch v2.4.0 https://github.com/tirth8205/code-review-graph.git
cd code-review-graph
docker build -t code-review-graph:local .

From the repository you want to analyse, run:

bash
docker run --rm \
  --user "$(id -u):$(id -g)" \
  --env HOME=/tmp \
  --volume "$PWD:/workspace" \
  code-review-graph:local build

The mounted repository must be writable. The command above uses your user and group IDs so the generated .code-review-graph/ directory remains owned by your user. Run these commands as a non-root host user.

For Podman, build the same Dockerfile from the same clone and preserve your user mapping:

bash
podman build -t code-review-graph:local .
podman run --rm \
  --userns=keep-id \
  --env HOME=/tmp \
  --volume "$PWD:/workspace" \
  code-review-graph:local build

The graph persists in .code-review-graph/ in the mounted repository and stores absolute container paths such as /workspace/app.py. Run update and detect-changes through Docker or Podman with the same /workspace mount. A host update on this graph can fail with "built with a different repository root". To switch to host commands, run code-review-graph build on the host to rebuild the graph with host paths.

Replace build with status to inspect the saved graph. The image includes Git and defaults to a non-root user. No graph is generated during image construction.

These examples use macOS/Linux shell syntax. On macOS, start your Docker-compatible engine or Podman machine before running them. On a host with SELinux on, such as Fedora, add :z to the mount ("$PWD:/workspace:z"), or the container is refused access to the repository.


FAQ and comparisons

Answers in docs/FAQ.md:

Troubleshooting

Start with code-review-graph doctor, above all when your AI tool says the graph was "written by a newer code-review-graph". It lists every copy on PATH, the version each MCP entry and hook runs, and the state of the graph. It changes nothing, exits 1 when a check fails, and takes --json.

More cases, including Windows/WSL, are in docs/TROUBLESHOOTING.md.

pip / pipx cannot download hatchling (or Errno 9 / Bad file descriptor to PyPI)

Installing from a source tree (for example pipx install .) needs build dependencies from PyPI. If you see Could not find a version that satisfies the requirement hatchling after connection warnings, the Python in that terminal may not be able to open an HTTPS connection to pypi.org. This is seen most often in an editor's integrated terminal, and sometimes with a VPN, firewall or proxy.

  1. 1Run the same command from a terminal outside the editor, such as Terminal.app.
  2. 2Install from a checkout with [uv](https://docs.astral.sh/uv/), which uses different download machinery: cd /path/to/code-review-graph uv tool install . --force
  3. 3For development in a clone, use `uv sync` and `uv run code-review-graph ...`.

To diagnose: python3 scripts/diagnose_pypi_connectivity.py. If it prints FAILED, the problem is the network environment, not the package name.

Windows: Invalid JSON: EOF while parsing or MCP error -32000: Connection closed

Do not use a cmd /c wrapper in the Claude Code config. Point ~/.claude.json at the .exe directly and set UTF-8 through the config:

json
"code-review-graph": {
  "command": "C:\\path\\to\\your\\venv\\Scripts\\code-review-graph.exe",
  "args": ["serve", "--repo", "C:\\path\\to\\your\\project"],
  "env": { "PYTHONUTF8": "1" }
}

Contributing

Pull requests target staging (the default branch). Changes are promoted staging → testing → main, and releases are tagged from main. No promotion is automatic: a person reviews and merges each one. See CONTRIBUTING.md for the full flow.

bash
git clone https://github.com/tirth8205/code-review-graph.git
cd code-review-graph
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest

To add a built-in language, edit code_review_graph/parser.py: add the extension to EXTENSION_TO_LANGUAGE and node type mappings to _CLASS_TYPES, _FUNCTION_TYPES, _IMPORT_TYPES and _CALL_TYPES. Include a test fixture and open a PR. For a language you only need in one repository, use languages.toml instead.

Licence

MIT. See LICENSE.

#ai-coding#claude#claude-code#code-review#graphrag#incremental#knowledge-graph#llm#mcp#python#static-analysis#tree-sitter