新闻详情

新闻详情

首页 / 资讯中心 / 详情

CodeGraph 使用指南

发布时间:2026/7/19 16:02:44
CodeGraph 使用指南
快速安装一键安装推荐无需 Node.jsbash# macOS / Linuxcurl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh# Windows (PowerShell)irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex安装完成后打开新终端窗口继续下一步。通过 npm 安装需要 Node.jsbashnpm i -g colbymchenry/codegraph升级bashcodegraph upgrade # 升级到最新版codegraph upgrade --check # 检查是否有新版本codegraph upgrade 版本号 # 锁定特定版本关联 AI 代理安装 CLI 后运行以下命令将 CodeGraph 连接到你的 AI 编码代理bashcodegraph install这会自动检测你已安装的 AI 代理Claude Code、Cursor、Codex CLI、OpenCode、Hermes Agent、Gemini CLI 等并为每个代理配置 MCP 服务器。你只需选择要启用的代理即可。支持的非交互式安装bashcodegraph install --yes # 自动检测并安装codegraph install --targetclaude,opencode --yes # 指定目标代理codegraph install --print-config claude # 仅打印配置片段不写入文件可选参数参数可选值说明--targetauto,all,none, 或 csv指定要配置的代理--locationglobal,local全局生效或仅当前项目--yes(布尔值)非交互模式--print-config代理 ID仅打印配置片段初始化项目进入你的项目目录运行bashcd your-projectcodegraph init这会在项目根目录创建.codegraph/目录并构建完整的知识图谱。构建完成后会自动监听文件变化并增量更新索引。各代理中的使用方式Claude Codecodegraph install会自动配置 Claude Code 的 MCP 服务器。安装后重启 Claude Code 即可。Claude Code 会自动使用codegraph_exploreMCP 工具来查询代码结构。如需手动配置编辑~/.claude.jsonjson{mcpServers:{codegraph:{type:stdio,command:codegraph,args:[serve,--mcp]}}}可选在~/.claude/settings.json中启用自动授权json{permissions: {allow: [mcp__codegraph__*]}}OpenCodecodegraph install同样支持自动检测 OpenCode。安装后重启 OpenCode 即可。OpenCode 的 MCP 配置会被写入对应的 MCP 配置文件中CodeGraph 会自动创建~/.config/opencode/mcp.json或类似路径的配置。Codex CLICodex CLI 同样被codegraph install自动支持。配置完成后重启 Codex CLICodeGraph 的 MCP 工具即可在 Codex 中使用。Hermes Agent同样支持自动配置。安装后重启 Hermes Agent 即可使用。ZCodeCodeGraph 未被codegraph install自动检测列表收录需手动添加 MCP 服务器配置。方式一通过 ZCode 设置面板添加打开 ZCode进入设置 → MCP 服务器点击右上角新建 MCP 服务器类型选择stdio本地命令填写以下信息字段值名称codegraph命令codegraph参数serve --mcp选择作用域用户作用域让所有项目可用工作区仅当前项目点击添加并确认开关处于启用状态方式二手动编辑配置文件ZCode 读取以下配置路径用户级~/.zcode/cli/config.json键mcp.servers项目级项目根/.zcode/config.json键mcp.servers在mcp.servers中添加json{codegraph:{type:stdio,command:codegraph,args:[serve,--mcp],env:{}}}方式三通过导入功能如果你已在其他代理中配置过ZCode 支持从 Claude Code、Codex CLI、OpenCode 等外部 Agent 一键导入 MCP 配置。在MCP 服务器页面点击右上角导入图标勾选 CodeGraph 即可。配置完成后重启 ZCode即可在项目中看到 CodeGraph 的codegraph_explore工具自动可用。CLI 常用命令命令说明codegraph status查看当前索引统计codegraph explore 查询核心功能 — 一次查询返回相关源码 调用链 影响范围codegraph node 符号/文件查看单个符号的源码或读取文件带行号codegraph callers 符号查找谁调用了某个函数codegraph callees 符号查找某个函数调用了什么codegraph impact 符号分析修改某符号的影响范围codegraph affected 文件...找出受更改影响的测试文件codegraph query 搜索搜索符号codegraph files查看文件结构codegraph index [路径]手动全量索引codegraph sync [路径]增量更新索引codegraph uninstall从所有代理中移除 CodeGraph 配置加--keep-cli保留 CLIcodegraph uninit [路径]移除项目的索引affected 命令的典型用法bash# 找出 git 变动的受影响测试文件git diff --name-only HEAD | codegraph affected --stdin --quiet# 然后在 CI 中只运行受影响测试npx vitest run $(git diff --name-only HEAD | codegraph affected --stdin --quiet)卸载bashcodegraph uninstall # 移除所有代理配置 CLI 自身codegraph uninstall --keep-cli # 仅移除代理配置保留 CLIcodegraph uninit # 移除当前项目的索引关键点CodeGraph仅索引你自己的代码自动跳过node_modules、dist、.gitignore中的目录图谱构建后自动监听文件变化无需手动重新索引支持多项目同时索引— 通过projectPath参数可在 MCP 会话中切换项目零配置即可使用不支持的文件扩展名可通过项目根codegraph.json映射所有数据100% 本地不发送你的代码
网站建设 高端定制 企业官网