Guide
Context engineering for AI agents: what to give them and how
Coding and work agents fail less from lack of skill than lack of context: they don't know what you did yesterday, what was decided on the call, or what's on your screen. Here's how to give Claude Code, Codex, Cursor and Gemini CLI the context they need, without pasting it in every time.
What agents are missing
An agent starts each session with your request, its instructions, and whatever it can read from the repo or folder it's in. Everything else it has to ask you for, or guess. In practice the missing context falls into four kinds:
- History: what you did on this last time, in this agent or another one.
- Decisions: what was agreed on a call or in a thread, and why.
- Live state: the error on your screen, the page you're looking at, the failing test in another terminal.
- Open work: what you promised, what's blocked, what's next.
None of these are in the code. All of them change daily. That's why “just write a better prompt” stops working after the first hour.
Four ways to give context
| Way | Good for | Falls short on |
|---|---|---|
| Instruction files (CLAUDE.md, AGENTS.md, .cursor/rules) | Stable rules: how to build, test, name things | Anything that changes; they go stale |
| Pasting into the chat | One-off facts the agent can’t reach | Your time, and the context window |
| The agent’s own memory | Preferences you told that agent | Work in other apps, calls, other agents |
| Tools over MCP | History, decisions, live state, open work, looked up on demand | Needs a server that has the data |
The pattern that scales is the first plus the last: short instruction files for the rules, and MCP tools for everything that changes. The MCP memory server guide covers the kinds of servers in more detail.
Rules that hold up
Retrieve, don't preload
Let the agent fetch context when the task needs it, not stuff everything into the first message. A tool call that returns the five relevant lines beats a pasted page of background.
Describe tools for the model
The agent picks tools by their descriptions. “Where the user left off on a project: latest agent sessions, call notes, files used. Use it at the start of work on a project” gets called at the right moment. “Get data” doesn't.
Share context across agents
If you use Claude Code in the morning and Codex in the afternoon, each one's memory is half the story. Context should live outside any one agent, where all of them can read it.
Treat retrieved text as untrusted
Anything read from a web page or a document can contain instructions aimed at the agent. A context server should mark what it returns as data, not commands.
Keep instruction files short
A CLAUDE.md that runs to pages gets skimmed by the model like it does by people. Rules, commands and pointers; not a diary.
Giving Claude Code context
- Write a short
CLAUDE.md(orAGENTS.md, which Codex and Cursor read too): how to build and test, conventions, what not to touch. - Connect an MCP server for what changes. With Cachejay, choose Connect AI Apps → Claude Code in the menu bar.
- Ask in plain words, with references the agent can resolve: “the error I just saw”, “what we decided on the call”, “continue the billing work”.
- Let it check: “did that fix work?” after you click through the change. If it can see your screen history, it can follow.
An example session
A Sentry error is open in the browser. In Claude Code, one line:
› fix the error in Sentry ⎿ cachejay · current_screen TypeError: Cannot read properties of undefined (reading 'amount') at applyDiscount (checkout/cart.ts:88), from /checkout with a 100% coupon. The discount line has no price when the total is zero. Fixing cart.ts and adding a test.
No stack trace was copied. The agent asked for the screen, got the error and the URL, and went to the right file. The same works for the call: “what did Priya want for upgrades?” calls search_memory and comes back with her words.
A checklist
- Instruction file under a page: build, test, conventions, no history.
- At least one MCP server that knows your recent work, not just the repo.
- The same context available to every agent you use.
- Retrieved text marked untrusted.
- Private apps and windows excluded from whatever captures your context.
Cachejay is one way to cover the last four: it keeps track of your screen, calls, projects and to-dos on your Mac and serves them over MCP to Claude Code, Codex, Cursor, Claude Desktop, Gemini CLI, Windsurf, VS Code and Zed on your Mac, and to ChatGPT and Claude on the web. How it works for agents.