# How to Give AI Coding Agents Better Code Context

Source: https://kivgraph.dev/blog/give-ai-agents-better-code-context/
Kivgraph blog, licensed Apache-2.0 (https://spdx.org/licenses/Apache-2.0.html).

---

Give an AI coding agent the smallest context that proves what it needs to change: the intended symbol, its references, relevant dependencies and the source behind those relationships. More files do not automatically produce better code.

## Why more context can be worse

An agent can spend its context window reading files that are adjacent in the directory tree but unrelated to the change. Repeated searches also make it harder to preserve the distinction between a declaration and an occurrence with the same name.

The goal is not to hide information. It is to order the investigation so the agent reads high-value evidence first. The [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) standardizes language-aware features such as go-to-definition and find-references; code intelligence extends that kind of evidence across the workspace.

## A better exploration sequence

Use this sequence for a change that starts with an unfamiliar symbol:

1. Find the declaration from the user intent.
2. Confirm its qualified identity and source location.
3. Find direct callers and references.
4. Trace dependencies to a stated depth.
5. Read the returned implementations and tests.
6. Edit only after the affected surface is clear.

Kivgraph supports the sequence with [find_by_intent](/docs/tools/find-by-intent/), [get_source](/docs/tools/get-source/), [find_references](/docs/tools/find-references/) and [trace_dependencies](/docs/tools/trace-dependencies/).

## Keep uncertainty visible

Context is only useful when the agent can tell how it was established. Exact relationships, candidates and unresolved references should not be collapsed into one confident-looking list.

That is why Kivgraph keeps provenance and confidence with graph facts. A result that needs manual inspection is still useful, as long as the agent knows that it needs inspection.

## Measure the workflow

Compare the number of exploratory calls, the amount of source read and the accuracy of the resulting change. Kivgraph publishes the methodology and raw results in its [code intelligence benchmark](/comparison/).

Better context is not the largest context. It is context that answers the next engineering question with enough evidence to act.
