← Back to Blog

Context Engineering

Context LLMs Best Practices

Without custom model training, the quality of an LLM's output is determined entirely by the quality of its inputs. We can take several key steps to ensure high-quality context and input:

Aspect Prompt Context
Definition The Instruction / Task The Background / Knowledge
Role Telling the model what to do Telling the model what it knows
Persistence Dynamic and query-specific Static or long-term information
Analogy The Exam Question The Textbook
Form Conversational Programmatic

1. Context Window

We should consider 5 subtle points to optimize the context window:

  1. Correctness: Provide accurate, verified info to prevent errors.
  2. Completeness: Include every essential detail to avoid missing context.
  3. Size: Remove irrelevant data to minimize token usage.
  4. What not to do: Define exactly what changes should be avoided.
  5. Trajectory: List the sequence of steps taken to clarify the current path.

2. Hierarchy of Failure

Context Rot: Model output quality degrades as the context window fills up with increasing token counts.

Note: A localized coding bug only affects a single line of code. However, a flawed plan can propagate into hundreds of incorrect lines. Worst of all, poor research—such as failing to understand how the system actually works—can corrupt thousands of lines.
  1. One bad LOC (Line of Code) == one bad LOC
  2. One bad LOR (Line of Research) = 100 wrong LOP
  3. One bad LOP (Line of Plan) == 100 wrong LOS
  4. One bad LOS (Line of Spec) = 1K wrong LOC

Flow: (1) Research → (2) Plan → (3) Spec → (4) Code

3. One Big AGENTS.md / CLAUDE.md Fails Because:

Solution: A short AGENTS.md (roughly 100 lines) is injected into context and serves primarily as a map, with pointers to deeper sources of truth elsewhere.

4. Pause and Resume a Session

Manage agent sessions actively to keep context windows optimal:




When Context Fails

Basically, this means: Garbage in → Garbage out.

1. Context Poisoning

2. Context Distraction

3. Context Confusion

4. Context Clash

How to Fix Context Issues

Understanding failure modes is only half the battle. When context gets cluttered, poisoned, or conflicted, active mitigation is required. For a full breakdown of strategies, configurations, and REPL commands to keep your context optimized, read our companion guide:

👉 Context Fix Strategies →