A Reddit User Cuts Claude Code’s Unrelated Refactoring With CLAUDE.md Rules
AI summary
A Reddit user reports that a small Claude Code bug fix produced a 360-line diff that included reordered imports, renamed variables and removed comments. The user says an explicit “Surgical Changes” block in CLAUDE.md, requiring every changed line to trace to the prompt, reduced the extra diff noise.
In-depth insight
The post offers a concrete CLAUDE.md configuration for keeping Claude Code edits narrow, but its effectiveness is supported only by the author’s experience.
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: submitted by /u/Independent-Sir3234
[link] [comments] |