Edit code with Cursor Agent and review the changes
Give Agent a tightly scoped task, send or queue instructions while it works, then review every changed file and roll back with a checkpoint if needed.
Before you start · 1. Put the working tree in a known state · 2. Write a scoped task in Agent
At a glance
Use one small edit to practice defining file scope, adding instructions, inspecting the diff and test output, then committing or rolling back. Review tracked and untracked files; use Agent's report as supporting information.
Workflow
Limit the task first
Give one small goal at a time, naming the file scope, the expected behavior and the parts that must not change, to keep the change surface small.
Control it while it runs
While Agent works, send additions that belong to the current task immediately to steer it, and queue only requests for a later task. If the direction is wrong, decide whether to stop.
Review and roll back afterward
Once the current task and the queue are both done, read each changed file and the terminal output. Use a checkpoint for a temporary rollback and Git to keep or undo work permanently.
Before you start
- A local project open in Cursor, with Agent available from the side pane via Cmd+I or Ctrl+I.
- This guide requires a Git-managed project for its review workflow whose working tree has no unrelated uncommitted changes before you start.
- The command your project uses to run tests, so you or Agent can run it in the terminal.
1. Put the working tree in a known state
Save unrelated changes through your existing version-control workflow, and inspect the working tree including untracked files. Confirm that those changes can be restored independently before starting this task; staging alone does not show that the working tree is empty. This makes the changes Agent produces easier to inspect on their own.
2. Write a scoped task in Agent
Open Agent with Cmd+I or Ctrl+I and enter the task. Include the file or function to change, the expected behavior, the files that must not change, and the tests to run afterward. Agent has file editing, codebase search and terminal tools, so saying exactly where to change is more reliable than saying "change as little as possible".
3. Tell "send now" from "queue" while it works
For a message typed while Agent works, Cmd+Enter or Ctrl+Enter sends it immediately, which suits additions or corrections to the current task. Enter adds it to the queue, where it waits until the current task finishes, which suits a separate follow-up task. Do not treat the current result as final until queued messages have been processed.
4. Review the changes file by file after everything is processed
First inspect the complete version-control state independently, including tracked modifications, deletions and untracked new files. Then review each actual change. Agent's report supports the review and is not its only file inventory. Wait until the current task and any queued messages are done, then list the changed files from Agent's report, open each one, and view the differences with Git in the terminal. Look for files outside the scope, deleted unrelated code, and edits to configuration or generated files. For anything you do not understand, ask Agent in the chat why it changed it.
5. Run the tests and read the output
Have Agent run the test command you supplied, or run it yourself, and read the full output rather than only a summary. If any follow-up edit happened, rerun after the last change. Agent can run terminal commands and monitor output, but the real output decides pass or fail. If something fails, paste the failure back and ask for a fix for that item only. After any follow-up fix, repeat the file inventory, diff review and tests before accepting the result.
6. Roll back or commit
Agent automatically creates checkpoints before significant changes. Click a checkpoint in the chat timeline to preview it, then restore to return the files to that state; this reverts files only and does not remove conversation messages. Checkpoints are local, separate from Git, and only for undoing Agent changes. Commit with Git once you are satisfied.
Original example
Synthetic example: a fictional bookkeeping helper where formatPrice in src/utils/price.ts returns an empty string when the amount is 0.
Before starting: confirm with Git that the working tree is clean.
Task given to Agent: "Change only formatPrice in src/utils/price.ts so that an amount of 0 returns "0.00"; add a matching case in src/utils/price.test.ts; do not touch any other file; then run the project's test command and show the output."
While it runs: after Agent starts editing, you want to add "negative amounts keep their current behavior". That belongs to the current edit, so press Cmd+Enter or Ctrl+Enter to send it immediately. Only if you were asking for a separate later task, such as "then add a doc comment to formatPrice", would you press Enter to queue it and wait for it to finish.
Review: once the current task and the queue are processed, the Git diff should show only those two files, the other branches of formatPrice should not be rewritten, and the test output should show the new case passing with negative-amount behavior unchanged. If package.json also appears in the diff, ask why first; if the reason is not sound, restore the checkpoint from before the edit and retry with a narrower instruction. This is an illustrative input, not a real run result.
Completion checks
- The working tree was clean (committed or stashed) at the start, so the diff holds only this Agent run.
- The current task and all queued messages were processed before you began reviewing.
- Every changed file lies inside the scope you set, with no extra configuration or generated files.
- No unrelated code was deleted or rewritten.
- The test output comes from a real run after the last change and the new case passes.
- You can explain each change in your own words; if not, keep asking.
- After any follow-up fix, repeat the file inventory, diff review and tests before accepting the result.
Limits
- Checkpoints are local and separate from Git; they are not permanent version control and do not delete conversation messages.
- The documentation says Agent has no limit on tool calls, so narrow changes come from your instructions and your review, not from Agent being automatically minimal.
- The documentation says /goal is rolling out, so you may not see it; this task does not use it.
- This covers one small change. For a larger feature or migration the documentation points to a Project with a coordinator agent, which is outside this guide.
Verification scope
Only Cursor's official Agent documentation was read. Login, installation, product API execution, file upload and generated output were not tested, and the task and results in the example are original illustrations. The documentation describes no dedicated diff viewer, so the diff check uses ordinary Git practice rather than a Cursor-documented step.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.