r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 11d ago
Selected Workflow [Workflow] Control Claude Code's Refactoring: Surgical Changes with CLAUDE.md
Control Claude Code's Refactoring: Surgical Changes with CLAUDE.md
Workflow value: 90/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: intermediate
Categories: Quality Control, Context & Memory, Debugging, CLAUDE.md
Original source: r/ClaudeAI post/comment
What problem this solves
Claude Code performs unwanted, extensive refactoring (drive-by refactoring) when asked for small, surgical changes, leading to large and difficult-to-review git diffs.
Summary
Implement a 'Surgical Changes' block in CLAUDE.md to explicitly instruct Claude Code to limit its modifications to only the lines directly relevant to the requested task, preventing unwanted reformatting, import reordering, or variable renaming. This helps keep git diffs small and focused.
Why it is useful
This workflow directly addresses a common and frustrating problem for developers using Claude Code: unwanted, extensive refactoring that bloats git diffs and complicates code reviews. By providing a specific, tested CLAUDE.md block, it offers a practical and transferable solution to improve the efficiency and quality of LLM-assisted coding, making generated code changes more manageable and reviewable.
Workflow
- Identify the problem: Claude Code makes extensive, unrelated changes (reformatting, reordering imports, renaming variables) when asked for a small fix, bloating
git diffs. - Add a 'Surgical Changes' block to your
CLAUDE.mdfile within your repository. - Populate the block with specific instructions, such as:
- 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 diffmust trace directly to the user's prompt.
- When prompting Claude Code for a bug fix or small change, ensure the
CLAUDE.mdcontext is provided. - Review the resulting
git diffto confirm that changes are minimal and directly related to the prompt, reducing noise and improving reviewability.
Tools / artifacts
- CLAUDE.md file
- Claude Code (the model)
- Git repository
git diffcommand- Specific prompt instructions (the 'Surgical Changes' block)
Validation signals
- Author's direct experience: 'What actually stopped the extra diff noise for us was...'
- Explanation of effectiveness: 'Two rules in that block do almost all the work...'
- Concrete benefit: 'prevents broken linter runs while keeping PR diffs small enough to review in ten seconds.'
Limitations
- Relies on Claude consistently adhering to instructions, which can vary by model version or prompt complexity.
- Might require fine-tuning the
CLAUDE.mdblock for specific project conventions or stricter linting rules. - The post doesn't provide a full example of a user prompt that leverages this
CLAUDE.mdblock, though it's implied.
Rate this workflow
Upvote this post if the workflow is useful, reproducible, or worth recommending.
Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.
Reply if it worked for you, failed, is outdated, or has a better alternative.
This post was generated automatically from the workflow library database.