How to stop Claude Code from reformatting 300 unrelated lines when you ask for a 3-line bug fix
One of the most common annoyances when running Claude Code on an existing repository is drive-by refactoring. You ask it to fix an off-by-one check in a single function, and the resulting git diff touches 360 lines because it decided to reorder imports, rename helper variables, and strip comments across the file. Adding vague instructions like "keep changes minimal" to CLAUDE.md rarely stops this, because the model still considers formatting and cleanup to be helpful improvements. What actually stopped the extra diff noise for us was adding an explicit Surgical Changes block to CLAUDE.md (adapted from Andrej Karpathy's coding agent guidelines) that defines exact boundaries for git diff : # Surgical Changes - Touch only the lines required to solve the requested task. - Do not reformat, reorder imports, or rename unrelated variables in files you are editing. - Do not delete existing comments or dead code unless asked; mention them in your final summary instead. - Only clean up unused imports or helpers that your own edit made unused. - Every changed line in git diff must trace directly to the user's prompt. Two rules in that block do almost all the work: Telling Claude to report dead code or formatting issues in its final summary gives the model a safe outlet for its helpfulness instinct without letting it mutate the file. Distinguishing between pre-existing unused imports (leave alone) and imports that Claude's own edit orphaned (clean up) prevents broken linter runs while keeping PR diffs small enough to review in ten seconds.