Methodology

Context Engineering for Coding Agents: A Practical Guide

Context engineering is the craft of controlling everything in the model's context window, instructions, code, history, retrievals, so your agent has exactly what it needs and nothing that misleads it. Here are the six levers that matter for coding agents.

By Kylian Migot · Updated July 2026 · 10 min read

Quick answer

Context engineering is the practice of controlling everything that enters the model's context window, instructions, code, conversation history, retrieved documents, so the agent has exactly what it needs and nothing that misleads it. The term was popularized in mid-2025, when Shopify's Tobi Lütke and Andrej Karpathy pushed it as the successor framing to prompt engineering, and it is now standard vocabulary for the central skill of working with coding agents.
One-line definition
Curating everything in the context window: instructions, code, history, retrievals
Popularized
Mid-2025, by Tobi Lütke and Andrej Karpathy, as prompt engineering's successor
The six levers
Project files · task specs · hygiene · isolation · retrieval · window economics
Core principle
Relevance beats volume, even with 1M-token windows
01

The Definition, and Where the Term Came From

A model's output is a function of its weights and its context window, and you only control one of them at inference time. Context engineering is the discipline of controlling it well: deciding which instructions, which code, which history, and which retrieved material occupy the window, and, just as deliberately, what stays out. The goal is an agent that sees exactly what the task requires and nothing that misleads it.

The term broke into the mainstream in mid-2025. Shopify CEO Tobi Lütke publicly argued it was a better name than “prompt engineering” for the real skill, providing an LLM with the full context a task needs, and Andrej Karpathy endorsed the framing, noting that serious LLM applications are mostly context-filling machinery around the model. The label stuck because it named what practitioners were already spending their time on, and by 2026 it is standard vocabulary in vendor docs, engineering blogs, and job listings.

02

Why It Displaced Prompt Engineering

Prompt engineering assumed the prompt was the whole input, which was true when you pasted a function into a chat box. Coding agents broke that assumption. An agent working in your repo gets most of its information by reading the repo: it explores files, greps for symbols, reads your CLAUDE.md, runs commands, and accumulates a long tool-call history. Your prompt is a few hundred tokens steering a window filled with hundreds of thousands.

At that ratio, wordsmithing the prompt is polishing the doorknob on a house you have not built. What decides agent output quality is whether the window contains the right conventions file, the right spec, the relevant modules, and clean history, or a stale doc, an accumulated wrong turn, and three files that look relevant but are not. That allocation problem is context engineering, and it is a systems skill, not a phrasing skill, which is why it sits at the center of agentic engineering rather than beside it.

03

The Six Levers of Context Engineering

