AI Academy · Book
Engineering Managers · Module 03 · Chapter 003

Giving Agents the Right Context

An agent starts each conversation knowing nothing about your repository except what it can read, and the instruction file is the one page you control. Treat it as team code: short, owned, reviewed, pruned and never the only enforcement. A hidden line in a rules file can steer an assistant without any reviewer seeing it, which makes review of that file a security matter.

≈ 10 min read

After this chapter you can

  • Decide which lines belong in an instruction file by asking whether the agent could find them by reading the repository.
  • Place must-hold rules in CI, permissions or hooks, since an instruction file is context and not enforcement.
  • Name an owner, require code-owner review and scan for hidden characters in files that steer agents.
  • Audit a file by tagging each line stale, duplicate, discoverable or worth keeping, and move service rules to nested files.
  • Count repeated convention comments in review to check whether the file helps.

In a study of 2,303 context files from 1,925 repositories, researchers counted what developers write in them. About three files in four describe how to test (75.9 percent), 70.8 percent cover implementation details and 68.1 percent cover architecture. Only 14.8 percent say anything about security and 14.5 percent about performance1. Developers, in the authors’ words, use these files to make agents functional while giving them few guardrails on security or speed. That is a description of what teams write, not a measure of what works, but it points at the manager’s problem. For your team the risk is easy to picture: a file written once, by whoever cared at the time, that nobody owns and that ages as the code changes.

The question you carry: what must I write down so that agents follow how we work? This chapter answers it with what to put in the file, how to keep it short, who should own it, and why changes to it need review.

What an instruction file is, and is not

An agent begins each conversation with no memory of the last. An instruction file is Markdown that the tool loads into the agent’s context at the start. Several conventions exist. AGENTS.md is a plain Markdown format with no required fields; its site says over 60,000 open-source projects use it and that more than 20 tools read it, that nested files are allowed, and that the closest file to the edited file wins2. Claude Code reads CLAUDE.md, and as of October 2026 its documentation says it reads an AGENTS.md when the directory tree has no CLAUDE.md, or can import one3. Other tools use their own names and folders; the case below involves the rules folder of one editor and a Copilot instructions file. The names change often, so date-stamp whatever your team standardizes on.

One sentence in the Claude documentation matters more than the file names. The memory files are loaded as context, and the tool “treats them as context, not enforced configuration”; to block an action regardless of what the agent decides, the documentation points to a hook3. Whatever your tool, assume the same. An instruction file is a strong suggestion that an agent will usually follow, and a policy you need to hold every time belongs in a place the agent cannot talk its way past: a continuous-integration check, a branch protection rule, a permission setting. Think of the file as the briefing and the pipeline as the lock.

What belongs in the file

The 2,303-file study suggests a useful asymmetry. Teams document commands and structure heavily and neglect constraints. A short list of what to include follows from asking one question of every line: could the agent have found this by reading the repository? If so, leave it out. The filter, not any evidence on which lines help, is the point here; the sources offer vendor guidance for it, not a measured ranking.

A table of six sections for an instruction file, commands, conventions, boundaries, definition of done, security and performance, and pointers, each with what to put in and what to leave out.SectionPut in the fileLeave outCommandsThe exact build, test and lint commands, and how to runone testCommands the build file already makes obviousConventionsRules a newcomer would break: error handling, naming,where new code goesA tour of the directory treeBoundariesFiles and systems not to touch: migrations, generatedcode, production configurationHopes, such as 'be careful'Definition ofdoneTests that must pass, what a pull request descriptionneeds, change size limitStyle rules a formatter already enforcesSecurity andperformanceNo secrets in code, how to handle personal data, theslow paths to avoidGeneric advice anyone could copy from the internetPointersA link to the design note or example to read whenworking in an areaPasted copies of long documents
Figure 3.3.1 A filter for instruction-file content. The rows are a starting structure; keep only what the agent cannot discover by reading the code.

The security row deserves a manager’s attention, because the study found it the least often filled. It is also the row where the file is weakest as a control, so write the rule in the file for the agent’s benefit and enforce it in the pipeline for yours. The last row, pointers, is the cheap way to keep the file short: instead of pasting a design note, name it and let the agent open it when the work touches that area. Anthropic’s engineering team describes the same approach under the name just-in-time retrieval, loading references on demand rather than up front4.

Context hygiene: short, consistent, layered

Anthropic’s engineers describe context as a finite resource with diminishing marginal returns, and say model accuracy can fall as the context grows4. They also recommend instructions at the “right altitude”: specific enough to guide behavior, flexible enough to leave the model room to use judgment. That is a provider’s view and not a controlled study, but it agrees with the Claude Code documentation, which targets under 200 lines per file and says longer files consume context and reduce adherence3. The 200 is one vendor’s figure for one tool; your team’s own limit should come from your tests, and 120 is used below as an illustrative starting value.

Two hygiene problems cause most of the trouble. The first is contradiction. The same documentation warns that when two instructions conflict, the agent may pick one arbitrarily, and it advises periodic review of root files, nested files and rules for outdated or conflicting content3. Contradiction grows when a root file, a nested file and a personal file all speak about the same thing. The second is staleness: a command that was renamed, a path that moved, a convention the team dropped. Stale lines cost twice, because they use context and they send the agent to something that does not exist.

Layering is the remedy for length. Keep the root file for what holds everywhere, put service-specific rules in a nested file beside the code, and keep personal preferences out of the team’s file altogether.

Four layers of agent context from the team root file to a nested service file, a pointer to a document, and a personal file kept out of the shared file.Root fileCommands, shared conventions, boundaries; the whole team owns itNested fileOne service or package; its owning engineers maintain itPointerA link to a design note or example, opened when neededPersonal fileOne person's habits; not committed to the team file
Figure 3.3.2 Four layers by scope. Closest to the work wins in AGENTS.md as the site describes it; other tools resolve conflicts differently, so test yours.

