OpenSource-Hub

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

常见问题 (4)

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

是的,从版本0.9.4开始,当MCP服务器运行时,Codegraph会在每次文件变更时自动同步。它使用内置的FileWatcher,在大约3秒内增量重新索引符号和边,无需手动执行codegraph synccodegraph 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
操作指南
如何将默认的CodeGraph索引目录从.codegraph更改为自定义路径?

在运行CodeGraph时使用--data-dir标志来指定自定义索引目录。示例:codegraph --data-dir /path/to/custom/dir。此功能正在通过PR #568添加。

来源 Issue #672