Skip to main content
50% off all plans, limited time. Starting at $2.48/mo
12 min left
AI & Machine Learning

How AI Coding Agents Pre-Load Your Context and When It Backfires

D By Dan 12 min read
Split panel showing context files streaming into an AI agent on the left and a developer's blank prompt cursor waiting on the right, illustrating AI agent context pre-loading before the first message

You open your editor and start a session. Before you type anything, before the cursor even settles in the prompt field, the agent has already done a substantial amount of reading. It has taken in its system prompt, the definitions of every tool it can call, its behavioral instructions, your project's CLAUDE.md (or .cursorrules, or AGENTS.md), any path-scoped rules that apply, and whatever sits in its memory file. By the time you say your first word, the agent already has a model of you, your project, and how it's supposed to behave.

The naive mental model is you type, the agent responds. The real sequence is the agent reads your context, you type, the agent responds. That silent first step, the agent reading you before you speak, is where a surprising amount of your outcome is decided. And the evidence about whether the context you feed it actually helps is more uncomfortable than most of us assume.

The Short Version

  • AI coding agents load pre-written context before your first message: system prompts, tool definitions, and tool-specific instruction files such as CLAUDE.md, Cursor rules, GitHub Copilot instructions, or AGENTS.md where supported or imported. You don't initiate the conversation; the agent's reading does.
  • That pre-load eats a significant share of the usable context window before you've typed a single character, so your effective working budget is smaller than the model's advertised window suggests.
  • The empirical finding is the counterintuitive part: developer-written context files help a little (about +4% task success) at real cost (about +19% inference cost), while LLM-generated or copy-pasted context files can actually make results slightly worse.
  • Self-hosting your model changes what you can see, not what you have to do. The pre-session architecture is the same everywhere; local tools just let you inspect and audit it. The discipline of writing context you actually understand doesn't go away.

The Naive Model Is Wrong: The Agent Reads First

Picture the exact moment a Claude Code session starts. The system prompt goes in. The tool definitions go in. Then, before you've said anything, your CLAUDE.md gets delivered, and the mechanical detail here matters. Anthropic's own documentation is explicit that CLAUDE.md content is “delivered as a user message after the system prompt,” loaded “at the start of every conversation.” So the very first user turn in the transcript isn't you. It's your file, speaking on your behalf, setting the terms before you arrive.

What actually loads at that opening moment is a stack: the system prompt, the tool definitions, the behavioral instructions, your project and user context files, any path-scoped rules that match the files in play, and a memory file the agent maintains itself. In Claude Code, the context files resolve through a four-level hierarchy (managed policy, then user (~/.claude/CLAUDE.md), then project (./CLAUDE.md), then local (./CLAUDE.local.md)), concatenated in that order. Auto memory adds its own slice: the first 200 lines (or 25KB) of a MEMORY.md the agent writes and reads on its own, loaded every session.

None of this is free. The infrastructure overhead (system prompt, tool definitions, behavioral instructions) consumes a significant share of the effective context window before your first message lands. That's the tax you pay for the agent knowing how to be an agent, and it's invisible unless you go looking for it.

There's a name forming around the discipline of managing all of this. Anthropic's applied AI team calls it context engineering: “the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference.” It's a useful term because it reframes the file you write from a note-to-the-robot into an architectural decision about what occupies a scarce, expensive resource.

Timeline of what an AI coding agent loads before the developer types: system prompt, tool definitions, behavioral instructions, context files including CLAUDE.md, path-scoped rules, and agent memory, all loaded before the first user message

Four Agents, Four Ways of Reading You First

The agents don't all read you the same way. They split along two axes worth naming: what gets loaded at session start (a curated hierarchy of files, versus always-on rules, versus a whole-repo scan), and how much of that you can inspect, meaning whether the mechanism is a deterministic, auditable artifact or a semantic index you have to take on faith. Those two axes are where Claude Code, Cursor, GitHub Copilot, and Aider genuinely diverge.

ToolWhat loads at session startMechanismAuditability
Claude CodeCLAUDE.md hierarchy + .claude/rules/ + auto memory; AGENTS.md only if imported or symlinkedFile-based hierarchy; path-scoped rules can lazy-load; compaction and re-read behavior varyHigh for your files and memory; system prompt remains proprietary
CursorProject, Team, and User Rules; AGENTS.md support; codebase index for semantic contextReadable rule files plus semantic codebase indexingMixed: rules are readable, but index retrieval is less transparent
GitHub CopilotRepository-wide copilot-instructions.md plus path-specific .instructions.md where supportedCustom instruction files applied across Copilot workflowsModerate: files are readable, but scoping depends on product surface
AiderA compact repo-map derived from the git repo, plus files manually added/readSymbol/graph-based repo map optimized for a token budgetHigh: the repo map can be inspected, but it is still a selected map, not the whole repo verbatim

