Context engineering: the real skill behind prompting
Jump to section
Prompting vs. context engineering
Most people focus on how to better phrase their prompts. That's like optimizing a SQL query without indexes — you can try all you want, but the fundamental problem is elsewhere. Context engineering is the discipline of managing what information the model has access to, when it gets it, and in what format. Whenever AI gives a bad response, the first question isn't 'how do I prompt better?' but 'what context is the model missing?'
Layers of context in AI dev tools
Context comes from several layers: the system prompt (set by the tool), project-level instructions (CLAUDE.md, .cursorrules), files loaded into context, conversation history, and your current prompt. Each layer has different priority and affects output differently.
As a developer, you control three layers: project instructions, which files get loaded, and your prompt. The biggest lever is the first one — project instructions apply to every conversation automatically.
Why the same prompt gives different results
Imagine the prompt 'refactor this function'. Without context, the model has no idea whether you prefer functional or OOP style, whether you use TypeScript strict mode, whether you have tests. With a CLAUDE.md that says 'use functional composition, TypeScript strict, every function must have a unit test' — that same prompt gives a dramatically better result.
The context window as RAM
Think of the model's context window as your computer's RAM. You have limited capacity and need to decide what goes in. Loading an entire repository is like opening 500 browser tabs — technically possible, but performance drops rapidly. Every token in context has its cost — irrelevant information isn't just useless, it actively hurts, because the model might pick up a false signal from an unrelated file.
Rule of thumb: the model works best when it has exactly what it needs in context — no more, no less. Too little context = hallucinations. Too much context = needles lost in a haystack.
Practical context engineering techniques
Several techniques that immediately improve your output: 1) Load relevant files before prompting. 2) Start a new conversation when switching topics. 3) Use CLAUDE.md for things that always apply. 4) Reference specific line numbers and files in your prompt. 5) Structure context hierarchically — from general to specific.
In Claude Code, you can use /clear to reset context, but CLAUDE.md stays. That's the advantage — your project instructions survive every reset.
Context vs. fine-tuning vs. RAG
Context engineering is the fastest way to influence model behavior. Fine-tuning requires data and compute. RAG requires infrastructure. But a well-written CLAUDE.md — that's 10 minutes of work with an immediate effect on every conversation.
Intro to Large Language Models
Open your main project and write down: 1. What project instructions do you have? (CLAUDE.md, .cursorrules, other) 2. What information does the model need but doesn't have? (conventions, architecture, dependencies) 3. What information does the model get but doesn't need? (irrelevant files, old history) Based on your audit, plan what to add to CLAUDE.md and what to stop loading into context.
Hint
Focus on things you repeatedly explain to the model — those are candidates for CLAUDE.md. And notice which files the model reads but never uses — those introduce noise.
Create a CLAUDE.md file for your current project. Include: tech stack, conventions, key architectural decisions, common commands, and specific AI instructions ('always use TypeScript strict mode', 'write tests in pytest'). Test: give AI the same task with and without CLAUDE.md. How much does output quality differ?
Hint
Document your process and results — they'll serve as reference for similar future tasks.
Pick one programming task and run three experiments: 1. Minimal context: give the task with no CLAUDE.md, no loaded files 2. Medium context: add CLAUDE.md and 2-3 relevant files 3. Maximum context: add everything — CLAUDE.md, relevant files, examples, history For each experiment rate: correctness, consistency with project style, number of fixes needed. Find the sweet spot.
Hint
The sweet spot is usually 'CLAUDE.md + directly relevant files'. Too much context can be counterproductive — the model gets lost in irrelevant details.
- Context engineering > prompting — focus on what the model knows, not just how you ask
- Context has layers: system prompt, project instructions, files, history, prompt
- More context isn't always better — maximize signal-to-noise ratio
- CLAUDE.md is the most effective context engineering tool
- Every new conversation = clean context (except project instructions)