Apply AI code changes with a diff preview
Apply turns the code in a DEVUP AI reply into a diff against your file, so you see the change before it happens. Your file stays as it is until you click Accept; Reject drops the proposal, and Undo takes an accepted change back.
Ways to use the code in a reply
The code in a DEVUP AI reply can reach your editor in different ways. Pick the one that fits the change.
Apply
Shows the proposed change as a diff first. Accept applies it, Reject discards it, and Undo reverts it afterwards.
Insert
Puts the code at your cursor, or in place of the code you selected, as a single edit you can undo.
New file
Opens the code in a new editor that has not been saved yet.
Compare
Insert, Apply and New file side by side
| Action | What it does | When to use it | How to undo it |
|---|---|---|---|
| Insert | Writes the block where the cursor sits, or over the text you have selected, in one edit. | A short snippet that belongs exactly where you are typing. | A single Undo in the editor removes the whole insertion. |
| Apply | Opens a diff between your file and the proposed code. The file changes only when you accept. | Edits to lines you asked about, or to a whole file, that you want to read before they land. | Reject before accepting; Undo once accepted. |
| New file | Puts the block in a fresh editor tab that has never been saved. | A module, script or test file that does not exist in the project yet. | Close the tab without saving it. |
How to apply a change with a diff preview
- Ask DEVUP AI for the change in the chat. To give it the code to work on, attach the file or a selection.
- When the reply is done, choose Apply on its code block.
- Read the diff. It opens beside the editor or in the same tab, as the
devupai.editor.applyDiffsetting says, and your file is left untouched while you look. - Choose Accept to apply the change, or Reject to discard it. The commands DEVUP AI: Accept Change and DEVUP AI: Reject Change in the Command Palette do the same. They have no default keys; you can assign your own in Keyboard Shortcuts.
- Changed your mind after accepting? Use Undo to revert the change.
Targets
What Apply replaces
The label on the button tells you, before you click, whether the code replaces a selection, a whole file, or a file you pick from a list. It depends on what your message carried and on the files you can see:
- Apply to selection: your message held one selection, for example from the right-click menu, and the code replaces those lines.
- Apply to file: your message held one attached file and no selection, or your attachments and the visible editors come to a single file, and the code replaces that whole file.
- Apply to…: there is more than one candidate, so a short list of your attachments and the files visible in the editor lets you choose.
Whichever label shows, the change opens as a diff, and nothing is written before Accept.
Walkthrough
How it works in practice: tightening one function
Say a saveUser function stores an email without checking it, and you want that fixed without touching anything else in the file.
- Select the function, right-click inside the selection and choose DEVUP AI → Ask DEVUP AI. The selected lines go into the chat as an attachment.
- Describe the change in your own words, for example "reject an empty email before saving", and send it.
- When the reply has finished, its code block offers Apply to selection, because your message carried one selection.
- Choose it. With
devupai.editor.applyDiffat its default,beside, the diff opens next to your code, and the file itself stays exactly as it was. - Go through every changed line, then choose Accept in the notification or in the diff's title bar.
- Run your tests. If the result is not what you wanted, Undo takes the change back. When you are happy with it, save the file yourself: DEVUP AI leaves saving to you.
Use cases
When to reach for Apply, Insert or New file
Reviewing a multi-line refactor before accepting it. A reply that reshapes a loop, renames variables and moves an early return touches many lines at once. Apply lays every one of them out in a diff, so you can check each before anything changes, and Reject leaves the file as it was.
Rewriting a configuration file. Attach only that file and ask for the updated version. The button then reads Apply to file, and the diff covers the entire file, removed lines included, before you decide.
Choosing between open files. When a message carried several files and no selection, Apply to… asks which one the code is for, listing your attachments next to the files on screen.
Dropping a small helper where you are typing. For a snippet you plan to adjust by hand, Insert is quicker: it lands at the cursor in one step, and one Undo removes it again.
Starting a new test or script. New file opens the code in a fresh editor set to the language named on the code block, and you pick the folder and name when you save.
Tips
Tips for reviewing changes
- Edited the file while its diff was still open? Accept then writes nothing and asks you to choose Apply again; if the selected lines themselves changed, it offers Apply to file instead. An older proposal never lands on newer work.
- Only one proposal waits at a time. Choosing Apply on another code block closes the earlier diff, and nothing from it is written.
- Prefer to review in place? Set
devupai.editor.applyDifftosameand the diff opens in the tab you are in. - Turn
devupai.editor.codeBlockActionsoff if you would rather copy code by hand; it removes the Insert, Apply and New file buttons from code blocks.
For every option in one place, read editor actions and code from replies in the docs, or see the right-click actions that bring code into the chat.
Protection
What keeps your files safe
- With Apply, nothing is written to your file until you choose Accept.
- DEVUP AI never changes a file that may contain secrets:
.envfiles, private keys, certificates and anything inside SSH or Git folders. - When the workspace is in Restricted Mode, DEVUP AI writes to no file, though chatting and reading your attachments keep working.
More on this in Security in DEVUP Code.
FAQ
Questions and answers
No. Apply first opens the change as a diff, and your file stays as it was until you choose Accept. Reject discards the proposal instead.
Yes. After you accept, Undo reverts the change.
Insert puts the code at your cursor, or in place of your selection, as one edit you can undo. Apply shows the change as a diff first and writes nothing until you accept it.
That depends on what your message carried, and the button says which. Apply to selection replaces the one selection you sent. Apply to file replaces a whole file when you sent one file and no selection, or when your attachments and the visible editors come to a single file. Apply to… lets you pick the file.
No. Accept puts the change into the file open in your editor, and saving stays in your hands, as with any edit you type yourself.
Accept then writes nothing. DEVUP AI asks you to choose Apply again, so the new diff starts from the file as it is now. When you used Apply to selection and those lines changed, it offers to apply the code to the whole file instead.
No. DEVUP AI never edits .env files, private keys, certificates or files in SSH and Git folders, because they may hold secrets. In Restricted Mode it doesn't write to files at all.
Related
Start coding with DEVUP Code
Create your DEVUP AI account, then sign in from the editor.