星标数:147112★ Fork数:14100 《graphify:把代码与文档变成可查询知识图谱》
graphify 是一个 Claude Code 技能。在 Claude Code 中输入 /graphify,它会读取你的文件,构建知识图谱,把你原本没有意识到的结构交还给你。
它完全支持多模态输入。无论是代码、PDF、markdown、截图、图表、白板照片,还是其他语言的图片,graphify 都会借助 Claude vision 从中提取概念与关系,并把它们连接成一张图。
Andrej Karpathy 会专门建一个 /raw 文件夹,往里面丢论文、推文、截图和笔记。graphify 就是为了解决这个问题而生:每次查询的 token 消耗比直接读原始文件少 71.5 倍,跨会话持久保存,并且对「找到了什么」与「推测了什么」保持诚实。
/graphify . # works on any folder - your codebase, notes, papers, anything
graphify-out/ 目录中会生成 graph.html 交互式图谱、可作为 Obsidian vault 打开的 obsidian/、供 agent 导航的 wiki/(需 –wiki)、包含 god nodes、意外连接与建议问题的 GRAPH_REPORT.md、可长期查询而无需重读文件的 graph.json,以及基于 SHA256 的 cache/(重跑时只处理有变动的文件)。
主要特点
- 本地确定性 AST 解析:代码通过 tree-sitter + 调用图处理,纯本地运行,不依赖 Neo4j 或服务器
- 每条边都标注为 EXTRACTED、INFERRED 或 AMBIGUOUS,你始终清楚哪些是找到的、哪些是猜的
- 自动同步(–watch):后台运行后图谱随代码库变化自行更新;代码文件保存触发即时重建(仅 AST,不调用 LLM),文档与图片变更则提示你运行 –update
- Git 提交钩子(graphify hook install):安装 post-commit 钩子,每次提交后自动重建图谱,无需常驻进程
- Wiki(–wiki):按社区与 god node 生成 Wikipedia 风格的 markdown 文章与 index.md 入口,任何 agent 读文件即可导航知识库
- 多种导出:–svg 导出 graph.svg、–graphml 导出可在 Gephi、yEd 打开的文件、–neo4j 生成 cypher.txt、–mcp 启动 MCP stdio 服务器
- 支持任意文件类型混合:代码(.py .ts .js .go .rs .java 等)、文档(.md .txt .rst)、论文(.pdf)、图片(.png .jpg .webp .gif)
安装
需要 Claude Code 和 Python 3.10+:
pip install graphifyy && graphify install
PyPI 包名暂时为 graphifyy(正在取回 graphify 名称),但 CLI 与技能命令仍是 graphify。Windows 下若安装后识别不到 graphify,可把 Python Scripts 目录加入 PATH:%APPDATA%PythonPython3xxScripts(把 3xx 换成你的 Python 版本),或改用 pipx install graphifyy 自动处理 PATH;macOS 出现 externally-managed-environment 报错时同样可用 pipx install graphifyy。
也可手动安装(curl):
mkdir -p ~/.claude/skills/graphify
curl -fsSL https://raw.githubusercontent.com/safishamsi/graphify/v1/skills/graphify/skill.md
> ~/.claude/skills/graphify/SKILL.md
然后在 ~/.claude/CLAUDE.md 中加入:
- **graphify** (`~/.claude/skills/graphify/SKILL.md`) - any input to knowledge graph. Trigger: `/graphify`
When the user types `/graphify`, invoke the Skill tool with `skill: "graphify"` before doing anything else.
用法
/graphify # run on current directory
/graphify ./raw # run on a specific folder
/graphify ./raw --mode deep # more aggressive INFERRED edge extraction
/graphify ./raw --update # re-extract only changed files, merge into existing graph
/graphify add https://arxiv.org/abs/1706.03762 # fetch a paper, save, update graph
/graphify add https://x.com/karpathy/status/... # fetch a tweet
/graphify query "what connects attention to the optimizer?"
/graphify path "DigestAuth" "Response"
/graphify explain "SwinTransformer"
/graphify ./raw --watch # auto-sync graph as files change
/graphify ./raw --wiki # build agent-crawlable wiki
/graphify ./raw --svg # export graph.svg
/graphify ./raw --graphml # export graph.graphml (Gephi, yEd)
/graphify ./raw --neo4j # generate cypher.txt for Neo4j
/graphify ./raw --mcp # start MCP stdio server
graphify hook install # post-commit git hook - rebuilds graph on every commit automatically
你会得到什么
- God nodes:度数最高的概念(所有内容经由它们连接)
- 意外连接:按综合分数排序,代码-论文边排在代码-代码边之上,每条结果都附带一句通俗的「为什么」
- 建议问题:4-5 个这张图最有能力回答的问题
- Token 基准:每次运行后自动打印。在混合语料(Karpathy 仓库 + 论文 + 图片)上,每次查询比读原始文件少 71.5x 的 token
仓库还提供了 worked/ 示例语料供验证:Karpathy 仓库 + 5 篇论文 + 4 张图片共 52 个文件时缩减 71.5x;graphify 源码 + Transformer 论文共 4 个文件时为 5.4x;httpx(合成 Python 库)6 个文件时约为 1x。每个 worked/ 文件夹都包含原始输入与真实输出(GRAPH_REPORT.md、graph.json),你可以自己跑一遍核对这些数字。
技术栈
NetworkX + Leiden(graspologic)+ tree-sitter + Claude + vis.js。不需要 Neo4j,不需要服务器,完全在本地运行。
📊 本项目 GitHub 星标数:147112。最后更新:2026-11-12,发布:2026-11-12。项目地址:https://github.com/Graphify-Labs/graphify
