Context engineering for coding agents
The context window is the agent's entire world. Context engineering is the discipline of deciding what fills it — retrieval, structure, budget, and verification — applied to code.
From prompt engineering to context engineering
Prompt engineering optimizes the words you ask with. Context engineering designs everything the model sees: which retrieved code lands in the window, how results are ordered and compressed, what survives as the conversation grows, and how you verify what the model actually knew. For one-shot questions the prompt matters most. For agentic workflows — retrieve, edit, test, repeat — the context pipeline matters more, because every step's inputs compound into the next step's decisions.
The budget problem
A real codebase is orders of magnitude larger than any context window. A 100k-token repo — a small one — already dwarfs what you can spend per turn once system prompts, tool schemas, and history take their share. Every agent run is an exercise in scarcity economics: each token of context spent on irrelevant code is a token not spent on the code that mattered. That's why "just paste the files" stops scaling immediately, and why the window's contents should be chosen, not accumulated.
The four levers
- Retrieval — what gets in. Hybrid semantic + keyword search over an AST-aware index is the reliable way to select the few chunks that matter from the thousands that don't. Measured retrieval (recall you can publish) is the difference between grounding and guessing.
- Structure — how it's arranged. Complete semantic units over severed fragments; symbol definitions pulled alongside references; a
repo-mapsketch ahead of deep dives, so the model orients before it reads. - Budget — what stays. As conversations grow, context must be pinned (the function under active edit) and evicted (the file read ten steps ago). Unmanaged windows fill with stale, contradictory material — the classic cause of agents "forgetting" decisions made earlier in the same session.
- Verification — what you can prove. An evidence rail that shows which chunks were retrieved at which scores, what was pinned or evicted, turns the agent's knowledge from an assumption into an inspection point — and makes regressions debuggable instead of mysterious.
What this looks like in practice
OCE is built as a context engineering tool, not just a search box:
npm install -g @dhaxor/open-context oce index # hybrid, AST-aware index — the supply side claude mcp add oce -- oce mcp # serve measured context to Claude Code oce trace # the evidence rail: see the agent's context live
Trace shows the ranked chunks in the model's context, lets you pin what matters and evict what doesn't, and records the run in a tamper-evident audit log afterward. The retrieval underneath is the same engine described in the code RAG guide, served over MCP per the MCP server guide — and scored on the benchmarks page before you have to trust it.
Memory: the fifth lever
Everything above governs this session. Agent memory governs the first input of the next one — remembered facts and preferences injected before retrieval ever runs. The same discipline applies: measured recall, visible injections, explicit supersession. OCE ships it as part of the stack, not a separate product.
Frequently asked questions
What is context engineering?
The discipline of deciding what goes into an LLM's context window — retrieved code, instructions, history, structure, budget — so the model can complete the task. It extends prompt engineering to the whole window.
How is it different from prompt engineering?
Prompt engineering optimizes the instructions; context engineering designs everything the model sees. In agentic systems, retrieval and context management usually dominate outcomes.
Why does it matter especially for code?
Because the artifact is bigger than the window. An agent's plan is only as good as the code its context contains — weak selection shows up as hallucinated APIs and edits that break unseen callers.
What is an evidence rail?
A live view of exactly what the model knew: retrieved chunks, scores, pins, evictions. OCE's Trace workspace provides it, plus a hash-chained audit log of every run.
Where do I start?
Give your agent measured retrieval and an inspectable window: oce index, claude mcp add oce -- oce mcp, oce trace. Setup details are in the docs.