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.
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.
/diff
git diff --shortstat mainPro 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.
{
"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.
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.
# 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_testCommon 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.
git diff --stat --merge-base mainOfficial docs
One fix of twenty: the whole Claude Code survival kit.
Follow @whyshouldaicareA new disaster and its fix every day. Comment the word under a reel to get its guide.