代码仓库的知识图谱工具 graphify 使用指南
graphify 是一款面向代码仓库的知识图谱生成工具,能够分析项目代码结构、调用关系,生成可视化图谱,并与 AI 编码助手(Claude Code)深度集成,实现智能上下文理解与自动增量更新。
Git 地址
项目 github 地址:https://github.com/safishamsi/graphify
快速上手流程总览
| 步骤 | 操作 | 命令 | 执行频率 |
|---|---|---|---|
| 1 | 安装 graphify | uv tool install graphifyy |
一次 |
| 2 | 初始化 skill | graphify install |
每个项目一次 |
| 3 | 生成知识图谱 | /graphify .(在 AI 助手中) |
首次 |
| 4 | 生成可视化图谱 | graphify export callflow-html |
按需 |
| 5 | 安装 Git Hook | graphify hook install |
每个项目一次 |
| 6 | 配置 .gitignore | 添加忽略规则 | 每个项目一次 |
| 7 | 集成 AI 助手 | graphify opencode install / graphify claude install |
每个项目一次 |
一、安装 graphify
通过以下任一方式安装(优先推荐 uv):
uv tool install graphifyy # 优先使用
pip install graphifyy # 备选
二、初始化 Skill
在项目根目录下执行以下命令,完成 graphify skill 初始化(仅需执行一次):
# 在项目目录下执行
graphify install
三、生成项目知识图谱
在 Claude Code 中执行以下命令,分析整个项目并在根目录生成 graphify-out/ 目录(仅首次需要执行):
# 在 Claude Code 中执行
/graphify .
执行完成后可额外生成供人阅读的可视化 HTML 图谱(可选):
# 在项目目录下执行
graphify export callflow-html
执行完毕后,graphify-out/ 目录内会包含:
- manifest.json — 图谱元数据
- cost.json — 生成成本统计
- cache/ — 增量缓存数据
- gateway-all-callflow.html — 可视化调用流图谱
四、配置 Git Hook(自动增量更新)
安装 Git Hook 后,每次 git commit 时将自动触发图谱增量更新,无需手动重跑。
# 在项目目录下执行
graphify hook install
移除 Hook
graphify hook uninstall
五、配置 .gitignore
将以下内容加入项目的 .gitignore,避免将生成缓存和临时文件提交到仓库:
graphify-out/manifest.json
graphify-out/cost.json
graphify-out/cache/
graphify-out/xxx-all-callflow.html
六、集成到 AI 编码助手
将 graphify 与 Claude Code 集成,使 AI 助手能够利用知识图谱提供更精准的上下文理解(仅首次需要执行)。
集成 CodeMaker
# 在项目目录下执行
# 会在 AGENTS.md 中写入使用说明,同时在 .opencode 下写入 plugin
graphify opencode install
集成 Claude Code
# 在项目目录下执行
# 会在 CLAUDE.md 中写入使用说明,同时在 .claude 下写入 hook
graphify claude install
相关文章