code-graph
High-performance code intelligence engine that indexes TypeScript/JavaScript 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. Find symbols, trace references, analyze blast radius, and detect circular dependencies through pre-built graph queries.
Features
- Tree-sitter parsing — TypeScript, TSX, JavaScript, JSX with full symbol extraction (functions, classes, interfaces, types, enums, components, methods, properties)
- Dependency graph — file-level and symbol-level edges: imports, calls, extends, implements, type references
- Import resolution — TypeScript path aliases (tsconfig.json), barrel files (index.ts re-exports), monorepo workspaces
- Six query types — find definitions, trace references, blast radius analysis, circular dependency detection, 360-degree symbol context, project statistics
- MCP server — exposes all queries as tools for Claude Code over stdio
- File watcher — incremental re-indexing on file changes with 75ms debounce
- Disk cache — bincode serialization for instant cold starts
- Token-optimized output — compact format designed for AI agent consumption
Install
This installs the code-graph binary to ~/.cargo/bin/.
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 project
# Find a symbol
# What breaks if I change this?
# Start MCP server for Claude Code
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
index
Index a project, discovering and parsing all TypeScript/JavaScript files.
find
Find symbol definitions by name or regex pattern.
Symbol kinds: function, class, interface, type, enum, variable, component, method, property
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.
watch
Start a standalone file watcher that re-indexes incrementally on changes.
The
mcpcommand starts its own embedded watcher automatically — you don't need to runwatchseparately.
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
Add to your Claude Code MCP config (~/.claude/claude_desktop_config.json or project .mcp.json):
Available tools
Once connected, Claude Code gets access to six 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 |
The MCP server loads from disk cache on startup for near-instant cold starts, runs an embedded file watcher for live updates, and suggests similar symbol names 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/"]
By default, code-graph respects .gitignore patterns and always excludes node_modules/.
How it works
- Walk — discovers TS/JS files respecting
.gitignoreand exclusion rules - Parse — tree-sitter extracts symbols, imports, exports, and relationships from each file
- Resolve — maps import specifiers to actual files using oxc_resolver (handles path aliases, barrel files, workspaces)
- Build graph — constructs a petgraph with file nodes, symbol nodes, and typed edges (imports, calls, extends, implements, type references)
- 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)