Skip to content

Repository files navigation

CodeGraph

Supercharge Claude Code, Cursor, Codex, OpenCode, and Hermes Agent with Semantic Code Intelligence

~35% cheaper · ~70% fewer tool calls · 100% local

npm versionLicense: MITSelf-contained

WindowsmacOSLinux

Claude CodeCursorCodex CLIopencodeHermes Agent

Get Started

No Node.js required — one command grabs the right build for your OS:

# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh
# Windows (PowerShell)
irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex

Already have Node? Use npm instead (works on any version):

npx @colbymchenry/codegraph # zero-install, or:
npm i -g @colbymchenry/codegraph

CodeGraph bundles its own runtime — nothing to compile, no native build, works the same everywhere. The interactive installer auto-configures your agent(s) — Claude Code, Cursor, Codex CLI, opencode, Hermes Agent.

Initialize Projects

cd your-project
codegraph init -i

1_C_VYnhpys0UHrOuOgpgoyw

Uninstall

Changed your mind? One command removes CodeGraph from every agent it configured:

codegraph uninstall

Reverses the installer — strips CodeGraph's MCP server config, instructions, and permissions from each configured agent. Your project indexes (.codegraph/) are left untouched; remove those per-project with codegraph uninit. Use --target to remove from specific agents, or --yes to run non-interactively.


Why CodeGraph?

When Claude Code explores a codebase, it spawns Explore agents that scan files with grep, glob, and Read — consuming tokens on every tool call.

CodeGraph gives those agents a pre-indexed knowledge graph — symbol relationships, call graphs, and code structure. Agents query the graph instantly instead of scanning files.

Benchmark Results

Tested across 7 real-world open-source codebases spanning 7 languages, comparing an agent (Claude Code, headless) answering one architecture question with and without CodeGraph. Each cell is the savings at the median of 4 runs per arm. Re-validated on v0.9.4 (2026-05-24).

Average: 35% cheaper · 57% fewer tokens · 46% faster · 71% fewer tool calls

CodebaseLanguageCostTokensTimeTool calls
VS CodeTypeScript · ~10k files26% cheaper78% fewer52% faster85% fewer
ExcalidrawTypeScript · ~64052% cheaper90% fewer73% faster96% fewer
DjangoPython · ~3k12% cheaper36% fewer19% faster53% fewer
TokioRust · ~79082% cheaper86% fewer71% faster92% fewer
OkHttpJava · ~6452% cheaper13% fewer31% faster45% fewer
GinGo · ~11021% cheaper34% fewer27% faster40% fewer
AlamofireSwift · ~11047% cheaper64% fewer48% faster83% fewer

The gains scale with codebase size: on large repos the agent answers from the index in a handful of calls with zero file reads, while the no-CodeGraph agent fans out across grep/find/Read (and the sub-agents it spawns). On a small repo like Gin (~150 files) native search is already cheap, so the margin narrows.

Full benchmark details