For coding agents specifically, the practice reduces to six levers. Pull them in this order, they run roughly from cheapest to most structural:

  1. 1

    Durable project context (CLAUDE.md / AGENTS.md)

    A short file the agent reads every session: build and test commands, conventions, boundaries. This is the context that should never need repeating. Keep it accurate and terse, and generate a solid starting version with the free AGENTS.md / CLAUDE.md generator.
  2. 2

    Task context (a spec with acceptance criteria)

    Per task, the highest-value context is a written spec: scope, files, acceptance criteria, exclusions. It tells the agent what done means and tells the reviewer what to review against. The full practice is spec-driven AI development.
  3. 3

    Context hygiene (compaction and fresh sessions)

    Long sessions accumulate dead weight: abandoned approaches, resolved errors, exploratory reads. Compact when history grows stale, and prefer a fresh session per story over one marathon session, a clean window plus a good spec beats a cluttered window with perfect memory.
  4. 4

    Isolation (subagents and worktrees)

    Keep unrelated work out of each other's windows. Subagents give exploratory work its own context that returns only conclusions; git worktrees give parallel tasks separate directories and branches so one agent's changes never appear in another's view. The mechanics are in parallel agents with git worktrees.
  5. 5

    Retrieval (MCP for what the repo can't tell it)

    Some context lives outside the codebase: database schemas, API docs, issues, browser state. MCP servers let the agent pull it on demand instead of you pasting it in, and curating which servers are worth their context cost is itself a context decision: MCP servers for AI coding.
  6. 6

    Context-window economics

    Current Claude models ship 1M-token windows (Fable 5, Opus 4.8, and Sonnet 5 as standard; Haiku 4.5 has 200k), big enough for a large repo plus specs. A big window is not a license to fill it: irrelevant content still competes with relevant content for the model's attention, and every token has a price. Relevance beats volume at every window size.

Ship your first agent today

Download AIDEN free and point it at your existing Claude Code or Codex setup. No credit card, running in minutes.

Download AIDEN free

Free to start · macOS 12+ · No credit card required

04

The Failure Modes

Bad context is worse than missing context, because the agent trusts what it is given. Three failure modes account for most ruined sessions:

Poisoned context

An early wrong assumption, a hallucinated API, a misread file, stays in the window and quietly skews every subsequent decision. Once you spot it, arguing with the session is futile; start fresh with a corrected brief.

Stale CLAUDE.md

The conventions file says npm but the repo moved to pnpm; it names a directory that was deleted in March. A stale context file is anti-context: the agent confidently does the wrong thing because you documented it.

Kitchen-sink prompts

Pasting every possibly relevant file, log, and doc into the task. The two facts that matter drown in fifty that don't, and you pay for the privilege. Curate, or let the agent retrieve what it needs.
05

How AIDEN Structures Context per Story

You can pull all six levers by hand, and it is worth doing at least once to internalize them. AIDEN's contribution is making the per-task levers structural: every story on the board gets a spec drafted from the card and codebase analysis (task context, gated on your approval), its own git worktree (isolation), and a fresh agent session scoped to that story (hygiene). Your CLAUDE.md and MCP setup carry over unchanged, because AIDEN runs your existing CLIs. The result is that each agent starts every story with a clean, relevant window by default, not by discipline.

06

One Pillar of a Larger Discipline

Context engineering answers one question: what should the agent see? It does not answer who approved the work, where parallel changes land, or how output gets verified and reviewed. Those belong to the surrounding discipline of agentic engineering, where context engineering is one of six core practices alongside specs, harnesses, isolation, verification, and review. The conventions layer that carries context rules across sessions, and the rest of the guardrails around a raw agent, is covered in the AI agent harness. Master the window first; it is the practice the others lean on.

FAQ

What is context engineering?
Context engineering is the practice of controlling everything that enters a model's context window, instructions, code, conversation history, retrieved documents, so the agent has exactly what it needs to do the task and nothing that misleads it. For coding agents specifically, that means curating durable project context (CLAUDE.md/AGENTS.md), writing task specs, keeping sessions clean, isolating parallel work, and wiring up retrieval via MCP.
Who coined the term context engineering?
The term existed earlier, but it was popularized in mid-2025 when Shopify CEO Tobi Lütke publicly championed it as a better name than prompt engineering for the core skill of working with LLMs, and Andrej Karpathy endorsed the framing. Since then it has become standard vocabulary across the industry, appearing in vendor documentation, engineering blogs, and job descriptions.
How is context engineering different from prompt engineering?
Prompt engineering optimizes the wording of a single input. Context engineering manages the entire context window across a whole session: which files the agent reads, what project conventions it knows, what the spec says, what history has accumulated, what it retrieves from external sources. For coding agents the distinction is decisive, because an agent working in your repo gets most of its information from the codebase and its context files, not from your prompt.
Does a 1M-token context window make context engineering unnecessary?
No, it changes the failure mode. Current Claude models (Fable 5, Opus 4.8, Sonnet 5) ship 1M-token windows, big enough to hold a large repo plus specs. But a big window is not a license to fill it: irrelevant or contradictory content still degrades output, and every token costs money and attention. Relevance beats volume. The window removes the hard ceiling; it does not remove the curation problem.
What are the most common context engineering mistakes?
Three recur constantly: poisoned context, where an early wrong assumption or bad file stays in the window and skews everything downstream (the fix is starting a fresh session); a stale CLAUDE.md that documents commands and conventions the repo no longer uses, actively teaching the agent wrong facts; and kitchen-sink prompts that paste in everything vaguely related, burying the two facts that matter under fifty that don't.

Keep reading

Context engineering, structured per story.

AIDEN gives every story an approved spec, its own worktree, and a fresh session, the three highest-leverage context moves, made automatic. Free for one project.

macOS 12+ · Bring your own Claude Code or Codex · Your code stays local