CodeGraph - An open-source code knowledge graph tool that accelerates code understanding and analysis.
CodeGraph is a pre-indexed code knowledge graph tool for AI coding agents, deeply integrated with Claude Code, Cursor, Codex CLI, OpenCode, and Hermes Agent via the MCP protocol. It utilizes tree-...
What is CodeGraph?
CodeGraph is a pre-indexed code knowledge graph tool for AI coding agents, deeply integrated with Claude Code, Cursor, Codex CLI, OpenCode, and Hermes Agent via the MCP protocol. It utilizes tree-sitters to parse codebases, storing symbol relationships, call graphs, and code structure in a local SQLite database. This allows AI agents to directly locate code through graph queries, replacing traditional grep/glob/read file scanning methods. Benchmark tests with seven real-world open-source projects validate that CodeGraph reduces API costs by an average of 35%, token consumption by 59%, saves 49% of time, and reduces tool calls by 70%, all while running 100% locally without requiring external API keys.
CodeGraph's main functions
-
Pre-indexed code knowledge graphThe codebase is parsed into an AST by tree-sitter, and symbol nodes such as functions, classes, and methods, as well as relationship edges such as calls, imports, and inheritance, are extracted to build an SQLite graph database that can be queried in real time.
-
Intelligent Context BuildingA single tool call can return the entry point, related symbols, and code snippets, eliminating the need for expensive exploration agents to scan file by file.
-
Full-text symbol searchBased on FTS5, it enables real-time symbol name search across code repositories, quickly locating target code.
-
Radius of influence analysisTrack the callers, callees, and full scope of influence of any symbol, and assess the impact before modification.
-
Framework-aware routingAutomatically identifies routing files for 14 web frameworks and associates URL patterns with corresponding handler functions/classes.
-
Real-time automatic synchronization: Listen for project changes through native OS file events (FSEvents/inotify/ReadDirectoryChangesW), and automatically incrementally synchronize the map after 2 seconds of debouncing.
-
Change Impact Test Tracking:
codegraph affectedThe command can track transitive dependencies of changed files, accurately locate affected test files, and is suitable for CI pipelines. -
Zero configuration, ready to useAutomatically recognizes the language based on the file extension and automatically respects it.
.gitignoreRules, no configuration files need to be written.
How to use CodeGraph
-
Install CodeGraph: Execute in the terminal
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh(macOS/Linux) orirm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex(Windows PowerShell); Users who have Node.js installed can also run it directly.npx @colbymchenry/codegraph -
Select Integrated AgentThe installer automatically detects the AI agents (Claude Code, Cursor, Codex CLI, opencode, Hermes Agent) already installed in the system, interactively prompts you to select the agent to configure, and automatically writes the configuration into the MCP.
-
Restart AI AgentAfter installation, restart the corresponding AI agent to make the MCP server configuration take effect.
-
Initialize project indexEnter the project directory and execute.
codegraph init -iThis will build a knowledge graph index for the project; it will also automatically configure project-level proxy rule files (such as...)..cursor/rules/codegraph.mdc) -
Start usingWhen the project directory contains
.codegraph/When accessing a folder, the AI agent will automatically invoke the CodeGraph tool for code querying and exploration; it can also be executed via the CLI.codegraph query <关键词>,codegraph callers <符号名>Manual query via command
CodeGraph's core advantages
-
Significantly reduce usage costsTested on 7 real open-source projects (VS Code, Excalidraw, Django, Tokio, OkHttp, Gin, Alamofire), it saves an average of 35% on API costs, 59% on token consumption, 49% on execution time, and 70% on tool calls; the effect is particularly significant for large repositories.
-
100% Local Privacy and SecurityAll data is stored in a local SQLite database, requiring no internet connection, no API key, and no data upload, thus fully protecting code privacy.
-
Cross-platform self-contained operationProvides standalone build packages for Windows (x64/arm64), macOS (x64/arm64), and Linux (x64/arm64), with a built-in Node runtime, eliminating the need for local compilation or additional Node.js installation.
-
19+ languages coveredIt fully supports mainstream and niche languages such as TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C/C++, Swift, Kotlin, Scala, Dart, Svelte, Vue, Liquid, Pascal/Delphi, Lua, and Luau.
-
Deep framework integrationIt natively recognizes the routing syntax of 14 frameworks, including Django, Flask, FastAPI, Express, NestJS, Laravel, Rails, Spring, Gin, React Router, and SvelteKit, and accurately associates URLs with processors.
-
Seamless Agent IntegrationIt interfaces with mainstream AI coding proxies via the MCP protocol, and the installer automatically completes the configuration without requiring manual editing of the JSON configuration file.
CodeGraph's project address
- GitHub repositoryhttps://github.com/colbymchenry/codegraph
Application scenarios of CodeGraph
-
Quick answers to architecture questionsAsk the AI agent architectural questions such as "How does the extended host process communicate with the main process?" The agent can directly locate the relevant source code through the graph, without the need for divergent file scanning.
-
Code review and impact analysisBefore modifying the core function, by
codegraph_impactAnalyze the scope of the changes to avoid introducing regression problems. -
Getting Started and Familiarizing with CodeNew team members ask questions to the AI agent using natural language to quickly understand the project structure, module dependencies, and key business logic.
-
Precise testing and positioningIntegrating CI into the pipeline
git diffandcodegraph affectedIt only runs test files affected by code changes, shortening build time. -
Cross-file reconstruction assistantWhen refactoring the public API, use callers/callees to track all library references and ensure that all calls are updated synchronously.