Skip to main content

Machine-Readable Project Context: Why Your CLAUDE.md Matters More Than Your Model

· 8 min read
Tian Pan
Software Engineer

Most teams that adopt AI coding agents spend the first week arguing about which model to use. They benchmark Opus vs. Sonnet vs. GPT-4o on contrived examples, obsess over the leaderboard, and eventually pick something. Then they spend the next three months wondering why the agent keeps rebuilding the wrong abstractions, ignoring their test strategy, and repeatedly asking which package manager to use.

The model wasn't the problem. The context file was.

Every AI coding tool — Claude Code, Cursor, GitHub Copilot, Windsurf — reads a project-specific markdown file at the start of each session. These files go by different names: CLAUDE.md, .cursor/rules/, .github/copilot-instructions.md, AGENTS.md. But they share the same purpose: teaching the agent what it cannot infer from reading the code alone. The quality of this file now predicts output quality more reliably than the model behind it. Yet most teams write them once, badly, and never touch them again.

Why Every Tool Converged on the Same Pattern

The convergence wasn't planned. It emerged from the same practical constraint: AI coding agents are stateless. They have no memory between sessions. Every time you start a new conversation, the model begins from scratch — it has never seen your codebase before, doesn't know that you use Yarn not npm, and has no idea that the generated/ directory is auto-generated and should never be edited.

The context file is the workaround. Put the file in the repo root, and the tool reads it automatically before responding to anything. The agent walks in knowing your rules instead of discovering them by making mistakes.

Anthropic shipped CLAUDE.md as part of Claude Code. Cursor shipped .cursorrules, then deprecated it in favor of .cursor/rules/ — a directory of .mdc files with YAML frontmatter that scope rules to specific file patterns. GitHub Copilot uses .github/copilot-instructions.md. OpenAI released AGENTS.md in August 2025 explicitly as a cross-tool standard. By December 2025, the Linux Foundation's new Agentic AI Foundation had accepted AGENTS.md as an open standard alongside MCP, with Anthropic, OpenAI, Google, Microsoft, and AWS as co-founders.

AGENTS.md has since been adopted by over 60,000 open-source projects. Teams running multiple tools can symlink AGENTS.md to tool-specific files to avoid maintaining separate versions that drift apart.

The pattern is now infrastructure, not preference. The question isn't whether to write one — it's whether yours is any good.

What the Research Actually Says About These Files

A study from ETH Zurich produced a counterintuitive finding: context files generated by LLMs hurt agent performance. Specifically, auto-generated files reduced task success rates by 0.5–2% while increasing inference costs by 20–23%. The reason: language models generate context summaries by reading the codebase and writing up what they found. But agentic tools already do this during task execution. Auto-generated files duplicate what the agent would discover anyway, adding token overhead without adding signal.

Human-written files performed better — about 4% improvement on standard benchmarks — but still carried roughly the same 19–20% token overhead. The implication is clear: every token in your context file costs you, and it only pays off if the content is genuinely non-inferable from the code.

This is the key constraint for writing effective project context files. The question to ask for every line: "Would a competent engineer figure this out by reading the code?" If yes, delete it. If no, it belongs.

The Three Categories That Belong in a Context File

Non-inferable operational details. Build commands aren't obvious when you have a non-standard toolchain. If you use Pixi instead of pip, or Turborepo with a custom task graph, or a Makefile wrapper around a multi-step test suite — document the exact commands with full flags. Agents reference these repeatedly; putting them early in the file reduces the chance they get ignored when context grows long.

Intentional architectural decisions that look wrong. Every codebase has patterns that look like mistakes until you understand why they exist. A monolithic transaction handler that breaks every SOLID principle. A data denormalization that seems redundant until you understand the read path. A file that's intentionally excluded from the type-checker. Without an explanation, the agent will "fix" these. With one, it understands the intent and doesn't touch them.