Methodology. Each arm is claude -p (Claude Opus 4.7) run headlessly against the repo with --strict-mcp-config: WITH = CodeGraph's MCP server enabled, WITHOUT = an empty MCP config. Built-in Read/Grep/Bash stay available to both. Same question per repo, 4 runs per arm, median reported. Cost = the run's total_cost_usd; Tokens = total tokens processed (input incl. cached + output); Time = wall-clock; Tool calls = every tool invocation, including those inside any sub-agents the model spawns. Repos cloned at --depth 1 and indexed by the same CodeGraph build that served them. Re-validated on codegraph v0.9.4 (2026-05-24); per-repo numbers move run-to-run with how hard the without-arm thrashes (the median-of-4 smooths it, but tails remain — e.g. Tokio's without-arm hit $2.41/3m one batch).

Queries:

CodebaseQuery
VS Code"How does the extension host communicate with the main process?"
Excalidraw"How does Excalidraw render and update canvas elements?"
Django"How does Django's ORM build and execute a query from a QuerySet?"
Tokio"How does tokio schedule and run async tasks on its runtime?"
OkHttp"How does OkHttp process a request through its interceptor chain?"
Gin"How does gin route requests through its middleware chain?"
Alamofire"How does Alamofire build, send, and validate a request?"

Raw medians — WITH → WITHOUT:

CodebaseCostTokensTimeTool calls
VS Code$0.60 → $0.80601k → 2.8M1m 10s → 2m 26s8 → 55
Excalidraw$0.43 → $0.90344k → 3.5M48s → 2m 58s3 → 79
Django$0.59 → $0.67739k → 1.2M1m 19s → 1m 38s9 → 19
Tokio$0.42 → $2.41379k → 2.6M53s → 3m 2s4 → 53
OkHttp$0.47 → $0.47636k → 730k42s → 1m 1s6 → 11
Gin$0.37 → $0.47444k → 675k44s → 1m 0s6 → 10
Alamofire$0.61 → $1.141.0M → 2.8M1m 17s → 2m 27s12 → 69

Why CodeGraph wins: with the index available, the agent answers directly — codegraph_context to map the area, then one codegraph_explore for the relevant source — and stops, usually with zero file reads. Without it, the agent (and the Explore sub-agents it spawns) spends most of its budget on discovery (find/ls/grep) before reading the right code. CodeGraph only helps when queried directly, so its instructions steer agents to answer directly rather than delegate exploration to file-reading sub-agents — otherwise a sub-agent reads files regardless and CodeGraph becomes overhead.


Key Features

Smart Context BuildingOne tool call returns entry points, related symbols, and code snippets — no expensive exploration agents
Full-Text SearchFind code by name instantly across your entire codebase, powered by FTS5
Impact AnalysisTrace callers, callees, and the full impact radius of any symbol before making changes
Always FreshFile watcher uses native OS events (FSEvents/inotify/ReadDirectoryChangesW) with debounced auto-sync — the graph stays current as you code, zero config
20+ LanguagesTypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Objective-C, Swift, Kotlin, Dart, Lua, Luau, Svelte, Liquid, Pascal/Delphi
Framework-aware RoutesRecognizes web-framework routing files and links URL patterns to their handlers across 14 frameworks
Mixed iOS / React Native / ExpoCloses cross-language flows that static parsing misses: Swift ↔ ObjC bridging, React Native legacy bridge + TurboModules + Fabric view components, native → JS event emitters, Expo Modules
100% LocalNo data leaves your machine. No API keys. No external services. SQLite database only

Framework-aware Routes

CodeGraph detects web-framework routing files and emits route nodes linked by references edges to their handler classes or functions. Querying callers of a view/controller now surfaces the URL pattern that binds it.

FrameworkShapes recognized
Djangopath(), re_path(), url(), include() in urls.py (CBV .as_view(), dotted paths)
Flask@app.route('/path', methods=[...]), blueprint routes
FastAPI@app.get(...), @router.post(...), all standard methods
Expressapp.get(...), router.post(...) with middleware chains
NestJS@Controller + @Get/@Post/..., GraphQL @Resolver + @Query/@Mutation, @MessagePattern/@EventPattern, @SubscribeMessage
LaravelRoute::get(), Route::resource(), Controller@action, tuple syntax
Drupal*.routing.yml routes (_controller, _form, entity handlers); hook_* implementations in .module/.theme/.install/.inc
Railsget '/x', to: 'users#index', hash-rocket => syntax
Spring@GetMapping, @PostMapping, @RequestMapping on methods
Gin / chi / gorilla / muxr.GET(...), router.HandleFunc(...)
Axum / actix / Rocket.route("/x", get(handler))
ASP.NET[HttpGet("/x")] attributes on action methods
Vaporapp.get("x", use: handler)
React Router / SvelteKitRoute component nodes

Mixed iOS / React Native / Expo bridging

Real iOS and React Native codebases live across multiple languages — a Swift caller invokes an Objective-C selector that's been auto-bridged, a JS file calls into a native module via the React Native bridge, a JSX component delegates to a native view manager. Static tree-sitter extraction stops at each language boundary. CodeGraph bridges them so trace, callers, callees, and impact connect end-to-end across the gap.

BoundaryJS / Swift sideNative sideHow
Swift → ObjCSwift obj.foo(bar:)ObjC selector -fooWithBar:@objc auto-bridging rules (including init/property/protocol forms) + Cocoa preposition prefixes (With/For/By/In/On/At/…)
ObjC → SwiftObjC [obj fooWithBar:]Swift @objc func foo(bar:)Reverse-bridge name candidates; verifies @objc exposure from source
React Native legacy bridgeJS NativeModules.X.fn(...)ObjC RCT_EXPORT_METHOD / RCT_REMAP_METHOD · Java/Kotlin @ReactMethodParses macro/annotation declarations to build a JS-name → native-method map
React Native TurboModulesJS import M from './NativeM'; M.fn(...)Native impl matching the Codegen specTreats the Native<X>.ts spec interface as ground truth
RN native → JS eventsJS new NativeEventEmitter(...).addListener('e', cb)ObjC [self sendEventWithName:@"e" body:...] · Swift sendEvent(withName: "e", ...) · Java/Kotlin .emit("e", ...)Synthesized cross-language event channel keyed by literal event name
Expo ModulesJS requireNativeModule('X').fn(...)Swift / Kotlin Module { Name("X"); AsyncFunction("fn") { ... } }Parses the Expo DSL literals; synthetic method nodes resolve via existing name-match
Fabric view componentsJSX <MyView prop={v}/>TS Codegen spec + native impl classSpec → component node; convention-based name+suffix lookup (View/ComponentView/Manager/ViewManager) bridges to native
Legacy Paper view managersJSX <MyView prop={v}/>ObjC RCT_EXPORT_VIEW_PROPERTY · Java/Kotlin @ReactPropSame as Fabric — Paper-era declarations also produce component + property nodes

Validated on real codebases (small + medium + large for each bridge):

BridgeSmallMediumLarge
Swift ↔ ObjCChartsrealm-swiftWikipedia-iOS
RN legacy bridgeAsyncStoragereact-native-svgreact-native-firebase
RN native → JS eventsRNGeolocationreact-native-firebase
Expo Modulesexpo-hapticsexpo-cameraexpo SDK sweep (7 packages)
Fabric / Paper viewsreact-native-segmented-controlreact-native-screensreact-native-skia

Each bridge emits edges tagged provenance:'heuristic' with metadata.synthesizedBy: set to a stable channel name (e.g. swift-objc-bridge, rn-event-channel, fabric-native-impl, expo-module-extract), so the agent can tell at a glance how a hop got into the graph.


Quick Start

1. Run the Installer

npx @colbymchenry/codegraph

The installer will:

  • Ask which agent(s) to configure — auto-detects installed ones from: Claude Code, Cursor, Codex CLI, opencode, Hermes Agent
  • Prompt to install codegraph on your PATH (so agents can launch the MCP server)
  • Ask whether configs apply to all your projects or just this one
  • Write each chosen agent's MCP server config + an instructions file (e.g. CLAUDE.md, .cursor/rules/codegraph.mdc, ~/.codex/AGENTS.md)
  • Set up auto-allow permissions when Claude Code is one of the targets
  • Initialize your current project (local installs only)

Non-interactive (scripting / CI):

codegraph install --yes # auto-detect agents, install global
codegraph install --target=cursor,claude --yes # explicit target list
codegraph install --target=auto --location=local # detected agents, project-local
codegraph install --print-config codex # print snippet, no file writes
FlagValuesDefault
--targetauto, all, none, or csv (claude,cursor,...)prompt
--locationglobal, localprompt
--yes(boolean)prompt every step
--no-permissions(boolean) skip Claude auto-allow listpermissions on
--print-config <id>dump snippet for one agent and exit

2. Restart Your Agent

Restart your agent (Claude Code / Cursor / Codex CLI / opencode / Hermes Agent) for the MCP server to load.

3. Initialize Projects

cd your-project
codegraph init -i

Builds the per-project knowledge graph index. Also wires up any project-local agent surfaces (e.g. Cursor's .cursor/rules/codegraph.mdc) so a single global codegraph install works in every project you open — no need to re-run the installer per project.

That's it — your agent will use CodeGraph tools automatically when a .codegraph/ directory exists.

Manual Setup (Alternative)

Install globally:

npm install -g @colbymchenry/codegraph

Add to ~/.claude.json:

{
"mcpServers": {
"codegraph": {
"type": "stdio",
"command": "codegraph",
"args": ["serve", "--mcp"]
}
}
}

Add to ~/.claude/settings.json (optional, for auto-allow):

{
"permissions": {
"allow": [
"mcp__codegraph__codegraph_search",
"mcp__codegraph__codegraph_context",
"mcp__codegraph__codegraph_callers",
"mcp__codegraph__codegraph_callees",
"mcp__codegraph__codegraph_impact",
"mcp__codegraph__codegraph_node",
"mcp__codegraph__codegraph_status",
"mcp__codegraph__codegraph_files"
]
}
}
Global Instructions Reference

The installer automatically adds these instructions to ~/.claude/CLAUDE.md:

## CodeGraph
CodeGraph builds a semantic knowledge graph of codebases for faster, smarter code exploration.
### If `.codegraph/` exists in the project**Answer directly with CodeGraph — don't delegate exploration to a file-reading sub-agent or a grep/read loop.** CodeGraph *is* the pre-built search index; re-deriving its answers with grep + Read repeats work it already did and costs more for the same result. For "how does X work?", architecture, trace, or where-is-X questions, answer in a handful of CodeGraph calls and stop — typically with **zero file reads**. The returned source is complete and authoritative: treat it as already read and do not re-open those files. Reach for raw Read/Grep only to confirm a specific detail CodeGraph didn't cover.
**Tool selection by intent:**| Tool | Use For ||------|---------||`codegraph_context`| Map a task / feature / area first — composes search + node + callers + callees in one call ||`codegraph_trace`| "How does X reach Y" — the call path, each hop's body inline (follows dynamic-dispatch hops grep can't) ||`codegraph_explore`| Survey several related symbols' source in ONE budget-capped call ||`codegraph_search`| Find a symbol by name ||`codegraph_callers` / `codegraph_callees`| Walk call flow one hop at a time ||`codegraph_impact`| Check what's affected before editing ||`codegraph_node`| Get a single symbol's source / signature |
A direct CodeGraph answer is a handful of calls; a grep/read exploration is dozens.
### If `.codegraph/` does NOT exist
At the start of a session, ask the user if they'd like to initialize CodeGraph:
"I notice this project doesn't have CodeGraph initialized. Would you like me to run `codegraph init -i` to build a code knowledge graph?"

How It Works

┌───────────────────────────────────────────────────────────────────┐
│ Claude Code │
│ │
│ "How does a request reach the database?" │
│ calls CodeGraph tools directly — no Explore sub-agent │
│ │ │
└─────────────────────────────────┬─────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────────────┐
│ CodeGraph MCP Server │
│ │
│ context · trace · explore · callers · callees · impact │
│ │ │
│ ▼ │
│ SQLite knowledge graph │
│ symbols · edges · files · FTS5 full-text search │
└───────────────────────────────────────────────────────────────────┘
  1. Extractiontree-sitter parses source code into ASTs. Language-specific queries extract nodes (functions, classes, methods) and edges (calls, imports, extends, implements).

  2. Storage — Everything goes into a local SQLite database (.codegraph/codegraph.db) with FTS5 full-text search.

  3. Resolution — After extraction, references are resolved: function calls → definitions, imports → source files, class inheritance, and framework-specific patterns.

  4. Auto-Sync — The MCP server watches your project using native OS file events. Changes are debounced (2-second quiet window), filtered to source files only, and incrementally synced. The graph stays fresh as you code — no configuration needed.


CLI Reference

codegraph # Run interactive installer
codegraph install # Run installer (explicit)
codegraph uninstall # Remove CodeGraph from your agents (inverse of install)
codegraph init [path] # Initialize in a project (--index to also index)
codegraph uninit [path] # Remove CodeGraph from a project (--force to skip prompt)
codegraph index [path] # Full index (--force to re-index, --quiet for less output)
codegraph sync [path] # Incremental update
codegraph status [path] # Show statistics
codegraph query <search># Search symbols (--kind, --limit, --json)
codegraph files [path] # Show file structure (--format, --filter, --max-depth, --json)
codegraph context <task># Build context for AI (--format, --max-nodes)
codegraph callers <symbol># Find what calls a function/method (--limit, --json)
codegraph callees <symbol># Find what a function/method calls (--limit, --json)
codegraph impact <symbol># Analyze what code is affected by changing a symbol (--depth, --json)
codegraph affected [files...] # Find test files affected by changes (see below)
codegraph serve --mcp # Start MCP server

codegraph affected

Traces import dependencies transitively to find which test files are affected by changed source files.

codegraph affected src/utils.ts src/api.ts # Pass files as arguments
git diff --name-only | codegraph affected --stdin # Pipe from git diff
codegraph affected src/auth.ts --filter "e2e/*"# Custom test file pattern
OptionDescriptionDefault
--stdinRead file list from stdinfalse
-d, --depth <n>Max dependency traversal depth5
-f, --filter <glob>Custom glob to identify test filesauto-detect
-j, --jsonOutput as JSONfalse
-q, --quietOutput file paths onlyfalse

CI/hook example:

#!/usr/bin/env bash
AFFECTED=$(git diff --name-only HEAD | codegraph affected --stdin --quiet)if [ -n"$AFFECTED" ];then
npx vitest run $AFFECTEDfi

MCP Tools

When running as an MCP server, CodeGraph exposes these tools to Claude Code:

ToolPurpose
codegraph_searchFind symbols by name across the codebase
codegraph_contextBuild relevant code context for a task
codegraph_traceTrace the call path between two symbols ("how does X reach Y") in one call — each hop with its body inline, following dynamic-dispatch hops (callbacks, React re-render, interface→impl) that grep can't
codegraph_callersFind what calls a function
codegraph_calleesFind what a function calls
codegraph_impactAnalyze what code is affected by changing a symbol
codegraph_nodeGet details about a specific symbol (optionally with source code)
codegraph_exploreReturn source for several related symbols grouped by file, plus a relationship map, in one call
codegraph_filesGet indexed file structure (faster than filesystem scanning)
codegraph_statusCheck index health and statistics

Library Usage

importCodeGraphfrom'@colbymchenry/codegraph';constcg=awaitCodeGraph.init('/path/to/project');// Or: const cg = await CodeGraph.open('/path/to/project');awaitcg.indexAll({onProgress: (p)=>console.log(`${p.phase}: ${p.current}/${p.total}`)});constresults=cg.searchNodes('UserService');constcallers=cg.getCallers(results[0].node.id);constcontext=awaitcg.buildContext('fix login bug',{maxNodes: 20,includeCode: true,format: 'markdown'});constimpact=cg.getImpactRadius(results[0].node.id,2);cg.watch();// auto-sync on file changescg.unwatch();// stop watchingcg.close();

Configuration

There isn't any — CodeGraph is zero-config, with no config file to write or keep in sync. Language support is automatic from the file extension; there's nothing to wire up per language.

What it skips out of the box:

  • Dependency, build, and cache directoriesnode_modules, vendor, dist, build, target, .venv, Pods, .next, and the like across every supported stack — so the graph is your code, not third-party noise. This holds even with no .gitignore.
  • Anything in your .gitignore — honored in git repos via git, and in non-git projects by reading .gitignore directly (root and nested).
  • Files larger than 1 MB — generated bundles, minified JS, vendored blobs.

To keep something else out, add it to .gitignore. To pull a default-excluded directory back in (say you really do want a vendored dependency indexed), add a negation — !vendor/. The defaults apply uniformly, so committing a dependency or build directory doesn't force it into the graph; the .gitignore negation is the explicit opt-in.

Supported Platforms

Every release ships a self-contained build (bundled Node runtime — nothing to compile) for all three desktop OSes, on both Intel/AMD (x64) and ARM (arm64):

PlatformArchitecturesInstall
Windowsx64, arm64PowerShell installer or npm
macOSx64, arm64shell installer or npm
Linuxx64, arm64shell installer or npm

See Get Started for the one-line install commands.

Supported Agents

The interactive installer auto-detects and configures each of these — wiring up the MCP server and writing its instructions file:

  • Claude Code
  • Cursor
  • Codex CLI
  • opencode
  • Hermes Agent

Supported Languages

LanguageExtensionStatus
TypeScript.ts, .tsxFull support
JavaScript.js, .jsx, .mjsFull support
Python.pyFull support
Go.goFull support
Rust.rsFull support
Java.javaFull support
C#.csFull support
PHP.phpFull support
Ruby.rbFull support
C.c, .hFull support
C++.cpp, .hpp, .ccFull support
Objective-C.m, .mm, .hPartial support (classes, protocols, methods, @property, #import, message sends; .mm ObjC++ may parse incompletely)
Swift.swiftFull support
Kotlin.kt, .ktsFull support
Scala.scala, .scFull support (classes, traits, methods, type aliases, Scala 3 enums)
Dart.dartFull support
Svelte.svelteFull support (script extraction, Svelte 5 runes, SvelteKit routes)
Vue.vueFull support (script + script-setup extraction, Nuxt page/API/middleware routes)
Liquid.liquidFull support
Pascal / Delphi.pas, .dpr, .dpk, .lprFull support (classes, records, interfaces, enums, DFM/FMX form files)
Lua.luaFull support (functions, methods with receivers, local variables, require imports, call edges)
Luau.luauFull support (everything in Lua, plus type/export type aliases, typed signatures, and Roblox instance-path require)

Troubleshooting

"CodeGraph not initialized" — Run codegraph init in your project directory first.

Indexing is slow — Check that node_modules and other large directories are excluded. Use --quiet to reduce output overhead.

MCP hits database is locked — current builds shouldn't: CodeGraph bundles its own Node runtime and uses Node's built-in node:sqlite in WAL mode, where concurrent reads never block on a writer. If you still see it:

  • You're on an old (pre-0.9) install. Reinstall to get the bundled runtime — curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh (macOS/Linux), irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex (Windows), or npm i -g @colbymchenry/codegraph@latest.
  • codegraph status shows Journal: other than wal — WAL couldn't be enabled on this filesystem (common on network shares and WSL2 /mnt), so reads can block on writes. Move the project (with its .codegraph/ folder) onto a local disk.

MCP server not connecting — Ensure the project is initialized/indexed, verify the path in your MCP config, and check that codegraph serve --mcp works from the command line.

Missing symbols — The MCP server auto-syncs on save (wait a couple seconds). Run codegraph sync manually if needed. Check that the file's language is supported and isn't inside a .gitignored or default-excluded directory (e.g. node_modules, dist).

Star History

Star History Chart

License

MIT


Made for AI coding agents — Claude Code, Cursor, Codex CLI, opencode, and Hermes Agent

Report Bug · Request Feature

About

Pre-indexed code knowledge graph for Claude Code, Codex, Cursor, OpenCode, and Hermes Agent — fewer tokens, fewer tool calls, 100% local

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages