Context Engineering for Coding Agents
An agent's context window is its entire working memory, and it is both scarce and perishable: every frontier model degrades as the window fills — the phenomenon the field settled on calling context rot. Context engineering is the discipline of curating the smallest high-signal set of tokens the agent sees at each moment. In 2026 it displaced prompt engineering as the primary skill of working with coding agents: the question is no longer "how do I phrase this?" but "what does the agent know right now, and what is polluting that?"
Standing Instruction Files (CLAUDE.md / AGENTS.md)
Every serious harness loads a per-repository instruction file into each session — CLAUDE.md (Claude Code), AGENTS.md (Codex and the emerging cross-tool convention), and their cousins. This file is the project's persistent voice: the things you would otherwise re-type every session.
What belongs there, in priority order:
- Non-derivable rules — conventions and constraints the agent cannot infer from the code ("never bump the minor version without asking", "work directly on main", "all schema changes need a numbered migration").
- Command truth — exact build, test, lint, and deploy commands, including the flags that matter and the ones that look right but break things.
- Load-bearing gotchas — the traps that cost a past session an hour ("this test suite needs Docker", "that env var poisons the build").
- A map, not the territory — a short architecture orientation with pointers to deeper docs, never the full documentation inline.
Two hard-won sizing rules. First, frontier models are commonly treated as reliably following on the order of 150–200 standing instructions before compliance degrades — a rule of thumb, not a guarantee, but a useful budget: every instruction you add taxes the ones already there. Second, stale instructions are worse than missing ones: an instruction file that says something false about the codebase teaches the agent to distrust (or worse, obey) fiction. Prune on every significant refactor.
The strongest 2026 evidence for minimalism: in July 2026, Anthropic removed over 80% of Claude Code's own system prompt for the Claude 5-generation models with no measurable loss on coding evals — most of the deleted text was old constraints that had become conflicting noise. Your CLAUDE.md accumulates the same sediment; treat deletion as a feature.
Progressive Disclosure
The alternative to one giant instruction file is a tree of context loaded at the right time:
- The root instruction file stays lean and links to deeper reference files ("deployment details: see docs/deploy.md") that the agent reads only when the task calls for it.
- Skills are the formalization of this pattern: a skill's name and one-line description enter context at session start (tens of tokens); the full body loads only when the skill triggers. A skill with a 2,500-token body and a 60-token header defers ~98% of its cost until it actually fires. See SkillsVsMcp.
- Tool schemas, large reference docs, and rarely-used runbooks all follow the same rule: pay for context at use time, not at session start.
Long-Horizon Strategies: Compaction, Notes, Subagents
For work that outlives one context window, three complementary strategies became standard (Anthropic formalized this triad, but every harness converged on some version):
- Compaction — when the window fills, distill the conversation into a high-fidelity summary and continue from that. Automatic in mature harnesses; the craft is in what survives — decisions, constraints, and open questions must; file dumps and dead ends must not.
- Structured note-taking — the agent writes durable state outside the window as it works: a plan file with checkboxes, a findings log, a decisions record. After compaction or restart, notes are re-read at full fidelity. This is why SpecDrivenDevelopment doubles as a context strategy: the spec is a note the agent can always re-anchor on.
- Subagent isolation — delegate context-hungry work (a deep search, a large-file analysis) to a subagent that burns its own window and returns only the distilled answer. The orchestrator keeps the conclusion, not the 50,000 tokens of exploration. See SubagentOrchestrationPatterns.
Retrieval-Grade Project Knowledge
Instruction files scale to one repository; they do not scale to an ecosystem of projects, hosts, and operational knowledge. The Level-4/5 pattern (see AgenticCodingMaturityModel) is a shared knowledge layer with retrieval: durable decisions, runbooks, infrastructure maps, and gotchas live in a queryable store — a wiki, a RAG service, a knowledge base — that any agent, in any harness, can pull a session-start briefing from and update as it learns. The instruction file then shrinks to rules plus a pointer to the knowledge layer. This wiki is itself an instance of the pattern: agent-readable pages served through MCP with retrieval, rather than per-tool local memory.
Anti-Patterns
- The kitchen-sink CLAUDE.md — every practice ever learned, inline. It burns budget on session start and buries the load-bearing rules; the fix is to promote detail into linked files or skills.
- Context hoarding — pasting whole files or logs into chat "for context" when the agent could read them itself, targeted, at need.
- Compaction roulette — letting long tasks hit the window limit with no notes on disk, so every compaction is a lossy dice roll over which constraint survives.
- Conflicting layers — instruction file, skill, and prompt disagreeing; the agent resolves the conflict unpredictably. Keep one source of truth per rule.
See Also