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

Ways to give an AI agent context
WayGood forFalls short on
Instruction files (CLAUDE.md, AGENTS.md, .cursor/rules)Stable rules: how to build, test, name thingsAnything that changes; they go stale
Pasting into the chatOne-off facts the agent can’t reachYour time, and the context window
The agent’s own memoryPreferences you told that agentWork in other apps, calls, other agents
Tools over MCPHistory, decisions, live state, open work, looked up on demandNeeds 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

  1. Write a short CLAUDE.md (or AGENTS.md, which Codex and Cursor read too): how to build and test, conventions, what not to touch.
  2. Connect an MCP server for what changes. With Cachejay, choose Connect AI Apps → Claude Code in the menu bar.
  3. 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”.
  4. 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.

Questions

What is context engineering for agents?

Deciding what an AI agent knows when it starts a task, and how it gets the rest while it works: instruction files, the files it reads, and tools it can call for history and live state.

How do I give Claude Code more context?

Put stable rules in CLAUDE.md or AGENTS.md, keep them short, and connect MCP servers for what changes: your recent work, calls, tickets. Then ask in plain words and let Claude call the tools.

Should I paste more into the prompt?

Usually not. Long pasted context crowds the window and goes stale. Give the agent a way to look things up, and paste only what it can’t reach.

What is AI agent memory?

Anything that carries context from one session to the next: instruction files, an agent’s own memory feature, or a memory server the agent queries over MCP.

Stop explaining your day to ChatGPT

Install it, connect the apps you use, and get on with your work. Free for 14 days, no card.