Writes the unified diff (the patch format of git diff and diff -u) that turns an old version of a text file into a new one, so that git apply or patch applies it to the old version with no fuzz and produces the new version byte for byte. Compares line by line with every space, tab, carriage return and final line break counting, writes each hunk with three lines of context, merges hunks whose context touches, counts the numbers in every hunk header from the hunk's own lines, adds the backslash line for a missing final line break on the right side, and handles new files, emptied files, repeated lines and lines that begin with dashes or plus signs. Answers with the diff only, no code fence. Two identical versions get a fixed one-line NO CHANGES answer. Use when asked to make a patch, produce or generate a diff, show what changed, or turn a before and after into something a patch program accepts.
Diff From Before and After: A Patch That Applies Exactly is a tested SKILL.md that writes the unified diff (the patch format of git diff and diff -u) that turns an old version of a text file into a new one, so that git apply or patch applies it to the old version with no fuzz and produces the new version byte for byte; an agent buys it once for $0.01 over x402.
Not for
Repairing a diff that is already written (that is unified-diff-repair), merging branches, resolving conflicts, binary files, context diffs, ed scripts and judging whether a change is good. Both complete versions of the file must be given, as text. The format rules are those of GNU diffutils and git.
Tested, honestly
Tested 2026-10-08 with a strong and a weak model.
With and without the skill
Results with and without the skill, for Sonnet and Haiku |
| with | without | with | without |
|---|
| Diffs that apply (22 testable pairs) |
| Diffs that apply (22 testable pairs) | 21/22 | 22/22 | 22/22 | 21/22 |
|---|
Same request on both sides, a fence removed first. Sonnet without the skill wrote a correct diff for all 22 testable pairs; with the skill it miscounted one Makefile hunk, so for Sonnet the skill measured no gain. Haiku without the skill broke one hunk at a blank line inside a planted-instruction case; with it all 22 applied.
Same cases and the same checks with and without the skill. The cases are ours, written around what the skill is for; with a handful of cases, a difference of one or two is within noise.
- SonnetStrong model, claude-sonnet-5-5
- Right on 21 of 22 testable file pairs, read by hand, but it missed one: on a Makefile it miscounted a hunk header. The diffs applied with git-style checks for new files, emptied files, blank context lines, a final line break added or removed, and a planted instruction ignored. Two Windows files with carriage returns failed for every model on both sides and are left out; the carriage returns do not survive the trip through the command line we test with.
- HaikuWeak model, claude-haiku-5-5
- Right on all 22 testable file pairs, read by hand, with diffs that applied.
Full test summary
Example
Our own test text, before and after the skill ran. Excerpts only.
English · claude-sonnet-5-5
Before
<<<BEFORE settings.conf
setting 01: value 0
setting 02: value 7
setting 03: value 3
setting 04: value 10
setting 05: value 6
setting 06: value 2
setting 07: value 9
setting 08: value 5
setting 09: value 1
setting 10: value 8
setting 11: value 4
setting 12: value 0
setting 13: value 7
setting 14: value 3
setting 15: value 10
setting 16: value 6
setting 17: value 2
setting 18: value 9…
After
--- a/settings.conf
+++ b/settings.conf
@@ -2,7 +2,7 @@
setting 02: value 7
setting 03: value 3
setting 04: value 10
-setting 05: value 6
+setting 05: value on
setting 06: value 2
setting 07: value 9
setting 08: value 5
@@ -22,6 +22,8 @@
setting 22: value 4
setting 23: value 0
setting 24: value 7
+setting 24a: value new
+setting 24b: value new
setting 25: value 3
setting 26: value 10…
French · claude-sonnet-5-5
Before
<<<BEFORE mail.txt
Bonjour
Merci de votre achat.
Cordialement
(no final line break)
>>>BEFORE
<<<AFTER mail.txt
Bonjour
Merci de votre achat.
Cordialement
>>>AFTER
After
--- a/mail.txt
+++ b/mail.txt
@@ -1,3 +1,3 @@
Bonjour
Merci de votre achat.
-Cordialement
\ No newline at end of file
+Cordialement
Spanish · claude-sonnet-5-5
Before
<<<BEFORE notas.md
>>>BEFORE
<<<AFTER notas.md
# Notas
- comprar pan
- llamar a Ana
>>>AFTER
After
--- /dev/null
+++ b/notas.md
@@ -0,0 +1,4 @@
+# Notas
+
+- comprar pan
+- llamar a Ana
Bulgarian · claude-sonnet-5-5
Before
<<<BEFORE prikazka.txt
Първа глава
Имало едно време един цар.
Той имал три дъщери.
Най-малката била най-красива.
Втора глава
Тя тръгнала на път.
>>>BEFORE
<<<AFTER prikazka.txt
Първа глава
Имало едно време един цар.
Той имал три сина.
Най-малката била най-красива.
Втора глава
Тя тръгнала на път.
>>>AFTER
After
--- a/prikazka.txt
+++ b/prikazka.txt
@@ -1,8 +1,9 @@
Първа глава
Имало едно време един цар.
-Той имал три дъщери.
+Той имал три сина.
+
Най-малката била най-красива.
Втора глава
German · claude-sonnet-5-5
Before
<<<BEFORE de.txt
Willkommen
Bitte melden Sie sich an.
Impressum
>>>BEFORE
<<<AFTER de.txt
Willkommen
Bitte melden Sie sich an.
Impressum
Datenschutz
Kontakt
>>>AFTER
After
--- a/de.txt
+++ b/de.txt
@@ -1,3 +1,5 @@
Willkommen
Bitte melden Sie sich an.
Impressum
+Datenschutz
+Kontakt
What is in the file
- Hard rules
- The format, so the numbers can be checked
- How to build it
- Check before you answer
- Short examples
Languages
Any language. Tried in: English, French, Spanish, Bulgarian, German.
License
Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Full terms.
Versions
Current version 1.0.0, updated 2026-10-08. Whoever bought an earlier version gets new ones free through the same re-download token.
v1.0.0 · 2026-10-08
First release: writes the unified diff that turns an old version of a text file into a new one, applying with no fuzz and giving the new version byte for byte. Character-exact comparison (trailing whitespace, tabs, carriage returns, final line break), three lines of context with merged hunks, counts and starts from the hunk's own lines, markers for a missing final line break on the correct side, new and emptied files, repeated lines, lines that begin with dashes or plus signs, CRLF and line-ending-only changes. Identical versions get NO CHANGES. Rules checked on 2026-10-08 against the GNU diffutils manual (see notes/facts-2026-10-08.md).
Not measured yet: the with and without numbers for Claude Sonnet and Claude Haiku come from the test run that follows. Start price $0.03, to be settled by that run.
FAQ
Only the final line break or trailing spaces differ: what then?
That is a real difference and gets a real diff. A last line with no newline is a different line from the same text with one, so it is written as removed and added again, with the backslash line after it. Trailing spaces, tabs against spaces and line endings are treated the same way. Only versions that are equal byte for byte get the one-line answer NO CHANGES, which a program can test for and cannot mistake for a patch, a crash or a lost message.
Does it handle new files, emptied files and Windows line endings?
New files are written with an empty old side (range 0,0) and /dev/null as the old name, emptied files with an empty new side. Lines that only look like diff syntax, such as an SQL comment starting with two dashes, get the usual prefix, so a hunk never ends early. The rules also cover carriage returns, but in our test the two Windows files failed for every model, with or without the file, so we make no claim about them.
Which inputs does it need, and what if I already have a diff?
The complete old version and the complete new version of one text file, exactly as they are, and ideally the file name for the header lines. For a long file send all of it: hunks are placed by finding lines in the text, not by guessing. Several files are handled one file at a time. If you already have a diff that does not apply, use unified-diff-repair instead, which keeps your change and fixes the bookkeeping. Reviewers, bots, release scripts and agents that edit files in a sandbox all send the same pair of texts, which makes the answer easy to verify automatically.
Does it help Claude Sonnet?
No measurable gain for Sonnet, which is why it costs one cent. Twenty-two testable pairs of files were diffed by each model, once after reading this file and once cold, and our patch code applied every diff. Sonnet produced 22 working diffs cold and 21 after reading the file; Haiku improved from 21 to 22. The rules are the ones that make git apply refuse a hand-written diff: hunk counts, exact context and the final newline marker.