Use Cursor to review an unfamiliar file, find risky code and refactor it in small, tested steps you can check and undo.
Cursor is a code editor with an AI assistant built in. It can read the files you point it at, explain them, suggest changes and apply edits across several files. That makes it useful for two jobs developers often put off: reviewing code you did not write and cleaning up code that works but is hard to change.
The risk is that an assistant can rewrite a lot of code quickly, and a large, unreviewed change is exactly what a refactor should avoid. This tutorial shows a workflow that keeps you in control: review first, agree on a plan, then change one thing at a time with tests running between steps.
Cursor gives the model context from your project. You can attach specific files or folders to a chat, select a block of code and ask about it, or let it search the codebase. The quality of the answer depends heavily on that context. A question about "the billing code" with nothing attached gets a generic answer. The same question with billing/invoice.py and its test file attached gets a specific one.
There are two broad modes you will use:
Exact names of these modes change between versions, so look for the mode or model picker near the chat input.
Suppose you inherit a 300-line function called calculate_invoice that mixes tax rules, discounts and currency rounding. It has a handful of tests and a history of bugs. A good review prompt looks like this:
Review calculate_invoice in billing/invoice.py.
List: (1) what it does in plain language, (2) hidden side effects,
(3) edge cases the current tests in tests/test_invoice.py do not cover,
(4) the three highest-risk sections, with line references.
Do not suggest code yet.
Asking for no code yet keeps the first answer focused on understanding. Once you agree with the analysis, you ask for a refactor plan, then implement it step by step. Each step should leave the tests green and be small enough to read in under a minute.
Commit or stash your current work so every AI change shows up as a clean diff. Run the tests once and note which pass, so you know the baseline. If the project has a linter or type checker, keep it handy; it catches many of the mistakes that slip through a quick diff review.
Treat the model as a fast, well-read reviewer who has not worked on your project. It can miss business rules that only exist in people's heads, so you remain responsible for the final change.