Sub topic 9
Reviewing, accepting, and undoing changes
This chapter assumes you can use Git (diffs, commits, branches), you have run an agent task in VS Code, and you know the agent loop from earlier chapters. The agent edits files directly in your workspace, so reviewing its work is your main safeguard.
Where edits appear
In VS Code, the agent writes its edits into your open files right away. They are pending until you decide on them. The editor marks each changed region with a diff, and the Chat view lists every file the agent touched. Pending edits are not committed and not final. Treat them as a proposal.
Other editors differ in the details, but most follow the same pattern: changes are applied, shown as a diff, and held until you accept or reject them.
The review loop
Review in this order:
- Read the agent's summary in the chat. It tells you what it believes it did.
- Open the list of changed files and check that the set is what you expected. An unexpected file is the first warning sign.
- Step through each diff. Look for changes you did not ask for, such as reformatting, renamed symbols, or removed comments.
- Run the tests and the build yourself, even if the agent says it ran them.
- Accept or reject.
Accepting and rejecting
You can decide at three levels:
- Single change: accept or discard one changed region (a hunk) inside a file.
- One file: keep or discard all pending edits in that file.
- Everything: keep or discard all edits from the current request.
Fine-grained review costs time but catches problems. A large edit that passes tests can still hide a deleted check or a loosened condition. Reject the hunk and say why in your next message, so the agent does not repeat it.
Undoing changes
You have several undo tools. They work at different scopes, so choose by how much you need to roll back.
| Tool | Scope | Best for |
|---|---|---|
| Reject or discard pending edit | One hunk, file, or request | Edits you have not accepted yet |
| Editor undo (Ctrl+Z / Cmd+Z) | One file's edit history | Small fixes in an open file |
| Chat checkpoint or request rollback | Everything after a chat request | Returning to the state before a prompt |
| `git restore` or `git checkout` | Files in your working tree | Discarding accepted but uncommitted edits |
| `git revert` or `git reset` | Commits | Removing work you already committed |
Checkpoint features vary by editor and version. Do not rely on them as your only safety net. Edits made by terminal commands, such as generated files or package installs, may not be covered by an editor-level undo.
Use Git as the real checkpoint
Commit or stash your own work before you start a task. Then the diff you see afterwards belongs only to the agent. A clean starting point also makes recovery simple.
git status # confirm the tree is clean before the task
git switch -c agent/add-validation
# ... run the agent task ...
git diff --stat # see which files changed and how much
git diff # read the full diff
git restore . # discard all uncommitted tracked-file changes
git clean -n # preview untracked files the agent createdgit restore . does not remove new files. Run git clean -n to preview them. Delete them with git clean -f only after you have read the list.
Common errors
- Accepting without reading. Passing tests do not prove the edit is right. Read the diff.
- Mixing your edits with pending ones. If you type in a file while the agent has pending edits, it is harder to tell whose change is whose. Resolve pending edits first.
- Forgetting untracked files. New files the agent created do not show up in
git diff. Checkgit status. - Large, unfocused requests. A request that touches 20 files is hard to review. Split it into smaller tasks and commit after each one.
Exercise
You ran an agent task on a clean branch. You accepted all edits, and then found the agent also created two new files you do not want, besides changing a function you want to keep. Which Git commands would you use to discard the unwanted changes safely?
Show answer
Run git status to list the changes, then git clean -n to preview the untracked files. Delete them with git clean -f once the list looks right. If the function change is also unwanted, run git restore <file> on it. If you only want to keep the function change, restore nothing else, and commit it. A branch with a clean starting point makes this safe, because everything in the diff came from the agent.