Skip to content

Repository files navigation

CodeMind

A local knowledge graph that gives Claude Code instant structural understanding of any codebase.

License: MITNode.jsWindowsmacOSLinux

git clone https://github.com/dgdev25/codemind.git
cd codemind && npm install && npm run build && npm link

See Getting Started for full setup

CodeMind demo


The Problem

When Claude Code explores a codebase, it scans. It greps, lists directories, reads files one by one, builds up a mental model from scratch — every single session. On a medium-sized project, answering "how does the auth system work?" burns 40–50 tool calls and over a minute of wall time before a single line of real work begins.

That scanning loop is the bottleneck.

How CodeMind Fixes It

CodeMind indexes your codebase once into a local SQLite knowledge graph, then exposes it to Claude Code via an MCP server. Instead of scanning files, Claude queries the graph.

WITHOUT CodeMind WITH CodeMind
──────────────────────────────── ─────────────────────────────────
"How does auth work?" "How does auth work?"
│
grep -r "auth" . (6s) ▼
ls src/middleware/ (1s) codemind_explore "auth" (1 call)
read src/auth/index.ts (3s)
read src/middleware/auth.ts (3s) Returns immediately:
grep -r "session" . (6s) • AuthService, JwtMiddleware,
read src/session/manager.ts (3s) SessionStore — with locations
grep -r "JwtMiddleware" . (5s) • Full call chain: login()
read src/types/user.ts (3s) → validateToken() → SessionStore
... 44 more tool calls ... • Source code for key functions
• Related symbols and imports
52 tool calls 1m 37s • Framework route bindings
3 tool calls 17s

The graph is built once, stays current via a file watcher, and is queried in milliseconds.


Benchmark Results

Tested across 6 real-world codebases — same question, same model, with and without CodeMind:

CodebaseWith CodeMindWithout CodeMindImprovement
VS Code · TypeScript3 calls, 17s52 calls, 1m 37s94% fewer · 82% faster
Excalidraw · TypeScript3 calls, 29s47 calls, 1m 45s94% fewer · 72% faster
Claude Code · Python + Rust3 calls, 39s40 calls, 1m 8s93% fewer · 43% faster
Claude Code · Java1 call, 19s26 calls, 1m 22s96% fewer · 77% faster
Alamofire · Swift3 calls, 22s32 calls, 1m 39s91% fewer · 78% faster
Swift Compiler · Swift/C++6 calls, 35s37 calls, 2m 8s84% fewer · 73% faster

Average: 92% fewer tool calls · 71% faster

In every test, the agent with CodeMind never fell back to reading files — it trusted the graph completely.

Full benchmark methodology and raw numbers

All tests used Claude Opus 4.6 (1M context), Claude Code v2.1.91. A single Explore agent was spawned per test with the same question.

Queries:

CodebaseQuestion asked
VS Code"How does the extension host communicate with the main process?"
Excalidraw"How does collaborative editing and real-time sync work?"
Claude Code (Python+Rust)"How does tool execution work end to end?"
Claude Code (Java)"How does tool execution work end to end?"
Alamofire"Trace how a request flows from Session.request() through to the URLSession layer"
Swift Compiler"How does the Swift compiler handle error diagnostics?"

With CodeMind:

CodebaseFiles IndexedNodesTool UsesTokensTime
VS Code4,00259,377356.6k17s
Excalidraw6269,859357.1k29s
Claude Code (Py+Rust)1153,080367.1k39s
Claude Code (Java)140.8k19s
Alamofire1022,624357.3k22s
Swift Compiler25,874272,898677.4k35s

Without CodeMind:

CodebaseTool UsesTokensTimeFile Reads
VS Code5289.4k1m 37s~15
Excalidraw4777.9k1m 45s~20
Claude Code (Py+Rust)4069.3k1m 8s~15
Claude Code (Java)2673.3k1m 22s~15
Alamofire3252.4k1m 39s~10
Swift Compiler3799.1k2m 8s~20

