Bug: Claude executes destructive git checkout without confirmation
Bug Report: Claude executes destructive git commands without confirmation
Summary
Claude Opus 4.5 ran git checkout <file> to discard uncommitted working directory changes without user confirmation, violating its own safety rules about destructive git commands.
Environment
- Model: Claude Opus 4.5 (claude-opus-4-5-20251101)
- Interface: Claude Code CLI
- Platform: Windows 10 (MSYS2/Git Bash)
- Date: 2026-01-15
What happened
- User asked Claude to improve error handling in shell scripts
- Claude read
experiment-single.sh(which had significant uncommitted changes) - Claude made some edits, then wanted to see the diff
- Claude ran
git diff experiment-single.shand saw a large diff - Claude's reaction: "The diff is huge because the file was already modified from git. Let me checkout the current state and make only the surgical changes needed."
- Claude ran
git checkout experiment-single.shwithout asking for confirmation - All uncommitted work in that file was destroyed
Exact command executed
cd /e/Dev/Scripts && git checkout experiment-single.sh
Claude's own rules (from system prompt)
"NEVER run destructive/irreversible git commands (like push --force, hard reset, etc) unless the user explicitly requests them"
git checkout <file> that discards uncommitted changes is unambiguously a destructive command.
Expected behavior
Claude should have:
- Recognized that
git checkout <file>discards uncommitted changes - Either refused to run it, or asked for explicit confirmation
- At minimum, warned the user before executing
Actual behavior
Claude executed the destructive command immediately with no warning or confirmation.
Impact
- User lost all uncommitted work in the file (~100 lines of changes)
- Only recovered because Claude had read the file earlier in the conversation and could restore from memory
- If the file hadn't been read earlier, or if conversation context was lost, the work would be permanently gone
Root cause analysis
Claude saw a "messy" situation (large diff) and reflexively tried to "clean it up" without thinking through why the diff existed. This is a failure of:
- Following its own safety rules
- Pausing to consider consequences before running commands
- Recognizing that uncommitted changes have value
- Confidence miscalibration: Claude was certain enough about its diagnosis to skip verification. High-impact irreversible actions should require higher confidence thresholds, not bypass them.
Suggested fixes
- Add
git checkout <file>(when it discards changes) to the explicit blocklist of commands requiring confirmation - Before any
git checkoutof a modified file, checkgit statusand warn if there are uncommitted changes - Consider a general rule: any command that discards user work requires confirmation
Reproduction steps
- Have a git repo with a file containing uncommitted changes
- Ask Claude to work on improving that file
- Create a situation where Claude sees a large diff and wants to "start fresh"
- Observe whether Claude asks for confirmation before running
git checkout <file>
Additional context
Claude's immediate response when confronted: "I destroyed your work. No excuses."
Claude acknowledged this violated its own rules and was "careless, reactive, and stupid."
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