Cursor's split is the most instructive. Its rules live in readable files you control, but it also builds a semantic index of your entire codebase, vector embeddings that power @codebase search and that you cannot really inspect. Aider sits at the other end: it reads your whole git repository and builds a repo-map, deterministically, with no embeddings anywhere. You can audit exactly what it fed the model. Same architectural inversion, very different visibility into it. For the deeper tool-by-tool comparison, we've covered the agentic CLI landscape in our agentic coding CLI showdown and gone head-to-head in OpenCode vs Claude Code elsewhere.

Underneath the tool-specific formats, a cross-tool standard is consolidating. AGENTS.md emerged across the agent-tooling ecosystem (OpenAI Codex, Amp, Jules from Google, Cursor, and Factory) and is now stewarded by the Agentic AI Foundation under the Linux Foundation, adopted across 60,000-plus repositories. That's the pre-session context file being promoted from a per-tool convenience into a first-class, portable artifact: the industry agreeing that “what the agent reads before you speak” deserves a standard of its own.

Comparison of four AI coding agents and how they load context before the first message: Claude Code file hierarchy, Cursor rule files and semantic index, GitHub Copilot instruction files, Aider repo-map

What the Evidence Says About Whether Any of This Helps

Here's where the comfortable story breaks. A team at ETH Zurich (Gloaguen, Mündler, Müller, Raychev, and Vechev) ran a controlled evaluation, “Evaluating AGENTS.md,” on whether these repository-level context files actually improve coding-agent performance. Across the agents and models they studied, the result was not “context files work” or “context files fail.” The current abstract says context files do not generally improve task success and increase inference cost by over 20% on average. In the paper's detailed results, developer-provided files were the exception: they improved performance by about 4% on average, but increased cost by up to 19%. LLM-generated files moved the wrong direction, reducing performance by about 3% on average while raising cost by more than 20%. A third finding sharpens it: agents call a tool 1.6–2.5× more often when that tool is named in a context file, which helps or hurts entirely depending on whether those extra calls were warranted.

Sit with the LLM-generated line for a second, because it's the load-bearing one. A file you didn't write, whether generated by a model or downloaded from a community pack of “best CLAUDE.md configs” and dropped into your repo, reads to the agent like instructions from someone who doesn't actually know your codebase. In the study's models, that was a net negative: you paid more tokens for slightly worse results. The Augment Code write-up on this captures it well when it calls the accumulated result “your agent's context is a junk drawer.” Every plausible-looking instruction you shovel in has a cost, and the ones you didn't author for a codebase they don't understand tend to cost more than they return.

I read this not as “context files are bad” and not as “context files are good.” Those are exactly the all-or-nothing framings that fall apart on contact with the data. The narrower reading is this: context is infrastructure you architect deliberately, and a file you didn't write, for a codebase it doesn't understand, is a cost rather than a gift. The scope caveat matters too. This is what the paper found for the models and agents it tested, not a universal law about every LLM. But it points hard in one direction, and it's corroborated from the vendor side: Anthropic's own applied AI team has noted the shift toward loading context “just in time” via tools at runtime rather than pre-loading everything up front, and describes a hybrid approach that retrieves some data up front and explores the rest at runtime. When the company that ships CLAUDE.md is leaning toward pre-loading less, the copy-paste-a-giant-context-file instinct deserves a second look.

Section takeaway: authorship is the signal that predicts whether context pays off. The token cost lands the same either way; what changes the return is whether the instructions came from someone who actually knows the codebase.

Research results on context file quality versus inference cost: developer-written files show +4% task success at +19% cost, LLM-generated files show -3% task success at +20% cost, from ETH Zurich evaluation of AGENTS.md

The Context That Fades: Why Session Start Isn't the Whole Story

Pre-loading sets the constraint. It doesn't hold the constraint. What developers keep running into is the second half of the story: the context you carefully arranged at session start erodes as the session runs, and it does so quietly.