Notable: the Alamofire benchmark traced a 9-step call chain from Session.request() to URLSession.dataTask() in a single explore call. The Swift Compiler (25,874 files, 272,898 nodes) was indexed in under 4 minutes and answered a complex cross-cutting question with 6 calls and zero file reads.


Getting Started

Step 1 — Clone and build:

git clone https://github.com/dgdev25/codemind.git
cd codemind
npm install
npm run build
npm link # makes the `codemind` command available globally

Step 2 — Run the installer:

codemind install

Select which editors to configure (Claude Code, Cursor, Windsurf). The installer writes the MCP server config for each, auto-allows tool permissions, and adds usage instructions to ~/.claude/CLAUDE.md.

Step 3 — Restart your editor(s) so they pick up the new MCP server.

Step 4 — Initialize your project:

cd your-project
codemind init -i

The -i flag runs the full index immediately. From here, the MCP server auto-syncs as you edit files.

Manual MCP server setup

The MCP server config is the same format for all supported editors:

{
"mcpServers": {
"codemind": {
"type": "stdio",
"command": "codemind",
"args": ["serve", "--mcp"]
}
}
}
EditorConfig file
Claude Code~/.claude.json
Cursor~/.cursor/mcp.json
Windsurf~/.codeium/windsurf/mcp_config.json

Auto-allow tool permissions in ~/.claude/settings.json:

{
"permissions": {
"allow": [
"mcp__codemind__codemind_search",
"mcp__codemind__codemind_context",
"mcp__codemind__codemind_explore",
"mcp__codemind__codemind_callers",
"mcp__codemind__codemind_callees",
"mcp__codemind__codemind_impact",
"mcp__codemind__codemind_node",
"mcp__codemind__codemind_files",
"mcp__codemind__codemind_status",
"mcp__codemind__codemind_semantic_search",
"mcp__codemind__codemind_similar",
"mcp__codemind__codemind_vector_status",
"mcp__codemind__codemind_flows",
"mcp__codemind__codemind_clusters",
"mcp__codemind__codemind_detect_changes"
]
}
}

Under the Hood

 Your source files
─────────────────
.ts .py .go .rs tree-sitter parses each file into an AST.
.java .rb .swift Language-specific queries extract symbols
.cs .php .kt ... (functions, classes, methods, routes) and
.svelte .vue .liquid .pas relationships (calls, imports, extends).
│
▼
┌─────────────────────────────────────────────────┐
│ .codemind/codemind.db │
│ │
│ nodes ──── edges ──── files │
│ (symbols) (relations) (hashes) │
│ │
│ execution_flows precomputed call chains │
│ node_communities label propagation clusters │
│ │
│ FTS5 full-text index ──┐ │
│ HNSW vector index ├── fused via RRF │
│ (optional, ruVector) ──┘ │
└──────────────────┬──────────────────────────────┘
│ live sync via OS file events
│ + PostEdit hook auto-sync
│
▼
codemind MCP server
──────────────────────────────────────────
codemind_explore deep topic exploration
codemind_search symbol lookup (FTS5 + vector RRF)
codemind_callers who calls this function?
codemind_callees what does this call?
codemind_impact blast radius with confidence tiers
codemind_context task-focused context bundle
codemind_flows precomputed execution call chains
codemind_clusters module community discovery
codemind_detect_changes git diff → affected symbols
codemind_semantic_search find by meaning, not keyword
codemind_similar find equivalent implementations
codemind_node symbol details + source
codemind_files project structure
+ codemind_status, codemind_vector_status
MCP prompts (reusable workflows):
detect_impact pre-commit blast-radius analysis
generate_map architecture overview + Mermaid diagram
explain_flow trace execution from an entry point

References are resolved after extraction: function calls are linked to their definitions, imports to their source files, class hierarchies are traced, and web-framework route patterns are bound to their handler functions.


MCP Tools

