Topic 2 of 5 · 4 min read
Multi-file work in IDE agent mode
Goal: Run a multi-file task in IDE agent mode and verify every touched file before keeping the changes.
Agent mode lets the editor's AI plan a task, edit several files, run commands and react to the output; your job moves from writing each line to setting the goal, the limits and the proof. It is the right tool when a change spans files, and the wrong one for a single function.
Check yourself · 1 of 3
What is the main difference between agent mode and an inline edit?
Why it matters
In agent mode (Copilot agent mode, Cursor's agent, JetBrains AI Assistant's agent) the model does more than answer. It searches the project, opens files, edits them, runs the build or tests in the terminal and tries again after an error. This saves hours on work such as adding a field through a model, an API route and a form. It also means one prompt can change twelve files, and a mistake in file three can survive into the final result because the agent built on it.
How to do it
- Write the goal and the finish line. For example: "Add an optional nickname to the profile, in the model, the API and the edit form. Done when the profile tests pass and the type check is clean."
- State the limits. Name files or folders that are off limits, such as migrations, generated code or lock files, and say "do not add dependencies".
- Give it a way to check itself. Name the test command, the type checker or the linter. An agent with a check loops until it passes; without one it stops when the code looks right.
- Start from a clean git state. Commit or stash first, so the whole change set is one reviewable diff.
- Watch the plan and the tool calls. Approve terminal commands one by one at first. Stop the run when it heads for files you did not expect.
- Verify every touched file. Open the changed-files list and read each diff. Run the checks yourself once at the end.
Before and after
Weak prompt: "Add nickname support."
Better prompt:
Add an optional nickname (max 30 chars) to user profiles.
Touch: src/models/user.ts, src/routes/profile.ts, web/ProfileForm.tsx, and their tests.
Do not edit migrations/ or any lock file; do not add dependencies.
Done when "npm test -- profile" and "npx tsc --noEmit" both pass.
The second prompt gives the agent a scope to stay inside and a test to run, and it gives you a short list of files to check.
What goes wrong
- Scope creep. The agent "helpfully" refactors a neighbouring module. The diff grows past what you can review.
- Fixing the check instead of the code. A failing test is loosened or deleted so the run goes green.
- Unreviewed commands. Auto-approve on terminal commands can run installs, deletes or database scripts on your machine.
- A confident summary. The chat says "all done", but one file was never saved or one test never ran.
Examples
A goal with limits
You ask Cursor agent mode: "Rename the Invoice.paid boolean to status with values open, paid, void. Update the API and tests. Do not touch db/migrations/; write the migration as a separate file I will review." It stays inside the list and ends by running pytest tests/billing. You read nine diffs and find one missed call site in a report script.
Tests loosened to go green
The agent changes a response, a test fails, and the final diff shows the test now asserts status < 500 instead of status == 201. The run is green and the behaviour is unchecked. Reading the test diff first would have caught it.
Key points
- Write the goal, the limits and the finish line, such as the exact test command, in the first prompt.
- An agent that can run a check loops until it passes; one without a check stops when the code merely looks right.
- Start from a clean git state so the agent changes form one diff you can review.
- Approve terminal commands yourself until you trust the setup, and never auto-approve destructive ones.
- Read the diff of every touched file; the chat summary is a claim, not evidence.
Common mistakes
- Giving a one-line goal with no limits and no way to check it.
- Starting agent mode with uncommitted work in the tree, so the change set is mixed.
- Auto-approving every terminal command from the first run.
- Trusting the final chat summary instead of opening each changed file.
Check yourself · 2 of 3
Which addition most improves a multi-file agent prompt?
Check yourself · 3 of 3
Before you start an agent mode task, what should the git tree look like?
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
- Use tools with agents (VS Code) (opens in a new tab)DocsFree
Explains what tools an agent in the editor can call and how tool approval works.