Review AI Edits with a Word-Level git diff
Ask an AI to polish a paragraph, compare it with the original using git diff --word-diff, then grep for changed numbers and names so you can check them by hand.
A number changed quietly inside an AI-polished paragraph is hard to spot by eye. Put the original and the edited text through git diff's word-level comparison and filter for changes that contain a digit or a name. For the approach where the model reports its own changes in a table, see Get Claude's proofreading as a table of changes. Here the model's report is not trusted; only the two files are compared.
[1] Save the original. It has numbers, dates, a person's name and a company name (all invented).
The Q3 sales report is attached. Revenue grew 12.4% over Q2 to $830,000, and we signed 47 new customers. The biggest driver was the Busan branch, which opened in September under Ms. Kim.Receivables rose to $120,000, though. Three clients paid late, including Harbor Supply.The review meeting is on Thursday, October 23 at 2 pm in the main conference room. Please reply by the 21st.[2] Have the AI polish it and save the answer as ai.txt. The prompt asks for "reads more smoothly" rather than proofreading, which gives the model more room to touch things.
$ (printf '%s\n\n' 'Polish the text inside <document> so it reads more smoothly. Output only the revised text.' '<document>'; cat orig.txt; echo "</document>") > prompt.txt$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" < prompt.txt > ai.txt$ cat ai.txtThe Q3 sales report is attached. Revenue grew 12.4% over Q2 to $830,000, and we signed 47 new customers. The biggest driver was the Busan branch, which opened in September under Ms. Kim. Receivables also rose, to $120,000, as three clients, including Harbor Supply, paid late. The review meeting will be held on Thursday, October 23, at 2 pm in the main conference room. Please reply by the 21st.The model merged two sentences and added blank lines between paragraphs.
[3] Compare the two files word by word. --no-index lets git compare files outside a repository.
$ git diff --no-index --word-diff orig.txt ai.txtdiff --git a/orig.txt b/ai.txtindex b18b33b..d6f02ce 100644--- a/orig.txt+++ b/ai.txt@@ -1,3 +1,5 @@The Q3 sales report is attached. Revenue grew 12.4% over Q2 to $830,000, and we signed 47 new customers. The biggest driver was the Busan branch, which opened in September under Ms. Kim. Receivables [-rose-]{+also rose,+} to $120,000, [-though. Three clients paid late,-]{+as three clients,+} including Harbor [-Supply.-]{+Supply, paid late.+} The review meeting [-is-]{+will be held+} on Thursday, October [-23-]{+23,+} at 2 pm in the main conference room. Please reply by the 21st.[-…-] is removed text and {+…+} is added text. Unchanged text stays in place, so the changes stand out inside the paragraph.
[4] Instead of reading every change, pull out the changed words that contain a digit. --word-diff=porcelain prints each changed word on its own line (- removed, + added), and -U0 drops the unchanged context.
$ git diff --no-index -U0 --word-diff=porcelain orig.txt ai.txt | grep -E '^[-+]' | grep -vE '^(---|\+\+\+)' | grep -E '[0-9]'-23+23,The grep -v removes the --- a/… and +++ b/… header lines. Here the only hit is a comma added after 23, not a changed number. To catch names too, list the words that must not change in a file and add grep -F -f. A name is caught only if the removed side contains a listed string, so list the word that would actually change.
KimBusanSupplyBoth filters in one script:
#!/bin/sh# usage: wd-flag.sh orig.txt revised.txt names.txt — print changed words that contain a digit or a listed namegit diff --no-index -U0 --word-diff=porcelain "$1" "$2" | grep -E '^[-+]' | grep -vE '^(---|\+\+\+)' > /tmp/wd.$$grep -E '[0-9]' /tmp/wd.$$; grep -F -f "$3" /tmp/wd.$$; rm -f /tmp/wd.$$$ chmod +x wd-flag.sh$ ./wd-flag.sh orig.txt ai.txt names.txt-23+23,-Supply.+Supply, paid late.Both hits are harmless, but you still have to look at each one.
[5] To see the filter catch something, you need a bad edit. In this run the model never changed a number or a name, so ai-bad.txt was made from ai.txt with sed (the model did not make these errors): 12.4% → 14.2%, 47 → 74, October 23 → 24, Ms. Kim → Ms. Lee, Harbor Supply → Harbor Trading.
$ sed -e 's/12\.4%/14.2%/; s/47 new/74 new/; s/October 23,/October 24,/; s/Harbor Supply/Harbor Trading/; s/Ms\. Kim/Ms. Lee/' ai.txt > ai-bad.txt$ ./wd-flag.sh orig.txt ai-bad.txt names.txt | sort -u+14.2%+24,+74-12.4%-23-47-Kim.-Supply.Every changed figure and both changed names show up. Spacing and wording edits such as rose → also rose, stay out. Check each hit against the original.
[6] Know what this does not catch.
- A number rewritten as a word ("3 clients" → "three clients") has no digit to match.
- With the default whitespace splitting, punctuation sticks to the word.
October 23→October 23,was flagged as-23/+23,above. - A name that is not in
names.txtgoes unseen. - A change in meaning with no number or name in it is not flagged. Read the full comparison from step 3 for that.
Check it with the Text diff (diff -u) tool ↗ — calculated in your browser.