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 hooks-based integration -- no source file reading needed. One code-graph setup command installs transparent PreToolUse hooks that auto-approve CLI calls and enrich search queries with structural graph data.
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
- 25 CLI commands -- find definitions, trace references, blast radius analysis, circular dependency detection, 360-degree symbol context, project statistics, graph export, file structure, file summaries, import analysis, dead code detection, clone detection, graph diff, decorator search, clustering, call chain tracing, rename planning, diff impact, project registry management, daemon control, hooks setup
- Hooks-based Claude Code integration --
code-graph setupinstalls PreToolUse hooks that transparently intercept tool calls, auto-approve CLI invocations, and enrich Grep/Glob searches with structural graph data - Background daemon --
code-graph daemon startlaunches a persistent background process that watches for file changes and keeps the graph index up to date automatically - Multi-project registry --
code-graph project addregisters project aliases for cross-project queries with--projectflag on any query command - 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
- Token-optimized output -- compact prefix-free format with context-aware next-step hints, designed for AI agent consumption (60-90% savings per session)
- Trigram fuzzy matching -- Jaccard similarity for typo-tolerant symbol search with score-ranked suggestions
- Clone detection --
clonesfinds structurally similar code via signature hashing (symbol kind, body size, edge counts, decorators) - Dead code detection --
dead-codeidentifies unreferenced symbols with entry-point exclusions - Graph snapshot/diff -- create named snapshots and compare current graph state against baselines
- Section-scoped context --
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
- Project auto-detection -- most commands auto-detect the project root from the current working directory when no path is given
- File watcher -- incremental re-indexing on file changes with 75ms debounce
- Disk cache -- bincode serialization for instant cold starts
- 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
# Set up Claude Code integration (installs hooks)
# Index a project
# Find a symbol
# What breaks if I change this?
# Start the background daemon for live re-indexing
# Launch the interactive web UI
# Find structurally similar code (clone detection)
# Export dependency graph as Mermaid at package granularity
# Create a named graph snapshot for later comparison
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
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 Install Claude Code hooks for transparent integration
serve Launch the interactive web UI (requires --features web)
structure Show file/directory tree with symbol outlines
file-summary Summarize a single file: role, symbols, imports, dependents
imports List all imports of a file, categorized by type
clones Detect structurally similar code (clone detection)
dead-code Detect dead code: unreachable files and unreferenced symbols
diff Compare two graph snapshots and show structural differences
diff-impact Analyze impact of git-changed files on the dependency graph
decorators Find symbols by decorator/attribute pattern
clusters Discover functional clusters via graph analysis
flow Trace data/call flow paths between two symbols
project Manage the project registry (add, remove, list, show)
daemon Manage the background daemon (start, stop, status)
rename Plan a symbol rename with impact analysis
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.
watch
Start a standalone file watcher that re-indexes incrementally on changes.
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
Install Claude Code hooks for transparent code-graph integration.
See Claude Code integration for details on what this configures.
serve
Launch the interactive web UI with graph visualization.
Requires building with
--features web. Add--features ragfor the conversational agent.
structure
Show the file/directory tree with symbol counts and outlines.
file-summary
Compact summary of a single file: role, symbols, imports, and dependents.
imports
List all imports of a file, categorized by type (internal, external, builtin).
clones
Detect structurally similar code via signature hashing. Groups symbols with identical structural fingerprints (kind, body size, edge counts, decorator count).
dead-code
Detect unreferenced symbols and unreachable files with entry-point exclusions.
diff
Compare two graph snapshots and show structural differences (added/removed symbols, changed edges).
diff-impact
Analyze the dependency graph impact of git-changed files. Takes a git ref to diff against.
decorators
Find symbols by decorator/attribute pattern across all languages.
clusters
Discover functional clusters (groups of highly-coupled symbols) via graph analysis.
flow
Trace call/data flow paths between two symbols.
project
Manage the multi-project registry for cross-project queries.
Once registered, use --project on any query command:
daemon
Manage the background daemon that watches for file changes and keeps the index up to date.
rename
Plan a symbol rename: lists all files and lines that reference the symbol, with the proposed changes.
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 |
Claude Code integration
code-graph integrates with Claude Code via PreToolUse hooks -- shell scripts that run before Claude executes tool calls. This approach is transparent, requires no background server, and works with any Claude Code version.
How it works
-
code-graph setupinstalls two hook scripts into.claude/hooks/:codegraph-pretool-bash.sh-- interceptsBashtool calls. When the command starts withcode-graph, the hook auto-approves it (no permission prompt). All other commands pass through untouched.codegraph-pretool-search.sh-- interceptsGrepandGlobtool calls. When the search pattern looks like a code symbol (PascalCase, snake_case, camelCase), the hook enriches the response withcode-graph findresults as additional context. String literals, file paths, TODOs, and regex patterns pass through to native search.
-
Setup also configures
.claude/settings.json:- Adds hook entries under
hooks.PreToolUse - Adds
Bash(code-graph *)topermissions.allowfor auto-approval - Cleans up any stale configuration from previous versions
- Adds hook entries under
-
The result: Claude Code transparently uses code-graph for structural queries while keeping native Grep/Glob for text searches. No manual tool selection needed.
Setup
# Project-level (recommended): hooks in .claude/hooks/
# Global: hooks in ~/.claude/hooks/ (available in all projects)
# Remove hooks and permissions
Recommended CLAUDE.md instructions
To maximize Claude Code's use of code-graph for navigation, add the following to your project's CLAUDE.md:
NEVER use Grep or Glob to find symbol definitions, trace references, or analyze dependencies.
ALWAYS use code-graph CLI commands instead -- they are faster, more accurate, and understand the full AST.
Use Read/Grep/Glob ONLY for:
- --
Configuration
Optional code-graph.toml in your project root:
# Additional path patterns to exclude from indexing (beyond .gitignore and node_modules).
= ["vendor/", "dist/", "build/"]
# Impact analysis thresholds for risk tier classification.
[]
= 20 # Files above this count are HIGH risk (default: 20)
= 5 # Files above this count are MEDIUM risk (default: 5)
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 | ~39,000 |
| Tests | 551 |
| CLI commands | 25 |
| Rust edition | 2024 |
| Binary size | ~12 MB (static, zero runtime deps) |
License
MIT