How to Stop Your AI Agent From Making Unwanted Code Changes

Published: (December 11, 2025 at 05:53 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Cover image for How to Stop Your AI Agent From Making Unwanted Code Changes

AI agents often behave like brilliant but overly enthusiastic interns — eager to help, but sometimes too eager. Even with clear instructions, they’ll occasionally decide, “Let me fix this other thing too…” and suddenly your codebase contains changes you never asked for.

This happens because modern LLMs are trained to be helpful. In software projects, “extra helpful” can quickly turn into chaos. A tiny, unintended edit can be hidden inside dozens of modified files. Reviewing that manually through git diff is painful, and asking the agent to revert it is even worse — it doesn’t remember your file state, only the conversation.

The solution isn’t complicated. It’s classic engineering discipline: version control. We already commit early and often, so why not enforce the same rules on our AI agents? Below is a workflow that uses goose to guarantee clean snapshots and easy rollbacks.

1. Set Up Version Control

  • Use GitHub.
  • The GitHub CLI (gh) works well because goose interacts with it perfectly.
  • The GitHub MCP Server is a solid alternative if that fits your workflow better.

2. Always Branch First

Never let an agent work directly on main.
Start on a feature branch so the agent’s changes remain isolated and reversible.

3. Add Rules in a Context File

Here’s the real game‑changer. In a .goosehints or AGENTS.md file, include this line:

Every time you make a change, make a commit with a clear message.

This single rule transforms the entire collaboration:

  • It forces automatic checkpointing.
  • It creates a perfect chronological trail of the agent’s decisions.
  • It turns your git history into an instant undo system.

No more manually hunting for hidden edits.

4. Work With Confidence

Once the rule is in place, let the agent build, refactor, or fix freely.
If it goes off track, all you need is:

git log          # inspect its steps
git diff         # review changes
# or simply:
git revert       # “Revert to commit abc123.”

Your workflow becomes transparent and reversible.

The Result

By applying one simple habit — frequent commits — you eliminate anxiety from AI‑assisted development. The agent remains helpful, but you stay in control.

  • No more digging through dozens of files for a rogue change.
  • No more hoping the agent “remembers” what it did.
  • No more surprise edits hiding in your repo.

Just clean commits, clear history, and total confidence. Try goose on your next project—your future self (and your git history) will thank you.

Thumbnail credit: https://petesena.medium.com/

Back to Blog

Related posts

Read more »