Code & Engineering

Diff From Before and After: A Patch That Applies Exactly

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

Tested 2026-10-08No code, no hidden instructionsv1.0.0 · 9.4 KB · perpetual license

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
SonnetHaiku
withwithoutwithwithout
Diffs that apply (22 testable pairs)21/2222/2222/2221/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.

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

Read more

Share

Read this page as Markdown: /skills/diff-from-before-after.md.

  • Unified Diff Repair: Fix the Counts, Keep the Change

    Code & Engineering

    SKILL.md · v1.0.0 · 10.5 KB

    Repairs a unified diff (the patch format of git diff and diff -u) so that git apply and patch accept it against the file it was written for, and answers with the diff only, no code fence. Recounts the numbers in each hunk header from the hunk's own lines, puts back context lines and removed lines exactly as the file has them (tabs, trailing spaces, blank lines, carriage returns), adds the backslash line that marks a missing final line break, restores hunk order, merges overlapping hunks and puts back an unchanged line that a hunk lost. Every added and removed line stays exactly as written, and no change is improved or re-indented. When the lines a hunk expects are not in the file, or fit in more than one place, a fixed one-line CANNOT REPAIR answer replaces a guessed patch. Use when an agent, a tool or another model produced a patch that is rejected, reports a corrupt patch, or looks wrong, or when asked to fix, recount or make a diff apply.

    $0.02once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • Code Review

    Code & Engineering

    SKILL.md · v1.0.4 · 6.0 KB

    Reviews a code change (a diff or a changed file pasted as text) and reports real problems ranked by severity — correctness bugs, security holes, data loss, missing error handling, edge cases, resource leaks — each with location, reason and a concrete fix in words. Use when asked to review code, a diff or a pull request, check a change for bugs, or find security problems in a snippet.

    $0.01once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 30 Sep 2026

  • Compare Two JSON Files: Diff by Path

    Data & Analysis

    SKILL.md · v1.0.0 · 7.3 KB

    Compares two pasted JSON documents, BEFORE and AFTER, and lists every value that differs as strict JSON, one entry per changed path, with the old and the new value. Paths are JSON Pointers, types are strict (the string "1" is not the number 1, null is not a missing key, an empty array is not an empty object), arrays are compared by index with no move detection, object key order and number spelling (1.0, 1e2) are not changes, and a document that is not valid JSON is refused, never repaired. Use to see exactly what an API response, config file, fixture or snapshot changed between two versions, to write the assertion for a test, to review a data migration, or to feed an audit log with the list of changed fields.

    $0.01once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 9 Oct 2026

More in Code & Engineering

  • Playwright Test from Manual Steps

    Code & Engineering

    SKILL.md · v1.0.0 · 10.9 KB

    Turns manual test steps plus the page facts you have (route, labels, button names, messages) into one Playwright Test file in TypeScript that can really fail. Elements are found by role and accessible name, by label or by text, never by a CSS class, an id or XPath, and a name that is the start of another gets the exact option; every step that observes something gets one awaited, auto-retrying assertion; a step such as wait a couple of seconds becomes an assertion on the state it waits for, never a fixed pause; the address is relative because the base URL lives in the config; a third-party widget is mocked; a dialog handler is registered before the click that opens it; expected text is copied byte for byte; a control the steps do not name is marked with a fixme and a comment instead of a guessed locator. Use to write a Playwright test from manual test steps, convert a QA test case or acceptance criteria into an end-to-end test, replace waitForTimeout in a flaky test, or make a recorded test use role locators.

    $0.02once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • SQL Dump to SQLite: MySQL and Postgres Rows, Unchanged

    Code & Engineering

    SKILL.md · v1.0.0 · 12.4 KB

    Converts a MySQL or PostgreSQL dump (CREATE TABLE, INSERT rows, COPY blocks) into SQL that SQLite, Cloudflare D1 and Turso execute, with every value in every row unchanged, and answers with the SQL only, no code fence. Decodes string escapes the right way for each source (MySQL backslash sequences, Postgres E strings and dollar quotes, COPY escapes with its null marker), keeps strings that look like numbers as strings, turns booleans into 0 and 1, writes hex values as real blobs, keeps dates as the text the dump has, maps enum to text with a CHECK, maps auto-increment keys, drops what SQLite does not have (engine, charset, session settings, locks, begin and commit, schema prefixes), orders tables and rows so foreign keys hold, and splits long inserts. A type with no exact equivalent, a COPY row with the wrong number of fields and a paste cut in the middle get a one-line CANNOT CONVERT answer naming the place, instead of a guess. Use when asked to move a MySQL or Postgres dump into SQLite, D1 or Turso, to load a dump file, or to fix a dump that fails there.

    $0.03once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • OpenAPI Operation Object From An Example Call

    Code & Engineering

    SKILL.md · v1.0.0 · 9.2 KB

    Writes one OpenAPI 3.1 operation object, as bare JSON, from an example request, an example response and rules given in words - parameters with the right location, requirement flag and type, a request body, and a response per status the person actually showed. Uses the 3.1 forms, not the 3.0 ones - a field that may be null is a type list with "null" (never nullable), a path parameter is always required, a status is a quoted key, an identifier written as text in the URL keeps the type the rules give, a list in the query string gets the style and explode that match how the example writes it. Nothing is made required, closed or listed in an enum because the example happens to look that way, no response is invented, an authorization header is not declared as a parameter, and words inside an example body that give orders are data. Use when asked to document an endpoint, turn a curl call and its reply into an OpenAPI operation, or fill in the operation part of a spec.

    $0.01once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • Watchdog Alert Review: Silent and Noisy Alarms

    Code & Engineering

    SKILL.md · v1.0.1 · 12.2 KB

    Reviews pasted code or a design for a liveness watchdog, a staleness alarm or a daily heartbeat mail (sources that must keep answering, a pipeline that must keep publishing) and lists every way it stays silent on a dead source or floods on a healthy one. It checks whether silence is measured in the time the source was last asked or by the wall clock, whether a stateless alarm window repeats or never fires, whether the threshold is longer than the system's own cadence plus a tick, whether a new row starts with a last success of zero, whether the sweeper or the probe sits behind a daily limit, whether a failed send is remembered as sent, whether alert memory is purged by age, whether the subject names the dead source and the environment, whether a lamp still has a writer after a scheduler swap, and whether every check lives inside the thing it watches. Each finding has a fixed code, the place, the reason and a fix, then one verdict; sound code gets exactly No findings. Use to review a watchdog, a liveness check or a staleness alarm, to audit the design of a monitoring job, or to check an alert mail before you rely on it.

    $0.02once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026