strategy-minimal-diff
Skill4 starsChanged 4 months agoMITView on GitHub
Make the smallest correct change to fix a bug or add behavior; never rewrite a whole file or module when a targeted edit suffices, and keep unrelated refactors out of the same change. Use when the user asks to fix a single bug or make a small change and does not want the surrounding file or module rewritten; the user wants only the requested change and no drive-by cleanups, reformatting, or unrelated refactors mixed into the same edit; the change can be expressed as a targeted, scoped edit to a few lines rather than a rewrite of the whole file or class. Keywords: strategy, minimal, diff, targeted, smallest, scoped, rewrite, rewriting, bug, edit.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- formsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 73
Do not enforce minimal diffs when the user has explicitly asked for a full rewrite, a redesign, or a large-scale rework of the file or …
- Distinctive: line 75
Do not apply this strategy when the user explicitly asks to create a new file or scaffold a greenfield module — there is no existing code …
- Distinctive: line 86
Do not reformat, re-order imports, or re-wrap lines you are not otherwise editing.
- Distinctive: line 94
Never rewrite or regenerate an entire file when a targeted edit to a few lines would satisfy the request.
- Distinctive: line 99
Prefer the smallest correct edit that satisfies the request, and match the surrounding code's style so the diff shows only the intended …
- Distinctive: line 104
Avoid drive-by refactors, import re-ordering, and reformatting of lines you are not otherwise changing.
- Distinctive: line 114
Read the relevant code and identify the smallest span of lines that must change to satisfy the request.
- Distinctive: line 150
Not applicable — no I/O, auth, or untrusted input.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/ai-rules/strategy-minimal-diff/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->Strategy — Minimal Diff Edits
When to use
- The user asks to fix a single bug or make a small change and does not want the surrounding file or module rewritten.
- The user wants only the requested change and no drive-by cleanups, reformatting, or unrelated refactors mixed into the same edit.
- The change can be expressed as a targeted, scoped edit to a few lines rather than a rewrite of the whole file or class.
When NOT to use
- Do not enforce minimal diffs when the user has explicitly asked for a full rewrite, a redesign, or a large-scale rework of the file or module.
- Do not apply this strategy when the user explicitly asks to create a new file or scaffold a greenfield module — there is no existing code to keep the diff small against.
Core guidance
- Defer unrelated cleanups to a separate change — When you notice unrelated improvements while making the change, note them for a follow-up instead of folding them into the current edit.
- Edit in place rather than rewriting the file — Prefer an in-place edit of the specific lines over rewriting or regenerating the whole file. Only rewrite a file when the change genuinely touches most of it.
- Match the surrounding style, do not reformat — Match the existing indentation, quote style, and naming of the surrounding code. Do not reformat, re-order imports, or re-wrap lines you are not otherwise editing.
- Read the diff and drop incidental changes — Before finishing, read the diff and remove any change that is not required by the request — stray blank lines, reordered members, or reformatted blocks.
- Scope the edit strictly to the request — Change only the lines needed to satisfy the request. If a line does not contribute to the fix or feature, leave it exactly as it is.
Never
- Never rewrite or regenerate an entire file when a targeted edit to a few lines would satisfy the request.
Prefer
- Prefer the smallest correct edit that satisfies the request, and match the surrounding code's style so the diff shows only the intended change.
Avoid
- Avoid drive-by refactors, import re-ordering, and reformatting of lines you are not otherwise changing; keep unrelated cleanups out of the diff.
Escalate to user when
- Escalate to the user when a correct fix appears to require a large rewrite or broad structural change, and confirm the wider scope before making it.
Quick recipe
- Read the relevant code and identify the smallest span of lines that must change to satisfy the request. (verify: The identified span is limited to what the request needs, with no adjacent code included.)
- Edit only those lines in place, matching the surrounding style, then read the resulting diff and remove any incidental change. (verify: The diff contains only the lines required by the request and no reformatting or unrelated edits.)
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Bundling a refactor into a bug fix | Mixing concerns makes the diff impossible to review cleanly and impossible to<br>revert without losing the fix. | Land the minimal fix first; propose the refactor as a distinct, separate change. |
| Rewriting a file to change one line | A full replacement forces a full re-review and risks reverting unrelated code<br>that already worked. | Apply a targeted edit to the specific lines and leave the rest byte-for-byte<br>unchanged. |
| Restyling untouched code to your preference | Style-only edits add noise, break blame, and can conflict with the project's<br>agreed conventions. | Follow the file's existing conventions and touch only the lines the request<br>requires. |
See references/anti-patterns.md.
Common mistakes
- Editor auto-formats the whole file — A format-on-save or auto-formatter rewrites the whole file, turning a one-line fix into a hundred-line diff. Fix: Disable format-on-save for the change, or reformat only the lines you edited, so the diff reflects only the intended fix.
- Regenerating a file silently drops detail — Rewriting a file from memory instead of editing it drops comments, edge-case handling, and formatting that were not part of the request. Fix: Edit the existing content in place; never regenerate a file you could have patched.
- Fixing nearby code you were not asked to touch — While making the requested change you "improve" adjacent code that was working fine, widening the diff and the blast radius. Fix: Change only what the request needs; record adjacent improvements as a separate follow-up.
Version notes
- Minimal-diff discipline is version-agnostic (PHP >=7.4) — This editing strategy applies to any PHP version; it constrains how the agent edits, not which language features it uses, so it holds from PHP 7.4 upward.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/ai-rules/strategy-minimal-diff.yaml.
Additional resources
- references/anti-patterns.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: ai-rules/strategy-bitrix-d7-incremental, ai-rules/strategy-explicit-over-magic, ai-rules/strategy-framework-conventions, ai-rules/strategy-legacy-safe-edits, ai-rules/strategy-no-untested-refactor, ai-rules/strategy-preserve-public-api, ai-rules/strategy-readonly-immutability, ai-rules/strategy-security-first, ai-rules/strategy-test-driven
<!-- graph-fragment: graph/fragments/ai-rules/strategy-minimal-diff.yaml -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

