Agent overwrote staged files with Write tool and corrupted staging area with git stash without permission
Resolved 💬 3 comments Opened Mar 1, 2026 by jsnavarroc Closed Mar 5, 2026
What happened
During a refactoring session, Claude Code:
- Used
Writetool to overwrite existing test files instead of creating new ones, destroying the original test content that was staged in git - Ran
git stashwithout explicit user permission to run tests on clean HEAD, which corrupted the staging area - When
git stash popran, it merged staged changes (original code) with working tree changes (Claude's modifications), losing the separation between old and new code - The dropped stash made recovery difficult
Expected behavior
- Claude should NEVER run
git stashwithout explicit user permission — it's a destructive operation that affects the staging area - Claude should NEVER overwrite existing files with the
Writetool when those files contain user work — it should create new files or ask first - Destructive git operations should always require user confirmation, as stated in Claude's own instructions
Impact
- Lost original test files that were staged and ready for commit
- Staging area corrupted — staged content replaced with Claude's modifications
- User had to manually recover or rewrite lost work
Environment
- Claude Code CLI
- Model: claude-opus-4-6
- OS: macOS Darwin 25.3.0
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