code-graph
High-performance code intelligence engine that indexes TypeScript, JavaScript, Rust, Python, and Go codebases into a queryable dependency graph. Built in Rust, designed for AI agents.
Gives Claude Code direct access to your codebase's structure via MCP -- no source file reading needed. Twenty MCP tools cover symbol search, reference tracing, blast radius analysis, circular dependency detection, dead code detection, decorator search, clustering, call chain tracing, rename planning, diff impact, graph export, batch queries, snapshot/diff, and multi-project management.
Features
- Multi-language parsing -- TypeScript, TSX, JavaScript, JSX, Rust, Python, and Go via tree-sitter with full symbol extraction (functions, classes, interfaces, types, enums, components, methods, properties, structs, traits, impl blocks, macros, pub visibility, async/sync functions, decorators, type aliases, struct tags)
- Python parsing -- functions (sync/async), classes, variables, type aliases (PEP 695), decorators with framework detection (Flask, FastAPI, Django)
- Go parsing -- functions, methods, type specs, struct tags,
//go:directives as decorators, visibility by export convention, go.mod resolution - Decorator/attribute extraction -- unified across all 5 languages with framework inference (NestJS, Flask, FastAPI, Actix, Angular)
- Dependency graph -- file-level and symbol-level edges: imports, calls, extends, implements, type references, has-decorator, child-of, embeds
- Import resolution -- TypeScript path aliases (tsconfig.json), barrel files (index.ts re-exports), monorepo workspaces, Rust crate-root module resolution with Cargo workspace discovery, Python package resolution, Go module resolution
- Twenty query types -- find definitions, trace references, blast radius analysis, circular dependency detection, 360-degree symbol context, project statistics, graph export, file structure, file summaries, import analysis, batch queries, dead code detection, graph diff, project registration, project listing, decorator search, clustering, call chain tracing, rename planning, diff impact
- Interactive web UI --
code-graph servelaunches an Axum backend + Svelte frontend with WebGL graph visualization, file tree, code panel, search, and real-time WebSocket updates - RAG conversational agent -- hybrid retrieval (structural graph + vector embeddings), multi-provider LLM support (Claude, OpenAI, Ollama), session memory, source citations
- BM25 hybrid search -- tiered pipeline: exact match → trigram fuzzy → BM25 → Reciprocal Rank Fusion
- Confidence scoring -- High/Medium/Low confidence tiers on impact analysis based on graph distance
- MCP server -- zero-config (defaults to cwd), exposes all queries as tools for Claude Code over stdio, optional
--watchflag for auto-reindex - Editor auto-setup --
code-graph setupconfigures MCP for Claude Code, Cursor, and Windsurf - Trigram fuzzy matching -- Jaccard similarity for typo-tolerant symbol search with score-ranked suggestions
- Batch queries --
batch_queryruns up to 10 queries in a single MCP call with single graph resolution - Dead code detection --
find_dead_codeidentifies unreferenced symbols with entry-point exclusions - Graph snapshot/diff -- create named snapshots and compare current graph state against baselines
- Multi-project support --
register_projectandlist_projectsfor managing multiple codebases from a single MCP server - Section-scoped context --
get_contextwith targeted sections for 60-80% token savings per query - Graph export -- DOT and Mermaid formats at symbol, file, or package granularity
- Non-parsed file awareness -- config files, docs, and assets visible in the graph
- File watcher -- incremental re-indexing on file changes with 75ms debounce
- Disk cache -- bincode serialization for instant cold starts
- Token-optimized output -- compact prefix-free format with context-aware next-step hints, designed for AI agent consumption (60-90% savings per session)
- [mcp] config section -- persistent project-level MCP defaults in
code-graph.toml - Feature flags --
--features webfor web UI,--features ragfor RAG agent
Install
This installs the code-graph binary to ~/.cargo/bin/.
To include the web UI or RAG agent, enable feature flags:
From source
Build manually
# Binary at target/release/code-graph
Requires Rust 1.85+ (edition 2024). No runtime dependencies -- tree-sitter grammars are statically linked.
Quick start
# Index a TypeScript/JavaScript project
# Index a Rust project
# Index a Python project
# Index a Go project
# Find a symbol
# What breaks if I change this?
# Start MCP server for Claude Code (zero-config, defaults to cwd)
# Start MCP server with auto-reindex on file changes
# Launch the interactive web UI
# Export dependency graph as Mermaid at package granularity
# Create a named graph snapshot for later comparison
# Auto-configure MCP for your editor
CLI reference
Usage: code-graph <COMMAND>
Commands:
index Index a project directory
find Find a symbol's definition (file:line location)
refs Find all references to a symbol across the codebase
impact Show the transitive blast radius of changing a symbol
circular Detect circular dependencies in the import graph
stats Project statistics overview
context 360-degree view of a symbol: definition, references, callers, callees
mcp Start an MCP stdio server exposing graph queries as tools
watch Start a file watcher for incremental re-indexing
export Export dependency graph to DOT or Mermaid format
snapshot Create, list, or delete named graph snapshots
setup Auto-configure MCP for Claude Code, Cursor, or Windsurf
serve Launch the interactive web UI (requires --features web)
index
Index a project, discovering and parsing all TypeScript/JavaScript, Rust, Python, and Go files.
find
Find symbol definitions by name or regex pattern. Supports trigram fuzzy matching for typo-tolerant search.
Symbol kinds: function, class, interface, type, enum, variable, component, method, property, struct, trait, impl, macro
refs
Find all files and call sites that reference a symbol.
impact
Show the transitive blast radius -- everything affected if a symbol changes.
circular
Detect circular dependency cycles in the import graph (file-level).
stats
Project overview: file count, symbol breakdown by kind, import summary.
context
360-degree view combining definition, references, callers, and callees. Supports section scoping for targeted queries with 60-80% token savings.
mcp
Start an MCP stdio server exposing graph queries as tools for Claude Code.
watch
Start a standalone file watcher that re-indexes incrementally on changes.
The
mcpcommand starts its own embedded watcher automatically when--watchis passed -- you don't need to runwatchseparately.
export
Export the dependency graph to DOT or Mermaid format at symbol, file, or package granularity.
snapshot
Create, list, or delete named graph snapshots for change tracking and comparison.
setup
Auto-configure MCP integration for your editor.
serve
Launch the interactive web UI with graph visualization.
Requires building with
--features web. Add--features ragfor the conversational agent.
Output formats
All query commands support --format:
| Format | Description |
|---|---|
compact |
One-line-per-result, token-optimized (default) |
table |
Human-readable columns with ANSI colors |
json |
Structured JSON for programmatic use |
MCP integration
Claude Code setup
Or use the auto-setup command:
This registers code-graph as a user-scoped MCP server available in all your projects. The --watch flag enables auto-reindex on file changes.
Available tools
Once connected, Claude Code gets access to twenty tools:
| Tool | Description |
|---|---|
find_symbol |
Find symbol definitions by name or regex |
find_references |
Find all files and call sites referencing a symbol |
get_impact |
Get the transitive blast radius of changing a symbol |
detect_circular |
Detect circular dependency cycles |
get_context |
360-degree view: definition + references + callers + callees |
get_stats |
Project overview: files, symbols, imports |
export_graph |
Export dependency graph to DOT or Mermaid format |
get_structure |
File/directory tree with symbol counts |
get_file_summary |
Compact summary of a file's symbols and imports |
get_imports |
List imports for a file or across the project |
batch_query |
Run up to 10 queries in a single call |
find_dead_code |
Detect unreferenced symbols with entry-point exclusions |
get_diff |
Compare current graph against a named snapshot |
register_project |
Register an additional project for multi-project queries |
list_projects |
List all registered projects |
find_by_decorator |
Find symbols by decorator/attribute pattern |
find_clusters |
Hierarchical clustering by coupling/cohesion |
trace_flow |
Find call chains between two symbols |
plan_rename |
Plan symbol renames with impact analysis |
get_diff_impact |
Git-diff-based impact analysis |
The MCP server loads from disk cache on startup for near-instant cold starts, runs an embedded file watcher for live updates (with --watch), and suggests similar symbol names via trigram fuzzy matching when a search yields no results.
Recommended CLAUDE.md instructions
Claude Code defaults to reading source files with its built-in glob/grep/read tools. Without explicit guidance, it won't use code-graph even when the MCP server is running. Add the following to your project's CLAUDE.md so Claude uses graph queries instead of file reading for codebase navigation:
NEVER use Grep or Glob to find symbol definitions, trace references, or analyze dependencies.
ALWAYS use code-graph MCP tools instead -- they are faster, more accurate, and understand the full AST.
Use Read/Grep/Glob ONLY for:
- --
Permission whitelisting
By default, Claude Code asks for confirmation on every MCP tool call. To auto-approve code-graph tools (they are read-only and safe), add this to .claude/settings.json in your project root:
Configuration
Optional code-graph.toml in your project root:
[]
= ["vendor/", "dist/", "build/"]
[]
= "compact" # Output format: compact, table, json
= true # Auto-start file watcher
By default, code-graph respects .gitignore patterns and always excludes node_modules/ and target/.
How it works
- Walk -- discovers TS/JS, Rust, Python, and Go files respecting
.gitignoreand exclusion rules - Parse -- tree-sitter extracts symbols, imports, exports, and relationships from each file. TypeScript/JavaScript parsing covers functions, classes, interfaces, type aliases, enums, and components. Rust parsing covers functions, structs, enums, traits, impl blocks, type aliases, constants, statics, and macro definitions with visibility tracking. Python parsing covers functions (sync/async), classes, variables, type aliases (PEP 695), and decorators. Go parsing covers functions, methods, type specs, struct tags, and
//go:directives. - Resolve -- maps import specifiers to actual files. For TypeScript/JavaScript: oxc_resolver handles path aliases, barrel files, and workspaces. For Rust: crate-root module tree walk with use-path classification (crate/super/self/external/builtin) and Cargo workspace discovery. For Python: package resolution with
__init__.pydetection and relative imports. For Go: go.mod module resolution with package path mapping. - Build graph -- constructs a petgraph with file nodes, symbol nodes, and typed edges (imports, calls, extends, implements, type references, has-decorator, child-of, embeds)
- Cache -- serializes the graph to disk with bincode for fast reloads
- Query -- traverses the graph to answer structural questions without reading source files
- Watch -- monitors filesystem events and incrementally updates the graph (re-parses only changed files)
Project stats
| Metric | Value |
|---|---|
| Languages supported | TypeScript, JavaScript, Rust, Python, Go |
| Lines of Rust code | ~38,000 |
| Tests | 492 |
| CLI commands | 13 |
| MCP tools | 20 |
| Rust edition | 2024 |
| Binary size | ~12 MB (static, zero runtime deps) |
License
MIT