← Back to Articles
AI 9 min read

Rules and Maps: What a Coding Agent Needs to Know About Your Repo

A coding agent needs two kinds of repo context: rules (why things are the way they are, and what it must never do) and maps (what exists and what depends on what). Here is how I run both on this site, what the research says actually helps, and how to choose.

Every coding agent starts a session knowing nothing about your repo. It reads files, guesses at conventions, and fills the gaps with what most repos do. For a lot of work that is fine. For the rest, the gap between "what most repos do" and "what this repo does on purpose" is where the wrong PRs come from.

The fix everyone reaches for is a context file. Give the agent a page about the repo and it will do better. The research says it is not that simple, and running two different kinds of context on this site taught me the same thing.

Two kinds of context

There are two different questions an agent needs answered, and they need different tools.

Rules answer why and never. Why is there no framework here? Which files are written by another process and must never be touched? What is an automatic reject in review? None of this is in the code. You can read every file and still not know that a hand edit to a generated block gets overwritten on the next build, or that the site must never cost money.

Maps answer what and where. Which script writes this file? What calls this function? If I change the publisher, what else moves? All of this is in the code, just spread across too many files to hold at once.

Rules have to be written by someone who knows the intent. Maps can be generated. Most repo-context tools are clearly one or the other, and most confusion comes from expecting one to do the other's job.

Both of them only inform. Neither can stop anything. An agent can read "never hand-edit a generated block," agree, and do it anyway. That is what checks are for: CI, hooks and permissions decide what actually gets merged. Rules and maps make a mistake less likely. A check makes it impossible to ship.

Two panels on a plum background. Left, Rules: two highlighted cards that are always loaded, the NEVER/ASK/ALWAYS rules and a cheatsheet, and six smaller on-demand cards (known issues, architecture, testing, git workflow, environments, design). Right, Maps: publish_article.py with arrows to the article page and js/data.js it writes and the two scripts it runs, build_pages.py (Home cards) and build_seo_files.py (sitemap and RSS). A line below reads: the rules say why the site uses scripts; the map says which script writes which file.
Rules are written by people who know the intent. Maps are generated from the code.

The formats agents read today

The ecosystem has settled on a few shared formats in the last year:

  • AGENTS.md is a plain markdown file at the repo root, "a README for agents." It moved under the Linux Foundation's Agentic AI Foundation in December 2025, alongside MCP, and Codex, Cursor, Copilot, Gemini CLI and others read it.
  • CLAUDE.md is Claude Code's version. One detail matters if you use both: Claude Code reads AGENTS.md only when there is no CLAUDE.md, so a repo with both needs one to point at the other. Claude Code also has .claude/rules/ files that load only when the agent touches matching paths.
  • Agent Skills are folders with a SKILL.md. The agent sees each skill's name and one-line description at the start and loads the full file only when a task matches. That is the key idea for keeping context cheap: describe everything, load little.
  • MCP servers give the agent live tools instead of stored text: Serena asks a language server for symbols and references, Context7 fetches current library docs, DeepWiki answers questions about a public repo.
  • Generated maps: Aider's repo map packs the most important signatures into about a thousand tokens; Graphify builds a full knowledge graph of code and docs.

What the research says

Four 2026 studies are worth knowing before you write a long context file.

Gloaguen and colleagues tested context files across several coding agents and found they did not generally improve task success, while raising inference cost by over 20%. Agents did follow the instructions. The parts that did not help were the repository overviews, the "this repo is a..." paragraphs most of us start with. Their advice: use these files for what is non-standard about your repo, and measure before you assume.

Guardrails Beat Guidance collected over 25,000 rules from real CLAUDE.md and Cursor rule files, then tested 18 of them one at a time by taking each out of the set. The three rules whose removal clearly hurt were all negative constraints ("do not refactor unrelated code"). The four whose removal helped were all positive directives, like "follow code style." It is a small test with one agent and one benchmark, and the authors say so, but the pattern is hard to ignore.

