CI verdicts and evidence-backed review for agent-written changes.

Building an Interactive Codebase Graph as the Runtime Substrate for AI Agents

A queryable codebase graph helps AI agents navigate repositories without rediscovering them.

Sponsored by Graphide

Navigating the Diff Editors
· 9 min read · Updated
Cover illustration for “Building an Interactive Codebase Graph as the Runtime Substrate for AI Agents”
Agentic Coding Workflows · November 3, 2026 · 9 min read · 1,913 words

An interactive codebase graph for AI agent steering is queryable infrastructure. It gives agents a persistent map of symbols, dependencies, and architectural boundaries so they can navigate directly to relevant code instead of rediscovering the repository each session. To serve as a runtime substrate, that map must update incrementally, expose a standard interface, and support both human oversight and machine-enforced constraints.

Why agents waste most of their token budget before writing a single line

An agent encounters a repository, greps for names, reads imports, opens files, and follows calls until it can locate the work. Each discovery creates another question about a dependency or entry point. In the next session, the loop starts again, while parallel agents do much of the same work on their own.

This is navigational waste. The repository lacks a persistent, queryable representation of its structure, so each agent must reconstruct enough of that structure to act. Larger, more tangled codebases make the reconstruction more expensive. As repositories grow more complex and agents do more work, this uses more context and tool calls before the agent reaches the task itself.

What a codebase graph must capture to be useful infrastructure, not a diagram

A useful graph represents the entities agents need to locate, including modules, files, classes, and functions. It also captures imports, call relationships, routes, tests, and domain boundaries. A picture alone cannot answer structural questions. The underlying data must let an agent move from a symbol to its callers, from an import to its dependency, or from a source file to the tests linked to it.

Those relationships need direction and provenance. A parsed call, a relationship inferred from naming conventions, and an ambiguous connection do not provide equal evidence. Treating them alike makes the codebase seem better understood than it is. Provenance tags let agents and reviewers distinguish relationships extracted directly from code from those that require further investigation, rather than mistaking a plausible connection for an established one.

Framework behavior makes that distinction especially important. JavaScript frameworks generate routes through conventions, Python hides behavior behind decorators, and Ruby relies on metaprogramming. Static symbol extraction alone can leave gaps that are easy to trust. Framework-aware parsing can expose more of this structure, but the data model must still preserve uncertainty where the relationship cannot be established directly. The graph locates relevant evidence rather than certifying that the code behaves correctly.

How do you give an AI coding agent a real-time map through three technical properties?

Incrementality is the first requirement because a structurally rich graph becomes unreliable as soon as edits outpace its updates. When a file changes, the graph must update without a full re-index. Rebuilding by hand cannot keep up when agents keep writing. Auto-sync on file change is therefore the minimum viable implementation, although the interval between the write and the update still creates a window for stale queries.

A current graph remains siloed unless agents can reach it through a shared interface. Model Context Protocol, or MCP, provides a common way to expose structural queries across agent runtimes without bespoke integration for every framework. Freshness alone does not make knowledge accessible. The codegraph init workflow gives this requirement a concrete repository-level shape through installation, initialization, and auto-sync. “Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP,” published in 2026, explores Tree-Sitter as a multi-language incremental parsing layer feeding an MCP-accessible graph.

Local-first operation keeps the graph local to the repository, letting it run without sending code through third-party inference infrastructure. A graph stored in .codegraph/ can be versioned and diffed with the source and used in CI. An external-only representation does not provide that same repository-local artifact, even if agents can query it.

How agents consume the graph: navigation patterns that replace the discovery loop

Diagram: The Blast-Radius Query: How an Agent Navigates Before Editing. Visualizes: Show the sequential navigation pattern an agent follows when the codebase graph is available, replacing the undirected discovery loop.

With that infrastructure available, an agent begins by querying for entry points rather than searching the repository indiscriminately. It inspects callers and callees, identifies likely affected files, and reads those exact source files before editing. Focused verification follows the change. The completion output then records the graph-derived assumptions that guided the work, so reviewers can see how the agent’s first steps led to the evidence they receive.

The central query is the blast-radius query. Before changing a function, the agent asks which symbols call it, which files contain those symbols, and which call paths connect them. This establishes an impact surface before the edit. How much it can be trusted depends on the graph’s coverage and provenance, but even an answer that is clearly incomplete can guide the search better than looking through unrelated files with no clear target.

CodexGraph, RepoGraph, ARISE, and the Code Graph Model report that approaches that use graphs do better than raw search on engineering tasks across a repository. The codegraph project also evaluates headless agents answering architecture questions on real open-source codebases with and without the graph. Its reported token and dollar savings depend on scale, with modest repositories producing small or noisy gains.

The completion receipt makes the navigation auditable. It records what the agent inferred from the graph, rather than presenting the patch as though its context were unquestionable. Reviewers can then challenge a dependency assumption or an impact boundary directly. This record is especially useful when the same structural model later checks whether the agent’s changes stayed within the declared architecture.

Why the diff-view paradigm breaks down when agents write the code

