Two years ago, everyone wanted to learn prompt engineering. Courses sold lists of magic phrases. "Act as a senior developer." "Think step by step." Some of it helped a little.
Then the tools changed. AI stopped answering one question at a time and started working through tasks: reading files, running commands, checking results, deciding the next step. For that kind of work, the wording of one prompt matters much less than everything else the model is looking at. That everything else is the context, and managing it well is called context engineering.
What context engineering means
Every time a model responds, it sees a block of text called its context. For a coding agent that includes:
- Instructions: the system prompt and your project file (
CLAUDE.md,AGENTS.md, Cursor rules). - Your request: the prompt you just typed.
- Files: the code it has opened and read.
- Tool results: test output, error logs, search results, command output.
- History: everything said and done earlier in the session.
- Memory: notes saved from earlier sessions.
Anthropic's engineering team, in a September 2025 article, defined context engineering as the set of strategies for curating and maintaining the optimal set of tokens during inference. In plain words: making sure the model sees what it needs, and not much else.
Why it replaced prompt engineering
Prompt engineering is about one message. Context engineering is about a whole session.
When you ask a chatbot one question, the prompt is most of the context, so wording it well matters a lot. When an agent runs for forty steps, your prompt is a few lines at the top. Below it sit thousands of lines of files, logs and earlier attempts. If those are messy, a perfect prompt will not save the result.
Model vendors have said as much. Anthropic's Claude Code docs now list "think harder" and ALL CAPS instructions under advice you can stop following. Those phrases are ordinary text, not switches. What still matters is giving the model information it does not have, and keeping out information it does not need.
A good prompt asks the right question. Good context makes sure the model can answer it.
The four failures of bad context
Most bad AI output traces back to one of four context problems.
- Missing context. The agent does not know your test command, the folder it must not touch, or a decision your team made last week. It guesses, confidently.
- Too much context. A 500-line instruction file, ten connected tools and the whole repo pasted in. The useful line gets lost, and you pay for all of it on every request.
- Stale context. The session has three unrelated tasks and two failed attempts in it. The model keeps re-reading them and gets pulled back towards old mistakes.
- Wrong context. An outdated doc, a copied snippet from a different framework, or a comment that no longer matches the code. The model trusts it.
Notice that none of these are fixed by better wording.
The core techniques
Anthropic's article names several techniques for long-running agents. They map neatly onto what you do day to day as a developer.
Just-in-time retrieval
Instead of loading everything up front, keep lightweight references, like file paths, and load the data only when it is needed. In practice: point the agent at @src/auth/session.ts instead of pasting five files, and let it search for the rest.
Compaction
When a conversation gets long, summarise it and continue from the summary. Claude Code compacts automatically, and you can run /compact with a focus, like "keep the API changes and the test commands." Even better is not needing it: /clear between unrelated tasks.
Structured note-taking
Save important notes outside the context window, then bring them back when needed. A SPEC.md for the feature, a NOTES.md of decisions, a checklist the agent updates as it goes. These survive a fresh session; chat history does not.
Sub-agents
Give a focused job to a separate agent with a clean context, and have it return a short summary. Useful for research or review. A second session that did not watch the code being written makes a good independent reviewer.
Context files: small and specific
Your project instruction file is the one piece of context that loads on every single task. That makes it the most valuable and the most expensive.
Claude Code's docs recommend keeping each CLAUDE.md under 200 lines. Codex combines AGENTS.md files up to 32 KiB by default and tells you to keep them small to make usage last. Both say the same thing: write only what the agent cannot work out from the code.
Here is what that looks like in practice. Picture a project that starts with a 300-line CLAUDE.md copied from a template: coding style essays, a description of every folder, a list of twenty "best practices". Trimmed down, it could become this:
# Commands
- Tests: pytest -q
- Run locally: uvicorn app.main:app --reload
# Rules
- Never edit migrations by hand; generate them
- All model calls go through app/llm.py
# Gotchas
- Tests need OPENAI_API_KEY unset; they use the fake client
Eight lines. Everything else the agent could learn by reading the code.
A test for every line:
- Could the agent find this by reading the code?
- Would it actually go and look?
If both answers are yes, delete the line. What remains is usually short: commands, forbidden areas, gotchas and decisions.
Reusable prompts
Context engineering is also about not reinventing the same instructions every day. When a prompt works, save it.
- A review prompt you run on every change: "Check this diff for unexpected files, new dependencies, secrets, and missing tests."
- A spec interview prompt: "Interview me until you could write the spec, then write it to SPEC.md."
- A bug prompt template: symptom, where to look, a failing test first, then the fix.
Most agents let you save these as commands or skills, so they load only when you call them instead of sitting in every session. That keeps your always-on context small and your best instructions one keystroke away.
A context engineering checklist
Use this before any task bigger than a quick fix:
- Is there a written spec or plan the agent can read?
- Is the instruction file short and current?
- Have I pointed at the exact files, not the whole repo?
- Are only the tools I need connected?
- Is this a fresh session, or does the history belong to this task?
- Is there a check (tests, build, type check) the agent can run to know it is done?
Why this is a career skill
Every company adopting coding agents is finding the same thing: the tool is the same for everyone, and the results are not. The difference is the people who can set up an agent's context, direct it, and review what it produces. That is a skill you can learn, and it transfers across Claude Code, Codex, Cursor and whatever comes next.
If you are starting out, practise it on real projects. Our AI engineer roadmap shows where it fits, and how to use Claude Code puts it into a daily workflow.
Context files and reusable prompts are a big part of our free Saturday workshop. We write a CLAUDE.md together, build with it, and compare the results against a session with none. Join us this Saturday.