# Gortex: Code Knowledge Graphs for More Efficient AI Agents

A coding agent often spends much of its context budget finding code rather than changing it. A question about one function can trigger a sequence of searches, file reads, and reference checks. Each response brings more text into the conversation, including code that may never matter to the change.

[Gortex](https://github.com/zzet/gortex) approaches that problem by indexing relationships ahead of time. Functions, callers, imports, and service interfaces become parts of a local graph that an agent can query through MCP. **The goal is to retrieve the relationships needed for a decision without repeatedly reading whole files.**

The project advertises large token reductions, including an example near 94%. Those figures need context. **A smaller graph response is useful evidence about retrieval efficiency, not a guarantee of an equally large reduction in the total bill.** The agent still has to choose the right tools, inspect relevant source, make the change, and test it.

<iframe width="100%" class="aspect-video h-auto" src="https://www.youtube.com/embed/6qQN_xW_0rc" title="Gortex code graphs and token usage" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

## Why file search becomes expensive

Text search answers where a string occurs. It does not automatically answer which occurrence refers to the function being changed, which callers depend on its return type, or whether a frontend client still matches a backend route.

A capable agent can reconstruct those relationships by reading code. The cost is repeated discovery. It may read a module to find the definition, read neighboring modules to follow calls, and open tests to infer expected behavior. A later session can repeat much of the same work.

![Token comparison between a file-reading baseline and a compact graph response](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/806e68c5-35af-46bc-bd2d-7c975a671600/orig =1920x1080)

The comparison illustrates a genuine opportunity: structural information can be much smaller than the source files needed to infer it. However, the baseline is part of the claim. A careful search with short context windows may cost less than a workflow that reads every matching file in full.

This is why token efficiency should be evaluated against the agent's actual behavior. The relevant question is whether the graph removes useful work from a real task, rather than whether it beats an unnecessarily verbose theoretical search.

## What a code graph represents

A graph separates code entities from relationships. A function is a node. A call from another function is an edge. Imports, implementations, routes, and references can supply other edge types, depending on the analyzer and language.

That structure supports questions that would otherwise require several reads. Starting from a payment function, the agent can ask for its callers, follow the call chain, and look for tests that reach the affected code.

![Coding agent requesting call-chain and change-impact information from Gortex](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/61fc617d-d128-4113-93f5-b8503128e900/orig =1920x1080)

A graph response is an index into the code, not a replacement for understanding it. A caller may exist syntactically but never execute under the relevant configuration. A dynamically constructed call may be absent from the graph. Generated code can introduce another boundary between what the analyzer sees and what runs.

The practical value is narrowing the investigation. Instead of assuming that every related file must be read, the agent begins with a map of likely dependencies and opens the pieces needed to confirm the change.

## Parsing and resolving are different capabilities

Gortex uses syntax analysis to identify entities in source code and additional resolution techniques to connect them. These are related stages, but their coverage is not identical.

A parser can recognize a function declaration without proving which overloaded implementation a call selects. Resolution may need type information, package boundaries, language-server support, or language-specific rules. A large grammar count therefore does not mean equally deep semantic analysis for every language.

![Gortex language support and parsing description with Tree-sitter and deeper resolution highlighted](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/325bb395-3db0-47d7-0ae7-c7819c4f8700/orig =1920x1080)

This distinction is particularly important in a mixed repository. TypeScript, generated clients, shell scripts, and configuration can all participate in one deployment while exposing different levels of analyzable structure.

The useful test is concrete: does the graph correctly resolve the functions, interfaces, and routes that matter in this codebase? A supported-language badge is a starting point for that test, not its conclusion.

A graph can also retain evidence about a relationship instead of presenting every edge with the same certainty. When a result is inferred from naming or route patterns, the agent should inspect the underlying source before treating it as a confirmed contract.

## MCP makes the graph available to the agent

An index only helps an agent if the agent can query it. Gortex exposes tools through MCP, allowing a coding assistant to request structural context during its normal workflow. The graph can also be explored through other interfaces, including a command line and a visual view.

![Agent tool results identifying functions and their related code locations](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/45c1159f-8ff1-45b9-ac1f-da76b0905400/orig =1920x1080)

Tool availability and tool usage are different observations. Registering an MCP server does not force an assistant to use it. An agent may still choose a familiar search tool, or may call the graph once and then read more files than necessary.

A useful prompt describes the intended investigation: identify the callers, explain the likely change impact, and locate tests, using structural tools where they provide evidence. That gives the tool a purpose without treating its output as unquestionable.

There is also a context cost to tool definitions and responses. An integration exposing many capabilities can add overhead of its own. The net gain depends on selecting useful operations and keeping their responses focused enough to support the next decision.

## Change impact is a set of candidates

Suppose a payment function gains a required argument. Direct callers are obvious candidates for edits. Tests covering those callers may need new inputs. A wrapper, adapter, or API handler can carry the effect into another layer.

Gortex can use the graph to identify that candidate set. This is often described as the blast radius of a change. The phrase is useful if it remains tied to evidence rather than a guarantee that every listed component will fail.

![Change-impact visualization connecting a function to affected symbols and tests](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/151e3070-64d5-48dc-3a61-9c160f3cc600/orig =1920x1080)

A test's relationship to a function does not show whether it will fail. It shows why the test is relevant. Running it still supplies a different kind of information: how the changed program behaves.

The same applies to a clean impact report. Missing graph edges, dynamic dispatch, and configuration-dependent behavior can leave relevant paths outside the result. Static structure helps choose what to inspect; runtime and test evidence decide whether the change works.

This division of labor is valuable for review. A patch can include both an explanation of why particular tests were selected and the actual results of running them. That is stronger than presenting a graph image as proof of compatibility.

## Multiple repositories share one investigation

A frontend and backend can live in separate repositories while depending on the same API contract. Searching one checkout in isolation leaves the client half of the change out of view.

Gortex's multi-repository support lets the agent investigate relationships across tracked projects. A payment endpoint on the server can be considered alongside the frontend calls that construct its request.

![Two-repository investigation showing frontend calls and backend payment endpoints](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/ca04bd91-f8fd-4262-1c29-94c8cd24fd00/orig =1920x1080)

The [multi-repository documentation](https://github.com/zzet/gortex/blob/main/docs/multi-repo.md) describes the graph's cross-project model. In practice, the important question is whether a discovered match has enough evidence: method, path, request shape, and the client code that sends it.

Matching names alone is weak evidence. Two services may both expose `/checkout` without sharing a contract. Environment-specific base URLs can make two otherwise identical paths refer to different systems. The agent needs to keep those distinctions visible.

This is where graph retrieval can save more than tokens. It reduces the chance that a change is reviewed entirely inside the repository where it began. The resulting evidence still needs ordinary integration tests and agreement about which version of the contract is deployed.

## A daemon keeps the index current

A precomputed graph becomes less useful if it describes yesterday's code. Gortex uses a persistent local process to watch files and update the index as the workspace changes.

![Gortex daemon and file-update diagram showing incremental graph maintenance](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/ae9c0cde-b337-436f-8d6f-5a7e2d2bf500/orig =1920x1080)

Incremental maintenance moves work out of the agent's immediate conversation, but it does not make indexing free. Parsing and resolution consume CPU, memory, and disk space. A large codebase can require a substantial index even when an individual query returns very little text.

Freshness should therefore be observable. After changing a function or switching a branch, a useful check is whether the graph reports the current definition and relationships. A fast answer from an outdated index can be worse than a slower direct source read.

Worktrees add another dimension. Separate checkouts may contain different implementations under similar paths. An index needs the correct workspace identity so that one agent does not retrieve relationships from another branch by accident.

## Local indexing does not make every interaction local

Gortex can build and query its index on the developer's computer. That avoids uploading the whole repository to a separate indexing service merely to construct the graph.

![Local Gortex pipeline with retrieved context passing onward to the coding model provider](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/6dab1024-1fd7-408b-f5bc-bcead2aa3200/orig =1920x1080)

The coding agent may still send the retrieved code and relationships to a cloud model. These are separate data boundaries: where indexing happens and where inference happens. A local index can reduce the amount retrieved without changing the destination of the agent's model requests.

This matters when comparing privacy claims. The right question is not simply whether a component calls itself local. It is which process receives source code, which information goes into a prompt, and which optional integrations have been enabled.

The graph also becomes a sensitive local artifact because it can reveal repository structure and names. Its storage and lifecycle deserve the same attention as other development indexes, particularly on a shared workstation.

## What the token dashboard measures

The [published Gortex example](https://gortex.dev/) compares a file-reading workflow with a much smaller structural response. That is a useful illustration of how focused retrieval can cut context. It should remain labeled as the project's comparison.

![Token dashboard contrasting measured graph responses with an assumed file-reading baseline](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/9e9ac4cb-3226-45c0-7174-aa38f9effe00/orig =1920x1080)

The graph can measure what it returned. It cannot directly observe every token a different agent would have consumed in the counterfactual run. A savings estimate therefore depends on assumptions about which files would otherwise be read and how much of them would be included.

An end-to-end evaluation needs a matched workload. Give the same representative tasks to the same model with and without the integration, track provider usage, and judge correctness independently. Include indexing overhead and time to completion, not just retrieval response size.

| Measurement | What it helps answer |
|---|---|
| Graph response tokens | How compact was this lookup? |
| Total model usage | Did the full task become cheaper? |
| Tool-call history | Did the agent actually use structural retrieval? |
| Passing tests and review | Did efficiency preserve a correct change? |
| Indexing resources | What did the local infrastructure cost? |

A tiny repository may not justify persistent indexing. A large service collection can offer much more repeated discovery work to eliminate. The advantage depends on the workload, not the largest percentage in a dashboard.

## Final thoughts

**Gortex changes code discovery from repeated reconstruction to reusable structural retrieval.** Call chains, likely change impact, and cross-repository contracts can give an agent a narrower and more useful starting point.

The graph remains a map with limits. Its freshness, language resolution, and actual use by the agent determine how much value it provides. Token estimates help identify opportunities; provider usage, tests, and reviewed changes establish whether those opportunities became better everyday engineering.
