Sub topic 1
Why Coding Agents Need Project Context
Prerequisites
This chapter assumes you know basic Git and repository layout, and you can read Markdown. You should be comfortable running build and test commands from a terminal. You should also have used an AI coding assistant or agent at least a few times.
What a coding agent does
A coding agent is a program that uses a language model to read files, run commands and edit code in your repository. Unlike a chat assistant, it acts on the project directly. It might search the code, change several files, run the tests and fix what breaks.
To do this well, the agent needs to know things about your project. The model does not know them in advance.
What the agent cannot see
When an agent starts a session, it sees your files and your request. It does not see the conventions your team agreed on, the history behind them, or the habits of the people who work in the repository. Some of that is guessable from the code. Much of it is not.
Typical gaps include:
- Commands. Is the test command
npm test,pnpm testormake check? Does the database need to be running first? - Style rules. Does the team ban default exports? Where does business logic go?
- Hard limits. Are some files generated or off limits, such as existing database migrations?
- Definition of done. Must lint and type-check pass before a pull request?
An agent that lacks this information guesses. Some guesses are right. Others cost you time.
What goes wrong without context
Three failures come up often.
- Wrong commands. The agent runs a test command that does not exist in your project, or runs the whole suite when one file would do.
- Style drift. The agent writes valid code that does not match your conventions. A reviewer then has to ask for the same fixes in every pull request.
- Unsafe edits. The agent edits a file that should never change by hand, such as an applied migration.
Each failure is small. Together they remove much of the time an agent is supposed to save.
Why not just put it in the prompt?
You can type these details into every request. That works for one task, but it has costs:
- You repeat yourself in every session.
- Each team member writes a slightly different version.
- The instructions are not versioned, so they cannot be reviewed or kept in step with the code.
Project context belongs in the repository, where everyone and every tool can read it and where it changes with the code.
What AGENTS.md provides
AGENTS.md is a plain Markdown file at the root of a repository. It tells coding agents how to build, test and work in that codebase. Think of it as a README written for agents. A README explains the project to people. AGENTS.md gives agents the operational details: exact commands, conventions and boundaries.
Here is a short example of the kind of content it holds:
# AGENTS.md
## Build and test
- Install dependencies: `npm ci`
- Run all tests: `npm test`
- Lint and type-check before finishing: `npm run lint && npm run typecheck`
## Code style
- Use named exports; do not add default exports.With this file, the agent knows how to install, test and check its work. It also knows one rule that it could not have inferred reliably from the code.
Later chapters cover the format, what to include, how nested files and precedence work, and how to keep the file accurate. For now, the main point is that agents act better when the repository tells them how it works.
Check your understanding
Exercise
An agent keeps running npm test for your whole repository, which takes ten minutes, when you only changed one file. It also adds default exports, which your team forbids. Name two reasons these problems occur and where you would fix them.
Show answer
The agent cannot see your team's commands and conventions, so it guesses. A general default such as npm test runs everything, and default exports are common in many codebases. Fix both in the repository's AGENTS.md: add the single-file test command (for example npm test -- path/to/file.test.ts) and a style rule saying to use named exports and not add default exports. Keeping this in the repository means every session and every team member gets the same guidance.