Workspace-aware semantic code intelligence for AI coding agents.
CodeGraph v2 indexes source code into a local SQLite knowledge graph so agents
can answer structural questions with fast MCP tools instead of repeatedly
scanning files. It is developed as a separate codebase from codegraph_v1; v1
remains the upstream reference baseline only.
- First-class multi-repo workspace support.
- Safe local-first installer for Claude Code, Cursor, Codex CLI, and opencode.
- Global install protections: dry-run plan, backups, rollback, and marker-based instruction updates.
- Workspace-aware MCP tools with
projectandprojectPathtargeting. - Child repositories ignored by the workspace root
.gitignorecan still be discovered and indexed. - One isolated
.codegraph/codegraph.dbper project.
- Node.js
>=20 <25 - npm
- A supported agent if you want MCP integration: Claude Code, Cursor, Codex CLI, or opencode
From npm:
npm install -g @dvttvnp/codegraph-v2
codegraph --helpFrom a local checkout:
cd codegraph_v2
npm install
npm run build
npm link
codegraph --helpRemove the local link when needed:
npm unlink -g @dvttvnp/codegraph-v2After running any codegraph install ... command, restart your agent so it can
load the MCP server.
Use this when the current folder is one normal project or one git repository.
cd your-project
codegraph install --location local --target auto
codegraph init -i
codegraph statusWhat this does:
- Adds project-local MCP configuration where supported.
- Creates
.codegraph/config.json. - Builds
.codegraph/codegraph.db. - Keeps the configuration scoped to the current project.
Run a quick query:
codegraph query "PaymentService"
codegraph context "How does authentication work?"Keep the index fresh manually:
codegraph syncRemove CodeGraph from the project:
codegraph uninstall --location local --target auto
codegraph uninitUse this when one umbrella folder contains many child projects, and each child project can be its own git repository.
cd your-workspace
codegraph install --location workspace --target auto
codegraph workspace init
codegraph workspace discover
codegraph workspace index
codegraph workspace statusWhat this does:
- Creates
.codegraph/workspace.jsonat the workspace root. - Discovers child projects using markers such as
.git,package.json,pom.xml,go.mod, andCargo.toml. - Indexes every enabled child project into that project's own
.codegraph/codegraph.db. - Searches enabled projects from the workspace root through CLI and MCP.
Sync all enabled child projects:
codegraph workspace syncRe-discover projects after adding or removing child repositories:
codegraph workspace discoverRemove CodeGraph from the workspace root and every enabled child project:
codegraph uninstall --location workspace --target auto
# or:
codegraph workspace uninstall --target autoThis removes CodeGraph-owned local agent config and deletes each managed
.codegraph/ directory. Use --dry-run first if you want to preview every
file and data directory that would be touched.
Example workspace manifest:
{
"version": 1,
"mode": "multi-project",
"projects": [
{ "name": "api", "path": "api", "enabled": true },
{ "name": "web", "path": "web", "enabled": true },
{ "name": "legacy-service", "path": "legacy-service", "enabled": false }
],
"scanIgnoredChildren": true,
"maxDepth": 2,
"workspaceExclude": ["**/node_modules/**", "**/target/**", "**/dist/**"],
"projectMarkers": [".git", "package.json", "pom.xml", "go.mod", "Cargo.toml"]
}Important workspace notes:
- Set
enabled: falseto keep a project in the manifest but skip indexing and MCP search. - Keep
scanIgnoredChildren: truewhen the workspace root.gitignoreignores child repositories but you still want CodeGraph to discover them. - Each child project's own
.gitignorestill controls which files are indexed inside that child project. codegraph uninstall --location local --target autoonly affects the current directory's agent config. Use--location workspaceorcodegraph workspace uninstallto clean the workspace root and enabled child projects, including their.codegraph/data directories.
Open the graph explorer from an initialized project:
cd your-project
codegraph uiOpen it from a workspace root that has .codegraph/workspace.json:
cd your-workspace
codegraph uiUseful options:
codegraph ui --port 8732
codegraph ui --host 127.0.0.1
codegraph ui --project ./packages/api
codegraph ui --workspace .
codegraph ui --no-openThe UI binds to 127.0.0.1 by default and serves a local HTTP API plus static
web assets. It shows project/workspace status, indexed files, symbol search
results, node and edge details, source locations, and graph views for file
dependencies, symbol neighborhoods, call graphs, type hierarchies, and impact
radius. Sync, index, and workspace sync actions run through the UI job API and
can also be run from the CLI.
Remote binding is disabled unless explicitly requested:
codegraph ui --host 0.0.0.0 --allow-remote --no-openUse remote binding only on trusted networks.
The v2 installer defaults to local or workspace-local setup. Global setup is available, but intentionally guarded because it edits user-wide agent files.
Preview a global install:
codegraph install --location global --force-global --dry-runApply a global install:
codegraph install --location global --force-globalPrint instructions without writing files:
codegraph install --manual --target claude
codegraph install --print-config codexUndo the latest global install backup:
codegraph install rollbackSafety rules:
- Existing MCP servers and user instructions are preserved.
- CodeGraph instructions are written only inside
CODEGRAPH_STARTandCODEGRAPH_ENDmarker blocks. - Global writes create backups before changing existing files.
- Invalid JSON/JSONC global config is treated as unsafe and blocks the write.
- Local and global uninstall remove only CodeGraph-owned MCP entries, permissions, and marker blocks.
- Workspace uninstall reads
.codegraph/workspace.json, removes those local config surfaces, deletes.codegraph/data directories for the workspace root and enabled projects, skips disabled projects, and continues if one child project cannot be cleaned.
| Command | Purpose |
|---|---|
codegraph install |
Configure MCP integration for agents |
codegraph install rollback |
Restore the latest global install backup |
codegraph uninstall |
Remove CodeGraph-owned agent config |
codegraph init -i |
Initialize and index a single project |
codegraph index |
Rebuild the current project index |
codegraph sync |
Incrementally sync the current project |
codegraph status |
Show index health and statistics |
codegraph ui |
Open the local graph explorer UI |
codegraph query <text> |
Search indexed symbols |
codegraph context <task> |
Build focused context for an AI task |
codegraph files |
Show indexed file structure |
codegraph affected <files...> |
Find tests affected by changed files |
codegraph workspace init |
Create a workspace manifest |
codegraph workspace discover |
Re-scan child projects |
codegraph workspace index |
Index enabled workspace projects |
codegraph workspace sync |
Sync enabled workspace projects |
codegraph workspace status |
Show per-project workspace status |
codegraph workspace uninstall |
Remove local agent config and .codegraph/ data from the workspace root and enabled child projects |
codegraph serve --mcp |
Start the MCP server |
CodeGraph exposes these tools to MCP-compatible agents:
| Tool | Purpose |
|---|---|
codegraph_search |
Find symbols by name |
codegraph_context |
Build task-focused code context |
codegraph_explore |
Inspect source for several related symbols in one call |
codegraph_node |
Show symbol details, signature, and source |
codegraph_callers |
Find what calls a symbol |
codegraph_callees |
Find what a symbol calls |
codegraph_impact |
Analyze the impact radius of a change |
codegraph_files |
List indexed files |
codegraph_status |
Check index health |
In workspace mode, pass project or projectPath when the target child project
is known:
{ "query": "PaymentService", "project": "payment-api" }{ "symbol": "createPayment", "projectPath": "payment-api" }If omitted, workspace-aware tools search all enabled projects and include
projectName and projectPath in the result metadata.
Single-project config lives at:
.codegraph/config.json
Workspace config lives at:
.codegraph/workspace.json
See the focused docs for details:
docs/WORKSPACE_MANIFEST.mddocs/INSTALLER_SAFETY.mddocs/MIGRATION_V1_TO_V2.md
TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Scala, Dart, Svelte, Vue, Liquid, and Pascal/Delphi.
CodeGraph also extracts routes for common web frameworks such as Django, Flask, FastAPI, Express, NestJS, Laravel, Rails, Spring, Gin, chi, gorilla/mux, Axum, actix, Rocket, ASP.NET, Vapor, React Router, SvelteKit, and Nuxt.
CodeGraph is not initialized
Run:
codegraph init -iFor workspace roots, run:
codegraph workspace init
codegraph workspace indexWorkspace root has no symbols
This is expected for an umbrella workspace. The workspace root stores the manifest; each child project stores its own graph database.
Child repositories are ignored by root .gitignore
Keep scanIgnoredChildren: true in .codegraph/workspace.json, then run:
codegraph workspace discover
codegraph workspace indexGlobal install was unsafe or failed
Use dry-run first, fix the reported config file, then run the install again:
codegraph install --location global --force-global --dry-runIf a backup was created and you need to undo it:
codegraph install rollbackIndexing is slow
Check that large generated folders are excluded, then verify the SQLite backend:
codegraph statusBackend: native is the fast path. Backend: wasm works, but can be slower and
may require rebuilding better-sqlite3 for best performance:
npm rebuild better-sqlite3MIT