Context Engineering
The practice of giving AI the surrounding context it cannot sense on its own.
You ask the AI to write a login endpoint (the function that logs users in). It delivers generic boilerplate — wrong framework, wrong folder, wrong error format. The AI is not stupid. It simply does not know your project.
Context Engineering is the discipline of giving the AI exactly the right information so it produces code that fits your codebase — not just any code that runs without errors. By the end of this article, you will understand how Context Engineering differs from Prompt Engineering, what belongs in a rule file, and how to decide which information the agent needs and when.
From Prompt to Context
Context Engineering — Shaping the AI's Working Environment
The onboarding analogy has a limit: a new hire learns and remembers permanently. An AI agent has a finite context window and may lose information when it overflows. The analogy does not capture the forgetting problem.
You optimise the individual question. "Write a login endpoint" becomes "Write a login endpoint with NestJS in src/modules/auth/ using absolute imports." Quality depends on how detailed you are each time.
You optimise the working environment. Through a rule file, the AI already knows your project uses NestJS, where services belong, and which error conventions apply. "Write a login endpoint" is enough — the context provides the rest.
Common Misconception
The Rule File — Persistent Project Context
A rule file is a project-level configuration that your AI coding tool reads automatically on every interaction. The content is natural language: architecture overview, coding standards, build commands, anti-patterns, workflows. Anthropic recommends keeping it concise and well-structured — not a dump of everything, but a curated set of what the agent needs most.
Like a cockpit checklist for pilots: the rule file does not teach the AI to fly — it ensures it consistently runs the same checks and avoids errors from carelessness.
What Belongs in a Rule File?
Example: Excerpt from a CLAUDE.md
Common Misconception
Context Hierarchy — Less Is More
LLMs have a finite attention budget. As context grows, precision when retrieving and connecting information tends to decrease. The central question is therefore not "How do I fit everything in?" but "How do I load the right information at the right time?"
Think of a surgeon's instrument tray. The operating room has thousands of instruments available, but only a small tray with the instruments needed for the current step is within reach. More instruments on the tray means more clutter, slower decisions, higher error risk. The surgeon asks for specific instruments when needed — just in time.
The analogy has a limit: a surgeon knows exactly which instrument they need. An AI agent must often discover what it needs during execution, using search and reading tools.
An example: a codebase with 50,000 lines. Bad approach: paste everything into the prompt. Good approach: CLAUDE.md provides the architecture overview, the agent uses search tools to find the specific files for the current task. Result: the agent works with 200 highly relevant lines instead of drowning in 50,000 lines of mixed relevance.
The Feedback Loop
Common Misconception
Interactive: Why More Context Does Not Always Help
The article explains that precision decreases as context grows. Move the slider and observe how costs scale: loading the rule file is constant (green). Reading the entire context grows linearly (blue). But cross-referencing information — the agent's core job — grows quadratically (red). Beyond n=1000 information units, the difference becomes dramatic. This is why less relevant context beats more total context.
At n=100, the difference becomes visible: O(n²) requires 10.000 operations, while O(n) needs only 100. O(log n) needs just 6.6 — that's 15x less than O(n).
Ratio to O(n)
| Complexity | Operations | Factor vs. O(n) |
|---|---|---|
| Regeldatei laden | 1 | 100x faster |
| Kontext lesen | 100 | 1x (Reference) |
| Infos verknüpfen (n²) | 10.000 | 100x slower |
Key Takeaways
Knowledge Check: Context Engineering
Checkpoint: Context Engineering
- Explain the difference between Prompt Engineering and Context Engineering using the onboarding analogy.
- What belongs in a rule file — and what should never be in one?
- Why is it often worse to give the AI your entire codebase as context instead of only the relevant files?