# Don’t give an AI coding agent the whole repository. Give it the right context.

Jaro Rais · 7 min read · 2026-12-04 · Development
Source: https://itashu.co/en/know-how/context-for-an-ai-coding-agent

You tell an AI agent to “add a login” and get working code. Except it doesn’t use your authentication library, returns errors differently from the rest of the app and puts the files somewhere else. One sentence can’t explain thousands of files and years of decisions. Here are six things an AI coding agent needs to know, and three ways to give them to it, even when you don’t know what to ask.

![Many files with lines to the three the agent really needs](https://itashu.co/img/art-30-hero-1280.webp)

## Why one sentence isn’t enough for an AI coding agent

The same request should lead to different code in different projects. In one project the right answer is Python with the FastAPI library, in another it is Go with a completely different structure. AI can’t read that from “add a login”. It has to see it in the project or hear it from you.

AI coding has opened software building to people without a programming background. But you only keep control over the result if you give the agent **good context**.

## Six things an AI coding agent needs to know

- **Existing code.** Good agents find and open files on their own. Your job is to point the way, for example “follow the pattern in the orders module”.
- **Project structure.** Where the tests live and how modules are split. A short file map helps the agent see the shape of the project without reading every line.
- **Exact library versions.** The library name isn’t enough, the agent needs the version. It finds it in the lock file, for example package-lock.json. Many “hallucinated” functions are really functions from a different version.
- **A test it has to pass.** The agent writes code, runs the test, fixes the error and tries again. It works best when it knows what done looks like.
- **Project rules.** Conventions, build commands, folders it must not touch. They belong in an instructions file in the repository, for example AGENTS.md or CLAUDE.md.
- **Your intent.** What done means, what the constraints are and what it must not do. The agent can never read this from the code.

> **What it could look like:** The agent is adding a login. It needs the authentication module, its test and the project rules. It doesn’t need billing or logs from three weeks ago.

## Why more context doesn’t mean better code

It is tempting to give the agent the whole repository. But **research** shows models make best use of information at the beginning and end of their input, and worse use of what is in the middle. Every irrelevant file competes for attention with the relevant ones.

So what matters is **relevance** to the task, not volume. Start a new session for every new task, and when a session gets long, clear out what you no longer need. The same principle applies outside coding too, as we described in [our article on why more documents don’t mean better answers](https://itashu.co/en/know-how/more-documents-do-not-mean-better-answers).

- **More context:** The whole repository, a long session, all the logs. The agent gets lost in the noise and misses the rule that matters.
- **The right context:** The module, its test, the project rules and a clear intent. The agent knows what to do and how to check it is done.

![A pile of folders, a funnel and three selected folders](https://itashu.co/img/art-30-funnel-1280.webp)

## Three steps when you don’t know what to ask an AI agent

If you are new to programming, you don’t need to know what to tell the agent. Let it **ask you**.

- **Let it interview you.** Before the first line of code, write: “Ask me questions until you understand what you need.”
- **Have it explain the project.** Ask the agent to go through the repository and explain in plain words how it is built. You will share the same map.
- **Have it show you a plan.** Before it starts, let it write down the steps and the assumptions it works from. A wrong assumption takes one sentence to fix, wrong code takes much more.

Finally, have the agent write what it learned into the **instructions file**. Next time it starts with better context. The agent does the digging, but you make the decisions.

## What this means for a company building with AI

The **quality of AI code** doesn’t depend only on the model. It depends on what the agent knows about the project. A company with up-to-date instructions, tests and clear briefs in its repository gets a better result from the same model than a company without them.

The goal isn’t more context for AI, it is the **right context**, with you in control of it. We described how the brief shapes the whole project in [our article on why projects take months](https://itashu.co/en/know-how/projects-take-months-because-the-brief-is-missing).

Sources: Liu et al., Lost in the Middle: How Language Models Use Long Contexts (2023); AGENTS.md, an open format for AI agent instructions; Anthropic, Claude Code: Best practices for agentic coding (2025).

**Ask yourself:** If a new developer joined your project today, would they find everything they need to know in the repository? An AI agent needs the same.

---

Tell us what you build with AI. We’ll help you prepare the repository, instructions and tests an agent can work with reliably. https://itashu.co/en/consultation
