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.
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.
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.
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.
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.
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
- If a rule is in the instruction file, you can count on the agent following it every time.
- Longer instruction files make agents follow them better.
- In one study of 2,303 context files, security guidance appeared in about 15 percent of them.
- A change to an instruction file needs less review than a change to code.
- Pillar Security showed the Rules File Backdoor being used against real victims.
- 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
- 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.
- AGENTS.md. AGENTS.md: a simple, open format for guiding coding agents. agents.md. 2026.
- Anthropic. How Claude remembers your project. Claude Code documentation. 2026.
- Anthropic. Effective context engineering for AI agents. Anthropic Engineering blog. 2025.
- Pillar Security. New Vulnerability in GitHub Copilot and Cursor: How Hackers Can Weaponize Code Agents. Pillar Security blog. 2025.
Further reading
- 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.
- Pillar Security. New Vulnerability in GitHub Copilot and Cursor: How Hackers Can Weaponize Code Agents. Pillar Security blog. 2025.
- GitHub. GitHub now provides a warning about hidden Unicode text. GitHub Changelog. 2025.
- Anthropic. How Claude remembers your project. Claude Code documentation. 2026.
- AGENTS.md. AGENTS.md: a simple, open format for guiding coding agents. agents.md. 2026.
- Anthropic. Effective context engineering for AI agents. Anthropic Engineering blog. 2025.
Sources last verified 2026-10-13.