Context Engineering: The Foundation of Effective LLM Interactions
Why context matters more than you think
Most of the talk around large language models (LLMs) is about prompt engineering: finding the perfect wording for a question or instruction. I think there's a more basic skill underneath every good interaction with AI, and that's context engineering.
Context engineering means giving the model the right information, at the right time, in a format it can use. Get it right and you get output tailored to what you actually need. Get it wrong and you get a generic answer.
What is context engineering?
It's the habit of deliberately structuring and organising what you give an LLM before you ask it to do anything. That usually covers:
- Background on your project, domain or situation
- Examples that show the output format or style you want
- Constraints and requirements that guide the model's behaviour
- Domain-specific knowledge that might not be in the model's training data
- Earlier conversation history, so the model has continuity
The context window: your workspace
Modern LLMs have a "context window", which is the amount of information they can process in a single interaction. Think of it as working memory. Recent models handle 200,000 tokens or more, roughly a 500-page novel.
That doesn't mean you should fill it with everything you've got. A well-curated 2,000-token context often beats a rambling 20,000-token dump of loosely related information.
Why it matters so much
1. Precision and relevance
Without context, an LLM falls back on general knowledge and common patterns. That's fine for generic questions and terrible for specialised tasks. Ask an LLM to refactor code without showing it the existing codebase and you'll get textbook solutions that ignore your architecture, naming conventions and design patterns.
2. Consistency across interactions
On a multi-step project, keeping the relevant context in play stops the LLM contradicting itself or forgetting decisions you made earlier. This matters a lot in software development, where one architectural choice affects the whole codebase.
3. Reducing hallucinations
LLMs sometimes produce information that sounds plausible and is wrong, which is what people call "hallucination". Concrete, factual context grounds the model's answers and makes it much less likely to make things up.
4. Domain adaptation
Your project, company or field probably has its own terminology, conventions and requirements. Good context lets you "tune" a general-purpose LLM to your domain without fine-tuning or retraining the model.
How I approach it
Be specific and structured
Organise what you hand over instead of dumping it. Headings, bullet points and clear labels all help. If you're providing code, include file names and the relevant line numbers. If you're sharing documentation, keep its original structure.
Prioritise relevance
Include what the task actually needs. If you're debugging one function, the LLM doesn't need your entire application. Give it the function, its dependencies and maybe the related test cases.
Provide examples
A good example saves a lot of explanation. If you want the LLM to follow a particular coding style, show it that style. If you want a specific output format, give it a sample.
Update context as you go
As the conversation moves on, feed in new information, changed requirements and recent developments. Take out anything outdated that might confuse the model.
Use metadata
When you share files or code snippets, include file paths, timestamps, version numbers or dependency information. It helps the LLM understand how things relate and make better decisions.
An example
Here are two ways to ask for the same feature in a web application.
With poor context:
"Add a login button to my app."
With rich context:
"I'm working on a React application using TypeScript and Material-UI. I need to add a login button to the navigation bar component (src/components/Navbar.tsx). The button should match our existing design system; specifically, it should use the primary colour variant with medium size, consistent with our other action buttons in the UserProfile component. When clicked, it should navigate to '/auth/login' using our existing React Router setup."
The second version tells the LLM the framework, the file location, the design requirements and how it plugs into the rest of the app. You'll get something far more useful that needs very little adjustment.
Where this is heading
LLMs are increasingly built to work with rich context. Tools like Claude Code can keep track of entire codebases, previous interactions and project-specific conventions. The developers who get good at context engineering will get the most out of these tools.
Conclusion
Context engineering is fundamental to using LLMs well. When you're thoughtful about what you give the model, it stops being a generic assistant and starts working like a collaborator who knows your needs, constraints and goals.
Next time you're about to fire off a prompt, ask yourself: "What context does the model need to understand what I'm asking for?" Answering that will improve your results far more than polishing the wording.
Member discussion