Treat the file as code: ownership and review

An instruction file shapes every change an agent proposes, so it deserves the controls of code that shapes every build. That means a named owner, review of every change by someone listed in your code-ownership file, a freshness check on a schedule, and an entry in the same review queue as the rest. The reason is not only quality. It is also security, and a documented case shows why.

Pillar’s own account of the vendors’ responses is worth reading in full. It disclosed to Cursor on 26 February 2025, and on 6 March Cursor said the risk falls to users. It disclosed to GitHub on 12 March, and GitHub replied that users are responsible for reviewing and accepting suggestions. On 1 May 2025 GitHub shipped a warning on github.com for files containing hidden Unicode text [@pillar-rules-file-backdoor-2025; @github-changelog-hidden-unicode-2025]. The limits matter. This was a demonstration by the firm that found it. Its paper makes no claim of exploitation in the wild. The warning covers files viewed on that website, not what shows in a local editor or on another host. And the vendors, as quoted, placed the duty of review on the user, which for your team means on you.

What you can do is ordinary and inexpensive. Review changes to instruction files like code. Never paste rules from a forum or a template repository without reading the raw file. Scan the file for characters that do not render, as the Monday steps show. And do not merge a change to an instruction file in the same pull request as a change nobody wants to review closely.

Five steps in a loop, write only what the code cannot show, review the raw file by a code owner, load each conversation, measure repeated review comments, and prune monthly, with hard rules kept in pipeline checks.WriteOnly whatthe codecannot showReviewCode ownerreads theraw fileLoadAgent readsit eachconversationMeasureRepeatedreviewcommentsPruneMonthly:removestale linesHard rules live in CI, permissions or hooks
Figure 3.3.3 The life of an instruction file as a loop. The monthly interval is a starting default, not a rule.

A team-sized worked example

These counts are fictional and only demonstrate the method; a real team’s audit will produce different counts. A team of nine engineers inherits a 214-line AGENTS.md, written by one person eight months ago and edited by several since. The manager asks each line one question and tags it.

An illustrative audit of a 214-line file tagged 38 stale, 22 duplicate or conflicting, 61 discoverable and 93 worth keeping.TagLinesWhat happensStale38Points to a renamed script or moved path; deleteDuplicate orconflicting22Repeats or contradicts another doc; keep oneDiscoverable61Describes what the code shows, such as a directorytour; deleteWorth keeping93Commands, conventions, boundariesTotal21438 + 22 + 61 + 93
Figure 3.3.4 Illustrative audit of a 214-line file; the counts are invented, and the point is the four tags, not the proportions.

Of the 93 lines worth keeping, 30 apply only to the billing service. They move to a nested file beside that service’s code. The manager adds 12 new lines the old file lacked: the rule on secrets and personal data, the migration boundary and a definition of done that names the tests and a change-size limit. The root file now has 93 - 30 + 12 = 75 lines. The nested file has 30, and the total of 105 is under the team’s own illustrative limit of 120 for any one loaded path. A code owner is named for each file. The monthly freshness check takes 15 minutes: run each documented command and confirm each named path exists.

To see whether it helps, the manager tracks one number: review comments that repeat a convention the file already states, such as “use the shared error wrapper.” In the four weeks before the change, with about 100 merged pull requests, reviewers wrote 11. In the four weeks after, with a similar count, they wrote 4. That is a fall of 7, from 11 to 4. The manager reads it as a signal worth following and not as proof: two four-week windows on one team cannot separate the file’s effect from a change in who wrote the code or what the work was. A second check costs an afternoon. Give the agent five representative tasks with the old file and five with the new one, in a scratch branch, and compare what a reviewer would accept.

What this means for engineering managers

The copyable starting point is a short file with fixed sections and an owner on the first line:

# AGENTS.md (owner: <name>; reviewed: <date>)
## Commands      build / test one file / lint  (exact, tested monthly)
## Conventions   only rules a newcomer would break
## Boundaries    never edit: migrations, generated code, prod config
## Definition of done   tests pass; PR description; change under <N> lines
## Security      no secrets in code; personal data rules; slow paths
## Pointers      links to design notes by area

Check yourself

  1. If a rule is in the instruction file, you can count on the agent following it every time.
  2. Longer instruction files make agents follow them better.
  3. In one study of 2,303 context files, security guidance appeared in about 15 percent of them.
  4. A change to an instruction file needs less review than a change to code.
  5. Pillar Security showed the Rules File Backdoor being used against real victims.
  6. A nested file lets one service carry its own rules without lengthening the root file.

Reflection

What comes next

With the context in place, the next question is which work to hand over at all. The next chapter, Delegating Work to Coding Agents, covers how to size tasks, write the brief and choose work that is easy to verify.

References

  1. Worawalan Chatlatanagulchai, Hao Li, Yutaro Kashiwa, Brittany Reid and collaborators. Agent READMEs: An Empirical Study of Context Files for Agentic Coding. arXiv 2511.12884. 2025.
  2. AGENTS.md. AGENTS.md: a simple, open format for guiding coding agents. agents.md. 2026.
  3. Anthropic. How Claude remembers your project. Claude Code documentation. 2026.
  4. Anthropic. Effective context engineering for AI agents. Anthropic Engineering blog. 2025.
  5. Pillar Security. New Vulnerability in GitHub Copilot and Cursor: How Hackers Can Weaponize Code Agents. Pillar Security blog. 2025.

Further reading

Sources last verified 2026-10-13.