AI-assisted pull requests are much larger than unassisted ones, and they can arrive faster than humans can review them. Faros AI’s 2026 report draws on two years of telemetry across tens of thousands of developers and thousands of teams. It found that task throughput rose sharply, median time in review grew much longer, and a large share of pull requests were merged without review.

A diff shows which lines changed, but their effects across the system are harder to see. That distinction becomes acute when an LLM produces heterogeneous work with homogeneous confidence across forty files. The reviewer must reconstruct the connections between changes. So even when a local edit looks correct, the reviewer may need to spend a lot of time tracing the architecture to judge how it affects the rest of the repository.

Automated review can add noise when it emphasizes style and best-practice comments over correctness, security, and structural impact. More comments do not necessarily improve understanding. Graph-derived context addresses a different layer of the problem by exposing relevant symbols grouped by file, call paths between them, and a blast-radius summary before line-by-line inspection. The same structure that narrowed the agent’s search can thus orient the reviewer without pretending to replace source-level judgment.

Enforcing architectural constraints in CI so the graph becomes a gate, not a suggestion

Once the graph exposes structural consequences, declared constraints can turn those consequences into merge conditions. Architecture tests examine codebase structure and design. A violation can then block the build. This is a different mechanism from review advice, because compliance no longer depends on whether a reviewer notices the problem and persuades the author to correct it.

Agents have particular need for such boundaries because they lack human intuition about architectural intent and can touch dozens of files in a single run. Instructions alone do not enforce that intent. Files that developers provide, such as agent instruction files and structured specification files, give context, while a graph-backed constraint file states what structure is allowed in a form that can be tested. Versioning that model with the code makes architectural policy part of the repository.

This is bounded autonomy expressed through architecture. Humans set the permitted scope and approval boundaries, and agents stay under human control as they work within those limits. DORA’s 2024 research found an association between AI adoption and reduced delivery stability, while emphasizing fundamentals such as small batch sizes and robust testing. That finding does not establish missing graph enforcement as a cause. The finding does strengthen the case for clear controls as production speeds up, because generation speed alone does not show delivery quality.

The staleness problem: keeping the graph consistent as agents write into the codebase

A stale graph can be worse than no graph because it supplies a precise-looking answer about a structure that no longer exists. Static analysis also misses dynamic behavior, even when its index is up to date. These are separate risks that can compound. A recorded call from function A to function B cannot establish that the relationship survived a refactor or behaves as expected under load.

Parallel agents expose the synchronization risk directly. One agent writes a change while another queries the graph before that change has been indexed. The second agent receives the previous topology. Executable Code Knowledge, introduced in 2026, advances a broader objection by arguing that code, tests, and validators should themselves serve as the knowledge representation.

Auto-sync on file change, instead of waiting for a commit or push, narrows the stale interval to seconds. It does not make synchronization instantaneous. Nor does it solve incremental updating in the general case for very large, dynamically typed, metaprogramming-heavy codebases. Those limits need to remain legible to agents and reviewers so that apparent completeness is not mistaken for actual coverage.

The corresponding operating rule is to use the graph for navigation and the file, tests, and runtime to decide what is true. Before they act, agents still need to read the source. Queries with high stakes should also be checked through direct search, even when the graph gives a confident result. Recording the graph-derived assumption in the completion receipt gives reviewers a way to examine the belief behind the action, including whether stale or inferred structure influenced it.

What it looks like to build on a graph substrate: the developer's new role in an agent-first codebase

When the graph becomes live infrastructure, the developer’s work shifts toward architectural stewardship. The central responsibility is defining and maintaining the model that agents navigate and CI validates. That requires more than drawing repository boundaries. Engineers must decide which relationships show architectural intent, which constraints can be enforced automatically, and which choices still need human judgment.

Harness engineering gives that responsibility a concrete form. It defines which parts of the repository an agent can access, at what granularity, and when the agent must stop for approval. The graph gives developers a way to state those limits, while its provenance and synchronization limits show where humans need to keep an especially close watch. Human control then rests on explicit scope and evidence.

For teams shipping production software with agents, line-by-line reading remains necessary but is no longer sufficient as the main method of oversight. Engineers also need to navigate relationships, inspect impact, and declare boundaries that survive beyond a single session. This is an architectural competency. The durable work is designing the system agents may change, stating the constraints they must respect, and judging their output at the level where consequences spread.

Putting architectural checks in CI

Choose an architecture-test or dependency-rule tool that supports your language and the constraints you can explicitly encode. Commit its rules with the code, run the documented command in CI, and make the resulting check required where those rules should prevent a merge. Test the gate with an intentionally forbidden dependency before relying on it. Such checks enforce the rules you specify; they do not establish that every aspect of the architecture or runtime behavior is correct.

Updated November 5, 2026: obsolete CLI examples removed. Use the selected tool’s current installation and command documentation.

Sources

  1. Executable Code Knowledge: Code as a Native, Validation-Carrying Knowledge Representation for AI Coding Agents

More in Agentic Coding Workflows