How do you stop coding agents from changing unrelated files?
by•
Whenever I let an AI coding assistant work on a specific bug, it almost always tries to refactor random files I never asked it to touch.
Lately I started adding a strict rule at the top of my instructions telling it to only modify the exact files mentioned in my prompt.
Honestly simple guardrails like this save me way more cleanup time than writing long prompts.
What is one strict rule you always keep in your AI setup to stop it from breaking things?
18 views
p/valentina-studio
p/termexo
p/meridian-16
p/runevr
p/mindpal-ai
p/many-displays
p/burnlink
p/classroomio
p/teaserkit
p/pushary
p/reso
p/producthunt
p/kodlo
p/dots-7
p/citable
p/neoagent
p/faraday-4
p/clipjack
p/temp-mail-370
Replies
Our version of this rule is about commits rather than edits, because we often have several agent sessions working in the same repo at once. Each session may only stage what it changed itself, by file name, and commit by path too. No "add everything", no bare commit. We learned the second half the hard way: one session ran a plain commit, which takes everything in the index, and shipped a rename and a deletion that another session had staged. Main didn't build until the next commit put them back. The rule also says never revert, stash or "clean up" a change you didn't make, and if a file has someone else's hunk in it, stage only your own hunks. It doesn't stop an agent from touching extra files, but it stops those touches from leaking into someone else's work.