Topic 3 of 5 · 4 min read
Giving IDE agents the right context
Goal: Choose which files, symbols, rules and docs to attach so an IDE agent answers from the right code.
An IDE agent can only answer from what is in its context window, so your job is to put the right files, symbols, rules and docs in it, and to know what is missing. Most "the AI ignored my code" problems are really missing context.
Check yourself · 1 of 3
An IDE agent invents a helper function that does not exist in your project. What is the most likely cause?
Why it matters
A model has no memory of your project. Each request is built from a bundle: your prompt, some open files, whatever you attached and whatever the tool retrieved from an index of the codebase. Retrieval is a search, and a search can miss. If the right file is not in the bundle, the model does what it always does: it guesses, and the guess looks like your style. It may call a helper that does not exist or re-implement one you already have.
How to do it
- Attach on purpose. Use the editor's mention syntax to add files, folders or symbols, for example
#filein Copilot Chat or@mentions in Cursor. Add the file you want changed, the type or interface it uses, and one similar existing example. - Close what is not relevant. Open tabs often count as context. A stale tab with old code can pull the answer the wrong way.
- Do not rely on the index alone. Codebase indexing finds likely matches by meaning. It can lag behind recent edits and skip files that are ignored, generated or too large. If a file matters, mention it.
- Put standing rules in a rules file. Instruction files (such as
.github/copilot-instructions.mdor Cursor rules) are included automatically. Keep them short: the build and test commands, naming rules, forbidden patterns, where things live. - Attach docs for anything new. For a library version the model may not know, give it the docs page or a short excerpt.
- Ask what it used. Many tools show the references used. If a key file is not listed, the answer is not based on it.
Before and after
Weak: "Add retry to the HTTP client." The agent writes a new retry loop with its own backoff.
Better:
Add retry to the HTTP client. Use the existing backoff() in
lib/retry.ts (attached) and follow how billing/client.ts (attached)
handles errors. Rules in .github/copilot-instructions.md apply.
What goes wrong
- Invented helpers. The agent calls
formatMoney()because it is a common name, not because it exists in your code. - Stale index. You renamed a module this morning; the agent still cites the old path.
- Context overload. Attaching twenty files buries the important one, and costs more. Pick the few that matter.
- Rules that drift. A rules file that names a script you removed sends every request toward a failing command.
Examples
Pointing at an example
You ask Copilot Chat: "Add a GET /teams/:id route. Follow routes/projects.ts (attached) for validation and error format." The new route reuses the same validateParams helper and error shape. Without the attachment it would have invented its own response format.
The stale rules file
Your rules file says "run make test", but the Makefile was replaced by npm run test last month. The agent keeps running the missing command, reports a failure and tries to "fix" the build. Updating one line in the rules file ends the loop.
Key points
- The agent answers from its context bundle, so a missing file means a guess, not an error.
- Attach the file to change, the types it uses and one similar existing example.
- Codebase indexing is a search that can lag or skip files, so mention the files that matter.
- Keep a short rules file with build and test commands and project conventions, and keep it current.
- Check which references the tool says it used before trusting an answer about your code.
Common mistakes
- Assuming the index always finds the right file and skipping explicit mentions.
- Leaving many unrelated tabs open while asking a focused question.
- Attaching a dozen files instead of the three that matter.
- Letting the rules file go out of date after the build or layout changes.
Check yourself · 2 of 3
You want the agent to follow how an existing route handles errors. What is the best step?
Check yourself · 3 of 3
What belongs in a short project rules file for an IDE agent?
Practice items, not counted towards your mastery.
Start here
- Build with AI in VS Code (opens in a new tab)DocsFree
An overview of inline suggestions, chat and agents in one editor, with the controls for each.
- Add context to chat (VS Code docs) (opens in a new tab)DocsFree
How to attach files, symbols and other context so the agent answers from the right code.
- Review AI code edits (VS Code docs) (opens in a new tab)DocsFree
Keep and undo controls, and what restoring a chat checkpoint does and does not undo.
More for this topic
- Custom instructions (VS Code docs) (opens in a new tab)DocsFree
Shows how to write instruction files that the agent loads automatically.