Markdown Is Not a Firewall ran one rules file through four coding agents and got four different boundaries. Its summary is the best line I have read on the topic: "A file tells an agent what you want. A gate decides what it gets."

The fourth is more positive: a smaller study of 10 repos found an AGENTS.md was associated with about 29% lower runtime. That does not cancel out the first study's 20% higher cost. One measured time per task and the other tokens and success, on different repos and agents, so a file can speed an agent up and still not make it right more often. Where the studies do agree: short, specific, negative rules help, long overviews add little, and anything that truly must not happen belongs in a check, not in prose.

How I run both on this site

Working with Claude Code: I designed a repo-knowledge skill and decided the rules it follows, and Claude Code wrote the files and ran it with me. It builds a set of rules files, one per topic: security, known issues, git workflow, architecture decisions, testing, environments, design. Every claim has to point at a real file, and anything it cannot find is marked [MISSING INFO] for me to fill in instead of guessed. It also refuses to restate anything CI already enforces.

Next to it, Graphify keeps the map: about 970 nodes and 1,770 edges for this repo, 94% read straight from the code. The first full build, which also reads the docs, cost about 450k tokens; refreshing the code part afterwards is free and runs locally. I installed it as a skill only, with no hooks, so the agent asks the graph when it needs structure and otherwise leaves it alone.

The split works. The rules skills say why the site uses scripts for all generated output; the graph says which script writes which file. When the knowledge files need refreshing after a change, graphify explain on the changed file shows which areas it touches, which catches skills the file-to-skill table misses.

The checks sit underneath both. Every pull request runs a self-test of the publishing scripts, a check that pre-built pages match their source, a check that every local link points at a real file, and a browser test that loads and clicks through each page. Several "never" rules are checks now: a page may only load resources from a short list of free hosts, so the site cannot start costing money without failing CI first. Checks need upkeep too: while publishing this article, the link check rejected three correct links because it treated the #section part of a URL as part of the file name. A gate with a blind spot fails just as quietly as a stale rule.

Writing this article made me check whether the setup did what I thought, and it did not, in three ways:

  • The "always loaded" tier was a label. My index marked five files as loaded every session. Nothing loaded them: they had no front matter, so Claude Code saw a name and a heading, and CLAUDE.md never imported them. The fix was two short files (the NEVER/ASK/ALWAYS rules and a one-page cheatsheet, about 500 tokens together) imported in CLAUDE.md, with everything else loaded on demand by its description.
  • The rules went stale. The day after the site moved to its own domain, five files still said the domain was "pending," even though a refresh had run that same day. A refresh only fixes what it is pointed at. A map regenerates; rules only change when someone edits them.
  • Only Claude could read any of it. There was no AGENTS.md, so any other agent started from zero. Now there is a short one that points to the same sources.

None of these showed up as a failure. The agent did fine most days. It just was not getting the context I had paid to write.

One gap is still open, and it goes against my own advice: CLAUDE.md, which loads in full every session, is over 300 lines. Six topics already live in .claude/rules/ files that load only when the agent touches matching paths. The next step is moving more of CLAUDE.md the same way, so the part that is always loaded holds only what every task needs.

When to choose which

Start with rules alone when the repo is small or you know it well, and the risk is in conventions and boundaries more than in structure. Keep the always-loaded part tiny and mostly "never." Put the rest in on-demand files with good descriptions.

Add a map when the agent spends its time searching: a large or unfamiliar codebase, a monorepo, a change whose blast radius you cannot see. Pick a generated graph if you want to ask questions across code and docs, or a live tool like Serena if staleness worries you more than setup does.

Run both when the repo is agent-operated day to day. Let the rules carry intent and the map carry structure, and refresh both in the same step so neither drifts.

Skip both for a throwaway script or a repo that follows its framework's defaults. The research suggests a generic context file there mostly costs you tokens.

Short rules, fresh maps, real checks

Context for a coding agent is not one document. It is a small set of rules a person wrote on purpose, a map generated from the code, and checks that stop what must never happen. Keep the rules short, keep the map fresh, and check every so often that the agent is actually reading what you wrote.

Further reading