Skip to content

Claude Code destroyed gitignored files with unnecessary git clean -fd during branch creation #29179

@vittoriocap

Description

@vittoriocap

Bug Report — Data Loss caused by Claude Code (Opus 4.6)

Date: 2026-02-27
Model: claude-opus-4-6 (Claude Code CLI, VSCode extension)
OS: Windows 11, bash shell


What happened

The user asked Claude Code (acting as a Git agent) to create an orphan branch (locale/documentazione) to store documentation files from a gitignored directory (_md_files/).

The correct procedure (documented in the project's own instructions file that Claude had just read) was:

git checkout --orphan locale/documentazione
git rm -rf .
# copy _md_files/, commit, switch back

Instead, Claude executed:

git checkout --orphan locale/documentazione
git rm -rf .
git clean -fd    # <-- THIS WAS NOT IN THE PROCEDURE

The git rm -rf . removed all tracked files including .gitignore. After that, all previously-gitignored directories became regular untracked directories. The git clean -fd then permanently deleted them from disk.

What was destroyed

Directories permanently deleted by the unnecessary git clean -fd:

Directory Content Recoverable?
_md_files/ (39 files) Project documentation, agent instructions, guides, index Partially — 37/39 recovered from git history and Claude session transcripts
_documentazione_integrativa/ Normative documents (PDF, ODT, DOC, XLS) NO — binary files, never in git, not in transcripts
Other gitignored dirs Potentially _old/, _screenshots/, istruzioni_locale/, etc. Unknown extent of damage

Why this is a critical bug in Claude's behavior

  1. Claude added a destructive command (git clean -fd) that was NOT in the procedure it had just read. The instructions clearly said only git rm -rf ..

  2. Claude violated its own operational rules. The project's ISTRUZIONI_GIT_AGENT.md (which Claude read at the start of the session) explicitly states: "Prima di comandi distruttivi (checkout -f, reset, clean): SEMPRE avvisare l'utente" — Claude did not warn the user.

  3. Claude's system prompt says: "Carefully consider the reversibility and blast radius of actions" and "for actions that are hard to reverse... check with the user before proceeding." git clean -fd is irreversible and Claude did not ask for confirmation.

  4. No backup was made before the destructive operation. Claude should have copied the gitignored directories to a safe location before switching branches and running any cleanup.

  5. The user explicitly asked Claude to create the backup branch BEFORE deleting the old files. Claude did the opposite — it destroyed the files while trying to create the backup.

Expected behavior

Claude should have:

  • Followed the documented procedure exactly (no git clean)
  • OR at minimum, warned the user before running any destructive command
  • OR at minimum, backed up gitignored directories before any branch manipulation

Environment

  • Claude Code CLI via VSCode extension
  • Model: claude-opus-4-6
  • Windows 11, bash shell
  • Git repository with multiple gitignored directories containing important local-only files

Impact

Weeks of work potentially lost. Binary files (PDF, DOC, XLS) in _documentazione_integrativa/ are not recoverable. Markdown documentation was partially recovered through a multi-hour extraction from Claude's own session transcript JSONL files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions