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:

  1. Used Write tool to overwrite existing test files instead of creating new ones, destroying the original test content that was staged in git
  2. Ran git stash without explicit user permission to run tests on clean HEAD, which corrupted the staging area
  3. When git stash pop ran, it merged staged changes (original code) with working tree changes (Claude's modifications), losing the separation between old and new code
  4. The dropped stash made recovery difficult

Expected behavior

  • Claude should NEVER run git stash without explicit user permission — it's a destructive operation that affects the staging area
  • Claude should NEVER overwrite existing files with the Write tool 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

View original on GitHub ↗

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