Local knowledge graph for Claude Code — call graphs, impact radius, and code search via MCP, powered by Tree-sitter and SQLite. Supports Python, JS/TS, Go, Rust, Java, C#, Ruby, C/C++, Swift and more.
Project description
claude-graph
claude-graph is a local MCP server that builds a structural knowledge graph of your codebase for Claude Code. It answers questions like "what calls this function?", "what breaks if I change this file?", and "is this covered by tests?" — without sending any code to the cloud.
It parses your repo with Tree-sitter, stores a call graph (functions, classes, calls, imports, test-coverage links) in a local SQLite file, and exposes it to Claude Code over the Model Context Protocol (MCP) — so Claude can answer structural questions without reading your entire repository into context.
Why this exists, and what it deliberately doesn't do
Built for a corporate setting with one hard requirement: everything happens locally, with zero network calls, ever.
- No cloud or local embeddings/semantic search. Claude Code itself is already the LLM in the loop — it reads the candidates this tool returns (keyword search + graph neighbors) and does the semantic reasoning itself. No vectors, no model downloads, no API calls.
- No hooks. Nothing runs automatically when you edit a file. You (or
Claude Code) call
build_or_update_graphexplicitly. - No multi-platform support. This only configures Claude Code. It won't touch Cursor, Windsurf, Zed, or anything else.
- No home-directory writes. Everything this tool writes lives inside
the repository you run it in (
.claude-graph/,.mcp.json,.claude/skills/). - No telemetry, no daemon, no multi-repo registry.
See tests/test_no_network.py for the automated proof: it runs a full
build + query + impact + search + viz + MCP server startup cycle with
outbound sockets disabled and asserts nothing tries to connect anywhere.
Token savings benchmark
Real numbers — benchmarked by running
claude-graph buildon a shallow clone of Djangomain.
Build time: 17 seconds
Files: 3,040
Nodes: 45,096 (functions + classes + modules)
Edges: 938,763 (calls + imports + tests_for)
Without claude-graph, Claude Code answers structural questions by reading entire source files into context. With claude-graph, it issues a single MCP tool call and receives only the relevant nodes and edges.
| Query | Tokens (naive — send matching files) | Tokens (claude-graph) | Reduction |
|---|---|---|---|
callers_of HttpResponse |
112,991 | 15,455 | 7× less |
callees_of dispatch |
92,539 | 3,143 | 29× less |
callers_of authenticate |
46,032 | 5,278 | 8× less |
search permission |
155,915 | 659 | 236× less |
Dumping the entire Django source naively: 1,475,429 tokens — 7.4× Claude's 200k context window. Claude cannot reason about Django's structure at all without a tool like this.
claude-graph makes it possible in a single tool call. The graph is built once (claude-graph build) and updated incrementally (claude-graph update) — queries are instant SQLite lookups, not re-parses.
Contents
- Requirements
- Install
- CLI
- MCP tools
- Graph visualization
- Supported languages
- How calls are resolved
- Search behavior
- Known limitations
- For teammates installing this themselves
- Releasing (maintainers)
Requirements
- macOS, Linux, or Windows
- Python 3.11+
- git
Install
pip install claude-graph
For file-watching support (claude-graph watch):
pip install "claude-graph[watch]"
GitHub Packages doesn't support pip-installable Python packages directly (only npm, Docker, Maven, Gradle, NuGet, and RubyGems are native registry types there), so if you'd rather install straight from this repo without going through PyPI, each release also ships the wheel as a downloadable asset:
pip install https://github.com/mohansagark/claude-graph/releases/download/v0.1.2/claude_graph-0.1.2-py3-none-any.whl
Or from source, for local development or to track main:
git clone https://github.com/mohansagark/claude-graph.git
cd claude-graph
pip install -e .
Docker
A container image is published to GitHub Container Registry on every release — this is a real GitHub Package, unlike the two options above:
docker pull ghcr.io/mohansagark/claude-graph:latest
docker run --rm -v "$PWD:/repo" ghcr.io/mohansagark/claude-graph build
Every command mounts your repo at /repo and takes the same arguments as
the native CLI, e.g. docker run --rm -v "$PWD:/repo" ghcr.io/mohansagark/claude-graph viz --symbol foo.
Note this is more friction than pip install for day-to-day use — in
particular, wiring claude-graph serve up as Claude Code's MCP server via
Docker means .mcp.json's command becomes a docker run -v ... invocation
instead of a bare binary, which is why claude-graph install (below)
generates the native-binary form by default. Docker is mainly useful when
you don't want a Python environment on the host at all.
Then, inside the project you want a graph for:
cd /path/to/your/project
claude-graph install # writes .mcp.json and .claude/skills/ in that repo
claude-graph build # parses the repo and writes .claude-graph/graph.db
Restart Claude Code (or run /mcp to confirm claude-graph is
connected) and ask it something structural, e.g. "what calls
parse_file in this repo?"
Build first. Calling any of the MCP query tools (query_graph_tool,
get_impact_radius_tool, search_nodes_tool) before a graph has ever
been built will not error — it silently returns empty results, and as a
side effect creates an empty .claude-graph/graph.db file. Run
claude-graph build (or let Claude Code call build_or_update_graph
first) before expecting real answers.
CLI
| Command | What it does |
|---|---|
claude-graph build |
Full parse of every git-tracked file |
claude-graph update |
Re-parses only changed files since the last build |
claude-graph status |
Prints node/edge/file counts (--json for machine-readable output) |
claude-graph install |
Writes .mcp.json and .claude/skills/ for this repo |
claude-graph serve |
Starts the MCP server (stdio) — Claude Code launches this itself |
claude-graph viz |
Render an interactive HTML graph view and open it in the browser (--symbol NAME or --impact FILE... to scope it, -o PATH to change output, --max-nodes N to cap node count, --no-open to skip browser) |
claude-graph watch |
Watch for file changes and auto-run incremental updates (requires pip install claude-graph[watch]) |
claude-graph doctor |
Health check: grammars, FTS5, git, MCP wiring, graph existence |
claude-graph query PATTERN TARGET |
Run a structural query (callers_of, callees_of, imports_of, tests_for, file_summary) |
claude-graph search QUERY |
Keyword search over function/class names |
Every command accepts --repo PATH to target a repo other than the
current directory. status, install, viz, doctor, query, and
search accept --json for machine-readable output.
MCP tools
| Tool | Purpose |
|---|---|
build_or_update_graph |
Full build if no graph exists, incremental update otherwise |
get_graph_stats |
Node/edge/file counts, languages detected |
query_graph_tool |
callers_of / callees_of / imports_of / tests_for / file_summary |
get_impact_radius_tool |
Blast radius of a set of changed files |
search_nodes_tool |
Keyword search over function/class names and signatures |
render_graph_tool |
Render the graph (or a scoped neighborhood) to a self-contained local HTML file |
Graph visualization
claude-graph viz (or the render_graph_tool MCP tool) writes a single
self-contained HTML file to .claude-graph/graph.html — open it directly in
a browser via file://, no server involved. It embeds a vendored copy of
D3 (ISC license) directly into the file, so it works fully offline, same as
everything else in this tool. The screenshot above is real output — a small
demo app rendered with claude-graph viz, no scoping.
claude-graph viz # the whole graph (capped at 500 nodes by default)
claude-graph viz --symbol NAME # a function/class's direct
# callers, callees, and its
# file's imports
claude-graph viz --impact FILE [FILE...] # the impact radius of those
[--depth N] # changed files, laid out
# visually
claude-graph viz --max-nodes 200 # override the cap
claude-graph viz --max-nodes 0 # no cap (may be slow on large repos)
claude-graph viz -o custom/path.html # change the output path
Click a node to highlight its direct neighborhood and see its file/line in
a side panel; drag to reposition; scroll to zoom; type in the search box to
find a node by name. Use the filter panel (bottom-left) to toggle node kinds
(function/class/module) and edge kinds (calls/imports/tests_for) live.
Nodes are grouped into translucent file-cluster hulls — toggle them off in
the filter panel if they add noise. For very large repos use --max-nodes N
to cap the view at the N highest-degree nodes.
Supported languages
31 languages built in. Powered by tree-sitter-language-pack which bundles 306 grammars — add any of them with a single .claude-graph/languages.toml entry, no code change needed.
| Language | Extensions |
|---|---|
| Python | .py |
| JavaScript | .js .jsx .mjs .cjs |
| TypeScript | .ts |
| TSX | .tsx |
| Go | .go |
| Rust | .rs |
| Java | .java |
| C# | .cs |
| Ruby | .rb |
| C | .c .h |
| C++ | .cpp .cc .cxx .hpp .hh |
| Swift | .swift |
| Kotlin | .kt .kts |
| Scala | .scala .sc |
| PHP | .php .phtml |
| Dart | .dart |
| Elixir | .ex .exs |
| Bash / Zsh | .sh .bash .zsh |
| Lua | .lua |
| Zig | .zig |
| Dockerfile | Dockerfile .dockerfile |
| HCL / Terraform | .tf .hcl |
| Nix | .nix |
| CMake | CMakeLists.txt .cmake |
| Solidity | .sol |
| CUDA | .cu .cuh |
| R | .r .R |
| Julia | .jl |
| Gleam | .gleam |
| Cairo | .cairo |
Add more by dropping a .claude-graph/languages.toml into your repo —
see claude_graph/default_languages.toml for the schema (extensions,
tree-sitter grammar name, and the node types that count as a
function/class/import/call for that grammar). No code change needed.
How calls are resolved
- A
callsedge's source (caller) is always a function-kind node — only functions/methods make calls in this graph. - A
callsedge's target prefers a function match; if no function with that name exists, it falls back to a class match (a call to a class name is treated as an instantiation, e.g.Foo()). - One
callsedge is recorded per call site. If the same function callsbar()twice, you get two edges — this is intentional, not a bug, so call counts reflect actual call-site frequency.
Search behavior
- Search runs over SQLite FTS5 when available. Your query is split into
tokens and each token is wrapped as a quoted phrase before being
handed to FTS5 (e.g.
foo-bar bazbecomes"foo-bar" "baz") — FTS5's own query operators (AND,OR,NEAR, prefix*, column filters, etc.) are not supported by design; special characters are treated as literal text, not syntax. - If the local SQLite build lacks FTS5, search falls back to a
LIKEquery, with%,_, and\escaped so wildcard-like characters in your query are matched literally rather than interpreted as SQL wildcards. - An empty or whitespace-only query returns
[]immediately in both modes.
Known limitations
- Bare-name, coarse node model. Nodes are keyed by
(file, kind, name), not by fully-qualified path — so two same-kind, same-named symbols in the same file (e.g. two methods named the same thing on two different classes in that file) collapse into a single graph node, and cross-file call resolution is a global name-heuristic: a call tosave()is matched against every function namedsave()in the graph, not just the one actually in scope. Two files with a same-named function can therefore produce over-broadcallers_of/callees_ofresults (or, in the same-file collision case, an under-broad merged one). This is a deliberate precision/recall trade-off for a tool whose answers are read by an LLM that can disambiguate from context — better to flag too much than miss a real caller. See the docstrings inclaude_graph/query.pyfor where this shows up in each query function. tests_forlinking is naming-convention only (test_foo.py/foo_test.py/foo.spec.ts/foo.test.tsmatched againstfoo.py/foo.ts). Tests that don't follow one of these conventions aren't linked.- Import resolution is best-effort path matching, not real module
resolution — it won't follow
tsconfig.jsonpath aliases or Python namespace packages. - Incremental
updateonly re-links edges for files whose content changed. If you move a symbol to another file, calls into it from files you didn't touch keep pointing at the old resolution until the next fullclaude-graph build. claude-graph viz's whole-graph view defaults to a cap of 500 nodes (highest-degree first). Override with--max-nodes Nor remove the cap entirely with--max-nodes 0. On very large codebases use--symbolor--impactfor a focused view instead. It can also pick up vendored/minified third-party files checked into the repo (e.g. a bundled.jslibrary) as noisy, densely-connected nodes — exclude them via.claude-graph/languages.tomlif that happens.
For teammates installing this themselves
git clone https://github.com/mohansagark/claude-graph.git
cd claude-graph
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
Releasing (maintainers)
Publishing to PyPI is automated via
.github/workflows/publish.yml using PyPI
Trusted Publishing (OIDC — no API token stored in this repo). Bump the
version in pyproject.toml, then cut a
GitHub Release;
publishing the release triggers the workflow, which builds the sdist/wheel
and uploads them to PyPI.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_graph-0.2.3.tar.gz.
File metadata
- Download URL: claude_graph-0.2.3.tar.gz
- Upload date:
- Size: 242.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
315c24a36e5ef5fb7e891d36effa333f8268c332166107e5d9654de49e4e1e9c
|
|
| MD5 |
9b65a82b0ba9d8373f5cd95bfa1c5ea8
|
|
| BLAKE2b-256 |
7ad3e30923ed7e80e87ce2e39c2f1bb5f31723d49ef8a20a5323469e845bb2ad
|
Provenance
The following attestation bundles were made for claude_graph-0.2.3.tar.gz:
Publisher:
publish.yml on mohansagark/claude-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_graph-0.2.3.tar.gz -
Subject digest:
315c24a36e5ef5fb7e891d36effa333f8268c332166107e5d9654de49e4e1e9c - Sigstore transparency entry: 2234055021
- Sigstore integration time:
-
Permalink:
mohansagark/claude-graph@717fb5928186779e92de40e212cb634744ed841c -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/mohansagark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@717fb5928186779e92de40e212cb634744ed841c -
Trigger Event:
release
-
Statement type:
File details
Details for the file claude_graph-0.2.3-py3-none-any.whl.
File metadata
- Download URL: claude_graph-0.2.3-py3-none-any.whl
- Upload date:
- Size: 134.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60a6d9556e2db7810045ac5ae96cde266146657cb40189fcc197c83cbb5c34e7
|
|
| MD5 |
1c8061d6b9f8d914ffb003136bedaeb4
|
|
| BLAKE2b-256 |
a690d6df8cd301107e1b10d45d442036a9b31b1e4e1be6a7566a81629d317b6c
|
Provenance
The following attestation bundles were made for claude_graph-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on mohansagark/claude-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_graph-0.2.3-py3-none-any.whl -
Subject digest:
60a6d9556e2db7810045ac5ae96cde266146657cb40189fcc197c83cbb5c34e7 - Sigstore transparency entry: 2234055892
- Sigstore integration time:
-
Permalink:
mohansagark/claude-graph@717fb5928186779e92de40e212cb634744ed841c -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/mohansagark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@717fb5928186779e92de40e212cb634744ed841c -
Trigger Event:
release
-
Statement type: