# Diff From Before and After: A Patch That Applies Exactly

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.

- Page: https://aiskills402.com/skills/diff-from-before-after
- Category: Code & Engineering (https://aiskills402.com/categories/code)
- Price: $0.01 once, USD-priced, paid in USDC on Base over x402. Price as loaded on this page. The 402 response your agent receives is authoritative.
- Version: 1.0.0
- Card (JSON): https://api.aiskills402.com/v1/skills/diff-from-before-after

## Use it when

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.

## 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.

- Strong model (claude-sonnet-5-5 (Claude Code alias "sonnet")): 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.
- Weak model (claude-haiku-5-5 (Claude Code alias "haiku")): Right on all 22 testable file pairs, read by hand, with diffs that applied.

Note: Twenty-four pairs of before and after files written by us (17 with a trap, 7 plain): tabs in a Makefile, blank context lines, a final newline added or removed, trailing spaces, new and emptied files, Windows line endings and a planted instruction. Each answer is applied to the before file by our patch code and must produce the after file exactly; counts use the verdicts recorded at run time, because re-reading a stored diff loses a trailing blank line. The two Windows cases failed for both models on both sides and are left out of the counts: we suspect the carriage returns are lost on the way to the model. No check was widened. One run per model and pair.

### With and without the skill

Tested 2026-10-08.

- Diffs that apply (22 testable pairs): Sonnet 21/22 with, 22/22 without; Haiku 22/22 with, 21/22 without.

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.

Full summary: https://aiskills402.com/skills/diff-from-before-after/tests

## Example

### 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

## How to buy

Agent (HTTP):

1. GET https://api.aiskills402.com/v1/skills/diff-from-before-after/file without a payment header. The answer is 402 with a PAYMENT-REQUIRED header (x402 v2): exact amount, asset, network, recipient.
2. Sign `accepts[0]` with an x402 client (for example @x402/core + @x402/evm).
3. Repeat the GET with the signature in the PAYMENT-SIGNATURE header. The answer is 200 with the file, its sha256 and a re-download token.

Agent (MCP): https://mcp.aiskills402.com/mcp — free tools search_skills, get_skill, redownload_skill. Buying itself is over HTTP.

Full flow: https://aiskills402.com/docs

## The file

- Version: 1.0.0
- Size: 9.4 KB (9639 bytes)
- SHA-256: e517a0b3d84a41b79cb0c6898e082fd2b25921c8b6066de8732e3d3305492e34
- Updated: 2026-10-08
- New versions are free through your re-download token.

## Versions

### 1.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.

## License

Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Terms: https://aiskills402.com/docs#license

## 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.

## Related skills

- [Unified Diff Repair: Fix the Counts, Keep the Change](https://aiskills402.com/skills/unified-diff-repair.md): $0.02 once
- [Code Review](https://aiskills402.com/skills/code-review.md): $0.01 once

## Measurement limits

- Models other than the two named above were not run.
- Each verdict comes from the test run on the date shown; the skill may have changed since (check the version).
- Full test inputs are not published here, only short excerpts of our own text.
- Results on your own texts, languages and domains can differ.

Offer note: Paid in USDC (USD-pegged) over x402 by an AI agent; one-time.
