codegraph

命令行工具

colbymchenry/codegraph

预索引的代码知识图谱,提升Claude Code效率。

项目简介

CodeGraph 为代码库构建预索引知识图谱,使 Claude Code 的探索代理无需扫描文件即可快速查询符号关系。支持 19 种以上语言和框架路由识别,完全本地运行,可减少高达 96% 的工具调用并提升 70% 以上的探索速度。

README 预览

\n\n# CodeGraph\n\n### Supercharge Claude Code with Semantic Code Intelligence\n\n**94% fewer tool calls · 77% faster exploration · 100% local**\n\n[](https://www.npmjs.com/package/@colbymchenry/codegraph)\n[](https://opensource.org/licenses/MIT)\n[](https://nodejs.org/)\n\n[](#)\n[](#)\n[](#)\n\n\n\n### Get Started\n\n```bash\nnpx @colbymchenry/codegraph\n```\n\nInteractive installer configures Claude Code automatically\n\n#### Initialize Projects\n\n```bash\ncd your-project\ncodegraph init -i\n```\n\n\n\n\n\n---\n\n## Why CodeGraph?\n\nWhen Claude Code explores a codebase, it spawns **Explore agents** that scan files with grep, glob, and Read — consuming tokens on every tool call.\n\n**CodeGraph gives those agents a pre-indexed knowledge graph** — symbol relationships, call graphs, and code structure. Agents query the graph instantly instead of scanning files.\n\n### Benchmark Results\n\nTested across 6 real-world codebases comparing Claude Code's Explore agent **with** and **without** CodeGraph:\n\n> **Average: 92% fewer tool calls · 71% faster**\n\n| Codebase | With CG | Without CG | Improvement |\n|----------|---------|------------|-------------|\n| **VS Code** · TypeScript | 3 calls, 17s | 52 calls, 1m 37s | **94% fewer · 82% faster** |\n| **Excalidraw** · TypeScript | 3 calls, 29s | 47 calls, 1m 45s | **94% fewer · 72% faster** |\n| **Claude Code** · Python + Rust | 3 calls, 39s | 40 calls, 1m 8s | **93% fewer · 43% faster** |\n| **Claude Code** · Java | 1 call, 19s | 26 calls, 1m 22s | **96% fewer · 77% faster** |\n| **Alamofire** · Swift | 3 calls, 22s | 32 calls, 1m 39s | **91% fewer · 78% faster** |\n| **Swift Compiler** · Swift/C++ | 6 calls, 35s | 37 calls, 2m 8s | **84% fewer · 73% faster** |\n\n\nFull benchmark details\n\nAll tests used Claude Opus 4.6 (1M context) with Claude Code v2.1.91. Each test spawned a single Explore agent with the same question.\n\n**Queries used:**\n| Codebase | Query |\n|----------|-------|\n| VS Code | "How does the extens

常见问题 (5)

feature_inquiry
Codegraph 是否会在代码更改后自动同步?

是的,从版本0.9.4开始,当MCP服务器运行时,Codegraph会在每次文件变更时自动同步。它使用内置的FileWatcher,在大约3秒内增量重新索引符号和边,无需手动执行codegraph sync或codegraph index命令。在早期版本中,代码变更后需要手动运行codegraph index来更新。

来源 Issue #393
故障排除
为什么通过桶状再导出导入的组件,codegraph 显示调用者为 0?

这是codegraph v0.9.8及更早版本中的一个已知错误,某些桶形格式无法被解析,导致丢失边,并对活动组件产生虚假的0 callers/impact。受影响的格式包括:export { default as X } from './X.svelte'、裸import from './'或from '.',以及工作区包子路径导入(@scope/pkg/sub)。该修复(PRs #657, #659)已合并,将在v0.9.8之后的下一个版本中发布。请升级到最新版本(v0.9.9+)以解决该问题。作为临时检查,可使用codegraph callees <file>查看导入是否显示为原始/未解析节点。

来源 Issue #629
故障排除
为什么在Windows上启动codegraph daemon或切换分支时控制台窗口会闪烁?

升级到codegraph v0.9.7或更高版本。v0.9.6中的这个bug导致git.exe spawns(例如git ls-files、git rev-parse)在没有设置windowsHide: true的情况下运行,使得cmd窗口可见。v0.9.7中的修复为所有git/npm子进程添加了windowsHide,消除了窗口闪烁。

来源 Issue #612
故障排除
为什么在 Windows 上运行 codegraph MCP server 时,控制台窗口每隔一秒就会闪烁一次?

在 Windows 上的 codegraph v1.6.1 中,默认文件监视器大约每秒运行一次 git ls-files。当 MCP 宿主由带有 CREATE_NO_WINDOW 的 GUI 进程启动时,Node.js 在未设置 windowsHide: true 的情况下派生 git.exe,导致 Windows 每次都创建一个可见的 conhost 窗口。作为变通方法,请禁用监视器:

codegraph serve --mcp --no-watch

然后在需要时手动刷新索引:

codegraph sync

永久修复方案是让 watcher/git 的 spawn 调用向 Node.js 的 spawn/exec 传入 windowsHide: true;如有包含该修复的版本,请升级到该版本。

来源 Issue #2467
故障排除
为什么 codegraph 会遗漏 Delphi/Object Pascal 中链式方法调用的调用者和被调用者?

这是 codegraph 1.6.2 中的一个已知 bug:Delphi 提取器对于类似 MD5FileSized(TMeta.ExtendedPath(APath)).IsSame(AKey) 的链式调用,只记录外层方法,而丢弃接收者调用(MD5FileSized)以及其参数内部的调用(ExtendedPath)。该问题已由 PR #2787(已合并到 main)修复,修复后无论是表达式形式还是无括号语句形式,都会索引接收者调用及其参数中的调用,此外还涵盖类型转换接收者,例如 TButton(Sender).Caption。请升级到 1.6.2 之后的版本。作为临时解决方案,可以修补 lib/dist/extraction/tree-sitter.js:在 extractPascalCall 中,在接收者名称处理之后(约第 7317 行)添加 this.extractPascalCall(innerCall);;并在 extractPascalParenlessCall 中,在非类接收者分支(约第 7411 行)添加 if (receiver.type === 'exprCall') this.extractPascalCall(receiver);。

来源 Issue #2547