Prompting

Context Engineering: Giving AI the Right Information to Code Well

When AI writes code that misses the mark, the instinct is to blame the model or reword the prompt. But most of the time the model was capable — it just didn't have the information it needed. Closing that gap on purpose is what "context engineering" means, and it's a bigger lever on code quality than any clever phrasing.

What context engineering actually is

Prompt engineering is about how you word a request. Context engineering is about what the model can see when it answers: the surrounding code, the constraints, the shape of your data, the conventions your project already follows. A model can only reason about what's in front of it. Give it the wrong picture and it will confidently write code for a project that doesn't exist.

The model isn't guessing to annoy you. It's filling in the blanks you left — and it fills them with the most generic assumption that fits.

The information AI needs to code well

Five things do most of the work. When output goes wrong, one of these was usually missing:

  • The goal and the why. Not just "add a login form" but what it's for and how it fits the rest of the app.
  • The constraints. The language, framework, and versions; the style you want; anything it must not change.
  • The shape of the data. What the inputs and outputs actually look like — a sample object beats a paragraph of description.
  • The existing patterns. How your project already does similar things, so new code matches instead of inventing a second way.
  • What "done" looks like. A concrete example of correct behavior, including an edge case or two.

The common context failures

Most disappointing output traces back to one of these:

  1. Asking for a change without showing the code it has to fit. The model rebuilds from scratch and breaks your conventions.
  2. Never stating the stack or versions. You get code for the wrong framework, or patterns that were current two years ago.
  3. Vague success criteria. "Make it work" leaves the model to decide what "work" means.
  4. Drowning it in noise. Pasting your entire project when only two files matter buries the signal. More context isn't better; relevant context is.

How to give context deliberately

You don't need special tools — just a habit of showing rather than telling:

  • Paste the relevant file or the pattern you want matched, not a description of it.
  • State the stack and constraints up front, every time it matters.
  • Give a sample of the real data the code will handle.
  • Define "done" with an example, including how it should behave when something is empty or invalid.
  • Trim to what's relevant. Signal over volume.

This is the layer above writing prompts that generate clean code: wording matters, but the information you put in front of the model matters more.

Where Vibe Coder Playground fits: the best context is what the code actually does when it runs. When the AI's output is wrong, the Playground shows you the real error, the rendered DOM, and the live network calls — exactly the information to paste back so the model fixes the actual problem instead of guessing at a described one.

Treat context as the input you control. The model handles the typing; you handle making sure it's typing for the right project.

Get the free Playground and turn what your app really does into better context →

Related: vibe coding best practices — a repeatable workflow →

Related: how to manage vibe coding sessions so context survives a restart →