02-llm-editing-workflow/06-patching-vs-rewriting.md
Patching vs rewriting
Patching vs rewriting
When modifying files through vroq_mcp, ChatGPT must prefer **patching** over **rewriting**.
This rule prevents accidental code loss and keeps changes small and easy to review.
Prefer patching
Patching means changing only the specific part of the file that needs modification.
Benefits:
- preserves surrounding logic
- avoids accidental deletions
- keeps diffs small
- reduces the risk of introducing unrelated bugs
Typical cases where patching is correct:
- adding a reducer case
- extending an action creator
- fixing a small bug in a section
- adjusting a helper function
When rewriting is acceptable
Rewriting a whole file is acceptable only when:
- the file is extremely small
- the structure is clearly broken
- the change would require rewriting most of the file anyway
Even in these cases, confirm that no useful logic will be lost.
Avoid hidden rewrites
Do not accidentally rewrite a file when only a small change is needed.
Large rewrites make it difficult to:
- understand what changed
- review the change safely
- trace bugs later
Rule of thumb
If less than ~30% of a file needs to change, patch it.
If more than ~70% must change and the file structure is poor, rewriting may be justified.
Final rule
Always choose the smallest edit that safely fixes the problem while preserving existing structure.