ToolWhat it does
codemind_exploreDeep exploration — returns full source sections grouped by file for a topic, in one call. The main workhorse for unfamiliar code.
codemind_contextTask-focused context: entry points, related symbols, and code for a described task.
codemind_searchFast symbol lookup by name. Fuses FTS5 + vector results via RRF when vector index is available.
codemind_callersEvery function/method that calls a given symbol.
codemind_calleesEvery function/method that a symbol calls.
codemind_impactBlast radius — affected symbols grouped by confidence tier (direct / depth-2 / deep).
codemind_flowsPrecomputed execution call chains from entry points (routes, main, exported handlers). Instant — computed at index time.
codemind_clustersModule communities detected by label propagation over call and import edges. Discover module boundaries without knowing folder names.
codemind_detect_changesMap a git diff to affected symbols and their immediate dependents. Pre-commit analysis.
codemind_nodeDetails for a specific symbol: signature, location, optionally source.
codemind_filesIndexed file tree with language and symbol count metadata. Faster than glob.
codemind_semantic_searchNatural language search powered by vector embeddings. Requires --build-vectors.
codemind_similarFind symbols semantically similar to a given one — useful for spotting duplicated logic.
codemind_statusIndex health: file count, node count, edge count, DB size.
codemind_vector_statusVector index sync state: how many nodes are embedded vs. pending.

MCP Prompts

Reusable workflows discoverable by any MCP-compatible editor:

PromptWhat it does
detect_impactPre-commit analysis — runs codemind_detect_changes + codemind_impact and summarises what will break.
generate_mapArchitecture overview — clusters, entry points, file distribution, and a Mermaid diagram.
explain_flowTrace execution from a named entry point through the full call chain.

CLI Reference

codemind # Interactive installer
codemind init [path] # Initialize a project (-i to index immediately)
codemind uninit [path] # Remove CodeMind data from a project
codemind index [path] # Full re-index (--force, --quiet, --build-vectors)
codemind sync [path] # Incremental sync
codemind status [path] # Index statistics
codemind query <term># CLI symbol search (--kind, --limit, --json)
codemind files [path] # File tree (--format tree|flat|grouped, --max-depth)
codemind context <task># Print AI context to stdout (--format, --max-nodes)
codemind affected [files...] # Trace which test files are affected by changed sources
codemind hooks install # Install PostEdit auto-sync hook in Claude Code
codemind skills generate # Generate per-community skill files in .claude/skills/codemind/
codemind serve --mcp # Start the MCP server (used by Claude Code, Cursor, Windsurf)

Smart test targeting with codemind affected

Traces transitive import dependencies from changed source files to find which test files need to run:

# Pass files directly
codemind affected src/auth.ts src/session.ts
# Pipe from git
git diff --name-only HEAD | codemind affected --stdin
# In CI — only run affected tests
AFFECTED=$(git diff --name-only HEAD | codemind affected --stdin --quiet)
[ -n"$AFFECTED" ] && npx vitest run $AFFECTED

For in-editor pre-commit review, use the codemind_detect_changes MCP tool or the detect_impact MCP prompt instead — they map the diff directly to symbol-level impact.

Auto-sync with PostEdit hook

Install a hook that syncs the graph immediately after Claude edits a file (rather than waiting for the 2-second file watcher debounce):

codemind hooks install

Writes a PostToolUse hook to ~/.claude/settings.json that triggers codemind sync on Write/Edit/MultiEdit.

Community-aware skill files

After indexing, generate a per-module context file for each detected code community:

codemind skills generate

Writes .claude/skills/codemind/<module-name>.md for each community with ≥5 members — lists key symbols, entry points, and call chains. No LLM required; purely graph-derived.


Execution Flows

CodeMind precomputes call chains from entry points (route handlers, main, exported init functions) at index time. The codemind_flows MCP tool returns these instantly — no on-demand traversal required.

codemind index # flows are always computed automatically

Entry points are auto-detected: route nodes, functions named main/run/start/init/setup/handler, and similar.

Community Clustering

After indexing, CodeMind runs label propagation over calls + imports + extends edges to detect module communities — groups of tightly connected symbols that form logical boundaries in the codebase.

codemind_clusters # discover module communities
codemind skills generate # generate .claude/skills/codemind/<module>.md per community

