Use an AI coding agent on an existing codebase without breaking it
Commit your work, make one small change at a time, and review every diff before you accept it.
An AI coding agent is a program that writes or edits code for you, and it can change files across your whole project in seconds. That speed helps, but it can also break code that works today. Use these steps to try its changes without losing anything.
Commit everything before you start
A commit is a save point in Git, the tool that tracks changes to your code. If the agent breaks something, you can go back to this exact moment.
- Open your terminal inside the project folder.
- Run
git statusto see which files have changes. - Run
git add .to stage all current work. - Run
git commit -m "Save point before AI agent changes". Reference: git commit
Ask for one small change at a time
Give the agent a single task, like fixing one function. Do not ask it to redesign the whole app at once. It is like asking a builder to repair one tap instead of rewiring the house.
- Open your AI coding agent chat.
- Point it to one file or folder.
- Ask for one change, for example: “Add a null check to the login function. Do not change anything else.”
- Wait for the agent to show proposed edits. Reference: Asking GitHub Copilot questions in your IDE
Review the diff before you accept
A diff shows what will be added (+) and removed (-). Treat it like checking a proofread essay before you hand it in.
- Open the diff view your agent displays.
- Read every file listed.
- Reject any change in a file you did not ask about.
- Accept only the edits you understand. Reference: git diff
Run your tests after every change
Tests check that the code still works. It is like turning on the lights after rewiring a room.
- Find your test command, such as
npm test,pytest, orgo test. - Run it after accepting the agent’s change.
- If a test fails, undo the agent’s edit with
git restore .. - Commit again only when tests pass. Reference: git restore
Expected result
You should see a clean list of commits, only the files you asked about changed, passing tests, and a single command that undoes anything the agent broke.
Sources
Stay Ahead. Work Smarter.
Get practical AI tips, automation ideas and useful technology tricks — one useful thing at a time. Follow the feed in any reader.