graphify: The Tool That Turns Codebases Into Maps Instead of Search Results

A Python skill for AI coding assistants that builds a structured knowledge graph from code, docs, and images, then uses topology, clustering, and labeled inference to guide understanding.

10 min read · safishamsi/graphify

A developer stands at the edge of a sprawling paper city made of files, folders, and linked notes. In front of them, a hand-drawn transit map rises out of the codebase, with clustered districts and routes leading toward a central hub. The image explains graphify’s core promise: navigate relationships instead of hunting through text.
graphify replaces file-by-file search with a map of the codebase, so the assistant can move through neighborhoods instead of snippets.
Key Takeaways

From Grep to Navigation

Most AI coding workflows still behave like search engines. You ask a question, they rummage through text, and you get back a pile of fragments. graphify is trying to replace that habit with something better: a navigable map of the repository.

That matters because codebases are not just documents. They are systems of dependencies, imports, ownership, and intent. A keyword search can find a symbol, but it cannot tell you which parts of the repo belong together.

Type `/graphify` in Claude Code - it reads your files, builds a knowledge graph, and gives you back structure you didn't know was there.

safishamsi, Maintainer · README.md at v2 · safishamsi/graphify
On one side, a tangled stack of search results sits in a heap. On the other, the same information is arranged as a clean map with clustered districts and connecting routes. The contrast explains why topology is more useful than a flat list of snippets for codebase understanding.
graphify is not just a better index. It changes the shape of the question from “what matches?” to “what belongs together?”

The Real Trick: Topology as Retrieval

The weird, important idea is that graphify does not depend on a vector database to decide what is relevant. It uses the graph itself. The structure of the repo becomes the similarity signal, which is a sharp break from the usual chunk-and-embed workflow.

That choice changes the whole retrieval model. Instead of asking, “Which text chunks are nearest?” graphify asks, “Which nodes live in the same neighborhood, and how do they connect?” That is a more honest fit for code, where adjacency often matters more than semantic fuzziness.

The graph is not an output format. It is the search space itself.

Default RAG / vector searchgraphify
Nearest-neighbor text matchingTopology is the retrieval signal
Chunking code into flat blobsPreserving structured relationships
Opaque similarity scoresLabeled provenance on edges
One long context dumpClusters and neighborhoods

Two Passes, Two Kinds of Truth

graphify’s trust model is what keeps it from feeling like a gimmick. It runs a deterministic AST pass first, then a semantic pass for documents and images. Those are not the same kind of knowledge, and the project does not pretend they are.

The AST layer is grounded. It extracts classes, functions, imports, and call relationships with tree-sitter. The semantic layer is interpretive. It uses vision and language models to pull concepts out of PDFs, markdown, screenshots, diagrams, and whiteboard photos.

Every relationship is tagged `EXTRACTED` (found directly in source), `INFERRED` (reasonable inference, with a confidence score), or `AMBIGUOUS` (flagged for review). You always know what was found vs guessed.

safishamsi, Maintainer · README.md at v2 · safishamsi/graphify

That labeling is the quiet innovation. A lot of AI tools blur facts, guesses, and summaries into one slurry. graphify keeps the boundary visible, which makes downstream analysis easier to trust.

How graphify Builds the Graph

The pipeline is straightforward, but the implementation discipline matters. `extract.py` does the hard structural work. `build.py` merges the layers. The result is not a pile of artifacts, but a graph with stable identity, preserved source locations, and retained directionality.

# Conceptual shape of the pipeline
ast_graph = extract_code_structure(files)
semantic_graph = ingest_docs_and_images(inputs)
merged = build_graph(ast_graph, semantic_graph)
clusters = cluster_graph(merged)
report = analyze_graph(merged, clusters)

# Output is then used by the assistant
# to consult GRAPH_REPORT.md before raw file search.

A few details do a lot of work. Stable IDs keep nodes consistent across runs. Idempotent node insertion lets richer semantic labels overwrite thinner structural ones without losing the original anchor. Even in an undirected graph, source and target metadata preserve who points to whom.

Implementation choiceWhy it matters
Stable IDsThe same symbol keeps the same identity across runs
Idempotent mergesStructural facts and semantic labels can coexist
Preserved source locationsThe graph still points back to the original file
Retained edge directionCall relationships stay readable even in an undirected store

Why Clustering Matters More Than Search

Clustering is where graphify turns raw structure into something an assistant can actually use. Leiden community detection groups densely connected nodes into neighborhoods, then recursively splits anything too large. That is not cosmetic organization. It is context control.

The point is to keep the assistant inside a small, coherent patch of the codebase instead of dumping the entire city on the table. That is the difference between being oriented and being overwhelmed.

Put differently, graphify is not just indexing. It is compression with structure preserved.

Flat retrievalClustered retrieval
Returns isolated matchesReturns related neighborhoods
Expands context indiscriminatelyKeeps context bite-sized
Treats every hit as equalPrioritizes dense structural regions
Forces manual synthesisPre-synthesizes likely relationships

What the Analyzer Actually Finds

`analyze.py` is where the graph turns into editorial judgment. It looks for god nodes, surprising connections, and structural patterns that are worth a human’s attention. The interesting part is that it filters out noisy hubs like `__init__.py`, which may be central but are not always meaningful.

That distinction is important. Centrality alone can lie. A node can be busy without being informative. graphify tries to separate high-traffic plumbing from the abstractions that actually explain the system.

Fully multimodal. Drop in code, PDFs, markdown, screenshots, diagrams, whiteboard photos, even images in other languages - graphify uses Claude vision to extract concepts and relationships from all of it and connects them into one graph.

safishamsi, Maintainer · README.md at v2 · safishamsi/graphify

That is where the project starts to feel less like an indexer and more like a research assistant for a messy repo. It can surface a paper, a screenshot, and a function definition as part of the same argument.

Teaching the Assistant to Use the Map

The smartest product move in graphify is not in the parser. It is in the hook pattern. The tool nudges Claude Code to read `GRAPH_REPORT.md` before it falls back to raw file search, which changes the assistant’s default behavior instead of relying on user discipline.

That matters because tools win when they reshape habits. If the assistant learns to consult the map first, the graph stops being a nice export and becomes part of the workflow.

Without graphifyWith graphify
Search raw files firstRead the graph report first
Context is assembled on demandContext is pre-shaped into neighborhoods
The assistant guesses its way aroundThe assistant starts with structure
Users repeat the same orientation workThe map carries that burden once

In practice, that is the difference between a repo browser and a repo guide.

Who This Is For

graphify is for people who keep running into the same failure mode: a codebase is too large, too mixed, or too intertwined to understand by brute-force search. That includes new contributors, researchers with document-heavy projects, and teams whose knowledge lives across code, notes, and images.

It is also for anyone who wants AI assistance to be more legible. The project’s real appeal is not that it adds more AI. It is that it makes the AI’s context more structured, more local, and more accountable.

Best fitWhy
Large or legacy codebasesRelationships matter more than flat search
Mixed code and documentationOne graph can hold both
Onboarding and researchA map beats a list of hits
Assistant-heavy workflowsThe hook makes the map part of the habit