Clustering runs automatically after codemind index for repos up to 100k symbols.

Semantic Search

CodeMind includes optional vector embeddings via ruVector (@ruvector/core) — an HNSW index with scalar quantization running entirely on-device.

codemind index --build-vectors

Once built, codemind_semantic_search and codemind_similar become available. codemind_search also automatically fuses FTS5 and vector results via Reciprocal Rank Fusion (RRF) for better ranking. Claude can find a "token refresh flow" or "retry with backoff" without knowing what the function is called.

Vector config in .codemind/config.json:

{
"vector": {
"enabled": true,
"model": "Xenova/all-MiniLM-L6-v2",
"dimensions": 384,
"storagePath": ".codemind/vectors",
"indexOnSync": true,
"batchSize": 64,
"quantization": "scalar"
}
}

Library API

importCodeMindfrom'codemind';// Open an indexed projectconstcg=awaitCodeMind.open('/path/to/project');// Symbol searchconsthits=cg.searchNodes('TokenService');// Graph queriesconstcallers=cg.getCallers(hits[0].node.id);constimpact=cg.getImpactRadius(hits[0].node.id,3);constchain=cg.getCallGraph(hits[0].node.id,4);// AI contextconstcontext=awaitcg.buildContext('fix the refresh token bug',{maxNodes: 20,includeCode: true,format: 'markdown',});// Semantic search (requires --build-vectors)constsimilar=awaitcg.semanticSearch('rate limiting middleware',{limit: 10});// Live synccg.watch();// auto-sync on file savecg.unwatch();cg.close();

Configuration

.codemind/config.json — created automatically on codemind init:

{
"version": 1,
"languages": ["typescript", "javascript"],
"exclude": ["node_modules/**", "dist/**", "build/**", "*.min.js"],
"maxFileSize": 1048576,
"extractDocstrings": true,
"trackCallSites": true
}
FieldDescriptionDefault
languagesLanguages to index. Empty = auto-detect from file extensions.[]
excludeGlob patterns to skip.["node_modules/**", "dist/**", ...]
maxFileSizeSkip files larger than this (bytes). Max 100MB.1048576
extractDocstringsPull docstrings/comments into the graph.true
trackCallSitesRecord line/column of each call.true

Supported Languages

TypeScript · JavaScript · Python · Go · Rust · Java · C# · PHP · Ruby · C · C++ · Swift · Kotlin · Scala · Dart · Svelte · Vue · Liquid · Pascal/Delphi

19 languages, covering .ts.tsx.js.jsx.mjs.py.go.rs.java.cs.php.rb.c.h.cpp.hpp.cc.swift.kt.kts.scala.sc.dart.svelte.vue.liquid.pas.dpr.dpk.lpr


Framework Route Detection

CodeMind emits route nodes and links them to their handler functions, so codemind_callers on a view returns the URL pattern that reaches it.

Supported: Django · Flask · FastAPI · Express · Laravel · Rails · Spring · Gin · chi · gorilla/mux · Axum · actix-web · Rocket · ASP.NET · Vapor · React Router · SvelteKit · Nuxt


Troubleshooting

"CodeMind not initialized" — Run codemind init in the project root first.

MCP server not connecting — Run codemind serve --mcp manually in the terminal to see the error. Usually a missing global install or wrong path in the editor's MCP config file. See the manual setup table above for config file locations per editor.

Symbols missing after editing — The server auto-syncs with a 2-second debounce. Run codemind sync to force an immediate update. For instant sync after Claude edits, run codemind hooks install to add the PostEdit hook.

codemind_flows returns nothing — Execution flows are computed during codemind index. Run a full re-index if flows are missing.

codemind_clusters returns nothing — Community detection runs automatically during codemind index for repos under 100k symbols. Very large repos skip it to keep indexing fast.

Semantic search returns nothing — The vector index needs to be built separately: codemind index --build-vectors. Use codemind_vector_status in Claude Code to check how many nodes are embedded.


License

MIT


Fork of CodeGraph — extended with vector search, semantic embeddings, and the codemind CLI.

Issues

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages