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:

  1. 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").
  2. Command truth — exact build, test, lint, and deploy commands, including the flags that matter and the ones that look right but break things.
  3. Load-bearing gotchas — the traps that cost a past session an hour ("this test suite needs Docker", "that env var poisons the build").
  4. 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:

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):

  1. 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.
  2. 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.
  3. 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

See Also