[Bug] Claude Code destructively overwrites unstaged changes with `git checkout <ref> -- .`

Resolved 💬 3 comments Opened Apr 30, 2026 by inwoodev Closed May 4, 2026

Bug Description
Destructive git checkout <branch> -- . wiped unstaged WIP across 14 files during a code review session. What happened: While helping me code-review a feature branch, Claude ran git checkout origin/<feature-branch> -- . inside my working tree (which was on a different branch with 14 unstaged modified files). The command silently overwrote every file with the feature branch's content. Then it ran git checkout HEAD -- . to "restore," which only reset to the current branch's HEAD — the unstaged WIP was destroyed. None of it had been git-added or stashed, so no recoverable blobs. Why it happened: The model reached for a destructive command to "look at" another branch's files when read-only alternatives (git show <ref>:<path>, git worktree add) would have been correct. Suggested mitigations: 1. Treat git checkout <ref> -- . (and -- <pathspec> with broad globs) and git restore --source=<ref> . as destructive when the worktree has unstaged/untracked changes — require confirmation. 2. The system prompt already warns about reset --hard, force push, etc., but the checkout <ref> -- . foot-gun is not on that list. It should be. 3. Default to git show <ref>:<path> or worktree creation when the intent is "read another branch." Impact: Significant uncommitted engineering work destroyed. fsck dangling blobs, APFS snapshots, Time Machine, editor autosave — all returned nothing. Only remaining hope was the editor's in-memory buffer. Environment: macOS, Opus 4.7 (1M context).

Environment Info

  • Platform: darwin
  • Terminal: iTerm.app
  • Version: 2.1.123
  • Feedback ID: 3eae7ba8-9efd-45c2-a6de-62ba3fd66d9c

Errors

[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/james/.local/share/claude/versions/2.1.123 (expected in multi-process scenarios)\n    at x86 (/$bunfs/root/src/entrypoints/cli.js:2769:2177)\n    at Jw8 (/$bunfs/root/src/entrypoints/cli.js:2769:1257)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-30T13:44:34.570Z"}]

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