@whyshouldaicareone AI disaster a day, and the fix

Check what Claude changed before you merge

Claude said the red tests were fixed. It had deleted 310 lines of them. This guide gives the diff commands that catch it.

The fix

Skip the summary and read the diff. The first command lists every changed file with its added and removed lines. The second lists only deleted files. The third shows one folder in full. Replace main with your base branch.

copy and paste
git diff --stat main
git diff --name-only --diff-filter=D main
git diff main -- tests/

Check it worked

A deleted test file, or a test file with only removed lines, is the red flag. Inside Claude Code, /diff opens the changes in your working tree, including the edits Claude has made so far, with added and removed line counts per file. Careful: the fullscreen diff panel skips test files by default. Click the count line at the bottom of its list to show them, or trust git diff.

copy and paste
/diff

git diff --shortstat main

Pro tip: make Claude ask before it edits tests

An ask rule makes Claude Code prompt on every edit to a matching path. Put it in .claude/settings.json. Ask rules are checked before allow rules, so an allow rule cannot silence it. Do not rely on it alone: a script that Claude runs can write files without hitting it. Still read the diff.

copy and paste
{
  "permissions": {
    "ask": ["Edit(tests/**)"]
  }
}

Pro tip: ask for the failing test first

Ask for a test that fails, then the fix. A test that never failed proves nothing. The Claude Code best-practices page suggests this: write a failing test that reproduces the issue, then fix it. The last sentence below is our addition.

copy and paste
Write a failing test that reproduces the bug,
then fix it. Do not change existing tests to
make them pass.

If it already happened: rewind

Run /rewind, or press Esc twice on an empty prompt. Pick the prompt from before the change and choose Restore code. Rewind does not track changes made by shell commands to files Claude never edited, and it is not version control. Commit before a big task. To put one deleted file back from main, use git restore.

copy and paste
# before a big task:
git add -A && git commit -m "before agent"
# put one deleted file back from main:
git restore --source=main -- path/to/deleted_test

Common mistake

Diffing against a branch that has moved. git diff main also shows what others added to main since you branched. Add --merge-base to compare against the point where you branched. It still includes uncommitted work.

copy and paste
git diff --stat --merge-base main

Official docs

One fix of twenty: the whole Claude Code survival kit.

Follow @whyshouldaicare

A new disaster and its fix every day. Comment the word under a reel to get its guide.