Git as Safety Net

The mandatory safety workflow for using Claude Code: always start from a clean git working tree, review all changes with git diff before committing, use git add -p for interactive file-by-file staging, and know how to revert everything Claude Code did.

Syntax

claude-code
// Before every Claude Code session:
git status          // Confirm clean tree
git stash           // Stash in-progress work if needed

// After every Claude Code session:
git diff            // Review all changes
git diff --staged   // Review staged changes
git add -p          // Stage interactively (accept/reject each hunk)
git commit          // Only after review

// Revert everything Claude Code changed:
git checkout .      // Discard all unstaged changes
git clean -fd       // Remove untracked files

Example

claude-code
// After a Claude Code migration session:
git diff
// Shows: 8 files changed

git add -p
// For each change hunk:
// Stage this hunk [y,n,q,a,d,s,?]?
// y — yes (include this change)
// n — no (reject this hunk)
// Repeat for each hunk across all files

// If Claude Code added a file you didn't want:
git clean -fd
// Removes untracked files created during the session