A useful way to picture this comes from the Mem0 team's framing that a context window is RAM, not storage, ephemeral and bounded, not a persistent place your instructions live. Load something in at the start and it's present; keep going long enough without exercising it and it fades, the way a variable you stop referencing eventually gets overwritten. That's the mechanism behind a pattern researchers describe as instruction decay. A 2026 study by Gamage and colleagues found that omission constraints are especially fragile: in one tested setting, compliance fell from 73% at turn 5 to roughly 33% by turn 16. That's a lab finding, not a universal constant, but it matches what a lot of people feel happening in long sessions.

The session boundary is where it gets sharper. Developers in a Hacker News discussion report that spawned subagents can suffer from context handoff problems, so work handed off mid-task may arrive with less of the parent session's context than you assumed. And idle time has a cost of its own: in a thread where Anthropic's Boris Cherny weighed in, the discussion covers how an idle session can trigger a large cache-miss rebuild, hundreds of thousands of tokens, without any warning to you. The through-line the community keeps reporting is silence: compaction runs, earlier reasoning gets trimmed, quality slips, and nothing on screen tells you it happened. You just notice the output got worse.

Does Self-Hosting Give You More Control?

Run the whole thing yourself (Ollama plus Open WebUI, or an agent like Aider or Continue.dev pointed at a local model) and the honest answer to “do I get more control now?” is: you get more visibility, not more inherent control. That distinction is the whole point.

What self-hosting genuinely buys you is inspection. No conversation data leaves your infrastructure. You can read the full system prompt instead of taking a proprietary one on faith. With a deterministic tool like Aider, you can audit exactly what went into each model call: the repo-map is a readable artifact, not a semantic black box like Cursor's embedding index. For anyone who cares about auditability and reproducibility, about being able to answer “what did the agent actually see?”, that inspectability is real and it's not nothing.

But the architectural inversion doesn't care where the model runs. Whether you're on a local model through Ollama, Claude Code against a cloud API, or Cursor on a subscription, the agent still reads its pre-session context before you speak, and you still have to architect that context deliberately. The discipline is identical. Self-hosting hands you a clearer window onto the mechanism; it does not hand you a different mechanism, and it certainly doesn't excuse you from the ETH Zurich lesson about what happens when you load context you didn't write. So the one shift worth taking from all of this: stop treating the context file as a gift you hand the agent, and start treating it as infrastructure with a running cost. Write what you actually understand about the codebase, load less rather than more, and remember that the agent read you first, so the version of you it read should be one you'd stand behind.

Frequently Asked Questions

Do AI Coding Agents Read Your Files Before You Type Anything?

Yes. At session start, an AI coding agent loads its system prompt, its tool definitions, and your context files (CLAUDE.md, .cursorrules, or AGENTS.md), along with any repo-map or memory file, all before your first message. In Claude Code specifically, the CLAUDE.md is delivered as a user message right after the system prompt, so the conversation effectively starts with your file rather than with you.

Do Context Files Like CLAUDE.md Actually Improve Agent Performance?

Partly, and less than most people assume. In the ETH Zurich evaluation of AGENTS.md-style files, the current abstract says context files do not generally improve task success and increase inference cost by over 20% on average. The detailed results are more useful for practitioners: developer-provided files improved performance by about 4% on average, but increased cost by up to 19%, while LLM-generated files reduced performance by about 3% on average and raised cost by more than 20%. The practical read: a file you wrote and understand can help a little; a file you didn't write can quietly cost you.

How Much of the Context Window Is Used Before I Send a Message?

A significant share. The system prompt, tool definitions, and behavioral instructions load before any user input, and together they consume a meaningful portion of the effective context window. Your usable working budget is smaller than the model's advertised context window because of this fixed startup overhead.

Does Self-Hosting an AI Model Give You More Control Over Context?

More visibility, not more inherent control. Self-hosting lets you inspect the full system prompt, keeps conversation data on your own infrastructure, and (with a deterministic tool like Aider) lets you audit exactly what went into each call. But the pre-session context architecture is the same as it is in cloud tools, and you still have to design your context deliberately.

What Is AGENTS.md?

AGENTS.md is an open format for telling coding agents how to work with a codebase, the agent-facing counterpart to a README. It emerged across the agent-tooling ecosystem (OpenAI Codex, Amp, Jules from Google, Cursor, and Factory) and is now stewarded by the Agentic AI Foundation under the Linux Foundation, with adoption across 60,000-plus repositories, making it the emerging cross-tool standard for pre-session agent context.

Share

More from the blog

Keep reading.

Ready to deploy? From $2.48/mo.

Independent cloud, since 2008. AMD EPYC, NVMe, 40 Gbps. 14-day money-back.