Explicit boundaries. What should the agent never modify? Auto-generated files, lock files, vendor directories, migration files that have already run. Make these explicit. The three-tier model works well: ALWAYS safe to modify, ASK FIRST before touching, NEVER modify. Agents respect explicit constraints far better than they respect implicit conventions they have to infer.

What doesn't belong: codebase overviews, architecture summaries, and anything that reads like documentation. Agents discover this through code exploration — adding it to the context file wastes tokens and often becomes stale within weeks as the code evolves.

Format-Specific Considerations

CLAUDE.md is read at the session start. It supports nested files: you can place CLAUDE.md files inside subdirectories to scope instructions to specific parts of a monorepo. Keep the root file short — under 300 lines is a reasonable target, under 100 is better. If you have detailed instructions for specific workflows, reference them as separate files rather than embedding everything inline.

Cursor rules in .cursor/rules/ use YAML frontmatter to control when rules apply. You can scope a rule to only activate when editing TypeScript files in src/components/, which means the agent sees relevant instructions without loading everything for every task. This is more surgical than a single root file, but it requires more maintenance discipline to keep rules from accumulating and contradicting each other.

AGENTS.md is designed to be tool-agnostic. OpenAI's specification prioritizes executable commands, constraints, and non-standard tooling. It's explicit that codebase overviews belong in the README, not in AGENTS.md.

Across all formats, one failure mode appears consistently: the "lost in the middle" problem. Agents in long sessions progressively pay less attention to context loaded at the start. Critical constraints — the ones where violation causes real damage — should appear at the top of the file, not buried in a section on code style.

Anti-Patterns That Actively Hurt Performance

The kitchen sink. Teams add rules over time without removing old ones. A file that starts at 50 lines grows to 500. Instructions accumulate, some contradict each other, and the agent starts ignoring them because there are too many to satisfy simultaneously. Research on instruction following suggests frontier models start degrading compliance around 150–200 instructions — and Claude Code's own system prompt already consumes ~50 of those slots. The math leaves less room than most teams assume.

Style guidelines. The context file is not a replacement for a linter. Telling the agent "always use single quotes" or "prefer const over let" is slower and less reliable than running Prettier and ESLint on every file. These rules add noise and occupy space that would better serve operational context.

Stale structural documentation. "The main API lives in src/api/v2/" is true today and wrong in six months. Repository structure references become misleading as codebases evolve, and agents following outdated maps make confident mistakes. If you document structure, point at patterns rather than paths.

Auto-generated content. The research on this is unambiguous. Don't generate your context file from the codebase. The tools already read the codebase. You're paying for tokens twice and getting no benefit.

Maintenance Discipline

The failure mode for well-intentioned context files is entropy. They're written carefully at project start, then nobody touches them as the codebase changes. Six months later, the file references packages that were replaced, directories that were reorganized, and a testing strategy that was abandoned.

Treat context files like code: they belong in version control, they need review when changed, and they need owners. The practical discipline that works: when a task reveals that the agent didn't know something it should have known, that's a prompt to update the file. When a build process changes, the file changes with it. When an architectural decision gets reversed, the explanation in the file gets updated.

The other direction matters too: when you add content to the file, ask whether something already there can be removed. Most context files should shrink over time as teams understand what actually adds value versus what they added defensively and never needed.

The Return on a Well-Maintained File

The 30-minute investment in an accurate, concise context file pays dividends across every session. Teams that maintain them report that agents stop making the same category of mistake — the wrong package manager, the wrong test command, the "fixed" abstraction that was intentional. The agent's first response is better calibrated, which means fewer correction loops, which means tasks complete faster.

The choice of model still matters at the margins. But the ceiling on what any model can do in your codebase is set by what it knows about your codebase. A mediocre context file with a great model produces worse outcomes than a great context file with a good model.

The tools all converged on this pattern because it works. The execution gap is in treating it as a configuration artifact rather than a first-class engineering asset.

References:Let's stay in touch and Follow me for more thoughts and updates