Context engineering
Deciding what a model sees before it answers: which files, docs, examples, and history go into the request, and in what order. It is the discipline that replaced prompt wording as the thing that most affects output quality on real codebases, because a model with the wrong context fails no matter how the instruction is phrased.
At a glance
- Question it answers
- What should the model see?
- Inputs
- Instructions, files, tool output, history
- Constraint
- The context window
- Main lever
- Selection and pruning
- Nearest term
- Prompt engineering
How it works
For a coding agent, context comes from four places: standing instructions such as a committed agents file, material the agent retrieves such as files and search results, tool output such as test failures and logs, and conversation history including its own earlier attempts. All four compete for the same window, so the work is deciding what gets in and what gets cut.
In practice that means naming the two files that matter instead of the whole folder, trimming a long log down to the failing test, writing the spec into the task rather than leaving it in a chat thread, and starting a fresh session when the old one is full of dead ends.
Why it matters
A model cannot use information it was never shown. If the agent never sees that your repo already has a date helper, it will write another one, however politely the prompt asks for reuse. On real codebases most bad output traces back to missing, stale or misleading context rather than to an unclear instruction.
Placement matters as well. An instruction buried in the middle of a long conversation tends to get less weight than the same instruction near the start or restated close to the request.
Context engineering vs. prompt engineering
Prompt engineering is about how you phrase the request: role, format, examples, constraints. Context engineering is about what material surrounds that request. They overlap, but on a coding task with a capable model, better context usually moves results more than better wording.
Retrieval-augmented generation (RAG) is one technique inside context engineering, where a search step picks passages to include. Coding agents often do the same thing less formally, by running grep or reading files they choose, which makes the starting instructions about where to look all the more important.
Example
Add rate limiting to POST /api/login.
Relevant: src/app/api/login/route.ts, src/lib/rate-limit.ts (reuse it).
Verify: pnpm test src/app/api/login
Out of scope: other routes, the signup flow.Common mistakes
- Dumping the whole repository into the request, which dilutes the relevant files and spends the window on noise.
- Keeping project knowledge in places the agent cannot reach, such as a private doc or one engineer's memory.
- Never pruning old instructions, so outdated rules keep steering new work.
In Fredrin
Fredrin keeps project context as markdown in the repo, so each Worker reads the same files in its worktree that you can open and check yourself.
How Fredrin keeps project contextRelated terms
Frequently asked questions
Is context engineering the same as prompt engineering?
No. Prompt engineering shapes the wording of the request, while context engineering decides which files, docs, tool results and history the model sees alongside it.
How do I give a coding agent better context?
Commit a concise agents file, name the specific files and tests involved in each task, write the requirements into the task itself, and restart sessions that have filled with stale attempts.