# CodeGraph：给 Codex 和 Claude Code 一份本地代码调用图

**URL:** <https://www.sunai.net/t/topic/1595>\
**Category:** IT\
**Tags:** 开源, ai, 开发, mcp\
**Created:** [2026 年11 月 26 日 11:33 UTC](https://www.sunai.net/t/topic/1595 "2026-11-26T11:33:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Logos](https://www.sunai.net/user_avatar/www.sunai.net/logos/32/2077_2.png) [@Logos](https://www.sunai.net/u/Logos)\
发布日期： [2026 年11 月 26 日 11:33 UTC](https://www.sunai.net/t/topic/1595/1 "2026-11-26T11:33:05Z")

</div>

## 接手大仓库，先弄清楚谁在调用谁

让 Codex 改一个公共函数，难的往往不是改那几行，而是先找到上游入口：谁在调用它？请求是从哪个 handler 进来的？名字能用 `rg` 找，调用链通常还得顺着几份文件拼。CodeGraph 给仓库建一份本地索引，让 Codex、Claude Code 之类的助手能通过 MCP 直接查这些关系。

它用 Tree-sitter 解析源代码，把函数、类等符号，以及调用、导入、继承关系存进项目目录下的 `.codegraph/codegraph.db`。源文件有变动时，文件监听会触发增量同步。适合先问「这段逻辑在哪、改动可能波及哪几处」，再打开对应文件看实现。

![CodeGraph 的终端演示](https://i.czl.net/r2/original/2X/6/63f3a3a01746222104e2f6e8ef993719ac5a0f23.gif)

## 拿一个熟悉的仓库试试

已经有 npm 的话，可以这样装。前两行安装并配置编码助手的 MCP；后两行在要分析的仓库根目录运行，每个仓库单独建索引。

```bash
npm i -g @colbymchenry/codegraph
codegraph install
codegraph init
codegraph status

```

可以找一个自己知道答案的问题来试，比如「订单创建从哪个 HTTP handler 进来？最后在哪个函数写入数据库？给出文件路径」。重点看它能不能找对入口和中间层。静态索引不等于运行时调用记录，遇到复杂的动态分派，还是要回源码或用测试确认。

源码索引留在本地。CodeGraph 有单独的匿名使用统计，安装时会询问，也可以用 `codegraph telemetry off` 关闭。编码助手是否把读到的上下文发给模型，则取决于助手本身的配置。

## 项目信息

- 语言：TypeScript，核心解析器包含 Rust 实现
- 许可证：MIT
- GitHub Stars：截至 2026-11-26 约 7.9 万
- GitHub：[GitHub - colbymchenry/codegraph: Pre-indexed code knowledge graph, auto syncs on code changes, for Claude Code, Codex, Gemini, Cursor, OpenCode, AntiGravity, Kiro, CoPilot, and Hermes Agent — fewer tokens, fewer tool calls, 100% local · GitHub](https://github.com/colbymchenry/codegraph)
- 官网：[codegraph — Understand any codebase as a graph](https://colbymchenry.github.io/codegraph/)
