Intermediate10 min

Context Engineering: Feed the Model the Right Things

A model can only reason about what is in its context window. Most failed agent runs are not reasoning failures, they are context failures: the agent never saw the file it needed, or it drowned in noise it did not. On a real codebase, deciding what enters the window is the skill that separates good results from frustrating ones.

The discipline is called context engineering: choosing what goes in, in what order, and when to clear it out. The goal is a small, high-signal context, not the biggest one you can stuff in.

Step 1: Point, do not paste

Instead of pasting a whole file, reference it. Modern agents read files on demand. In Cursor you mention a file with @, in Claude Code you name the path. This keeps the window lean and lets the agent pull exactly what it needs.

scoped-prompt.txt
The bug is in @src/auth/session.ts. Tokens expire too early.
Read that file and the test in @src/auth/session.test.ts,
find the cause, fix it, and make the test pass.

Step 2: Clear context between unrelated tasks

When you switch to a new task, old context becomes noise that can confuse the agent. In Claude Code, /clear wipes the conversation so the next task starts fresh. Treat a long, drifting session as a warning sign.

claude - app
# finished the auth fix, moving to a new feature
$/clear
Context cleared. Ready for a fresh task.
$> add pagination to the /users API endpoint
$

Step 3: Use compaction on long tasks

Some tasks are genuinely long. When the window fills up, agents can compact: summarize the work so far and keep going with the summary instead of the full history. Let it compact rather than starting over, so it does not lose the thread.

Smaller context, sharper answers
If results are getting worse mid-session, the cause is usually a bloated context, not a dumb model. Clear it, re-point at the few files that matter, and the quality jumps back up.
Claude Code - context meter
Context used: 38k / 200k tokens
Files in context: session.ts, session.test.ts
Tip: /clear before switching tasks
Watch the context budget; clear it when a new task begins.

Hands-on tasks