claude-code - 💡(How to fix) Fix [BUG] Agent destructive multi-step git operation deleted user-uploaded files outside intended scope [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56277Fetched 2026-05-06 06:32:25
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Error Message

This is an agent-systems concern, not user error. The destructive multi-step flow (symlink creation → git add -A → commit → ff-merge) was synthesized by the agent across

Error Messages/Logs

No error from the agent's perspective — every step succeeded. No error from git either: the destructive directory→symlink type change is technically valid and ff-merge No error from the agent's perspective — every step succeeded. No error from git either: the destructive directory→symlink type change is technically valid and ff-merge

Code Example

No error from the agent's perspective — every step succeeded. No error from git either: the destructive directory→symlink type change is technically valid and ff-merge
  proceeded silently.

  Post-incident state of `uploads/` (was a directory with user files, now empty):
  $ ls -la /path/to/repo/uploads
  (empty)
  $ stat /path/to/repo/uploads
  ... lrwxr-xr-x ... uploads -> /path/to/repo/uploads (circular symlink, 49 bytes)

  Recovery attempts (all empty):
  $ tmutil listbackups
  No machine directory found for host.
  $ tmutil listlocalsnapshots /
  Snapshots for disk /:
  $ find / -name "<one of the deleted UUID files>" 2>/dev/null
  (no results)
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

While working in a git worktree, the agent created a symlink intended as a local fix, committed it via git add -A, and later fast-forwarded that commit into main. The fast-forward merge replaced an existing real directory in main with the tracked symlink. As part of that replacement, git deleted the untracked user-uploaded files that lived inside the directory. About 18+ user-uploaded image files were permanently lost across multiple shows in a performance management app — including files completely unrelated to the symlink's stated purpose. The user did not intend, approve, or anticipate the destruction.

This is an agent-systems concern, not user error. The destructive multi-step flow (symlink creation → git add -A → commit → ff-merge) was synthesized by the agent across multiple turns. At each gating step the agent had access to information that would have revealed the blast radius (git status, git diff, git diff base..head --stat) but did not consult it. The agent's stated rationale ("worktree-local symlink for poster display") never matched the eventual effect ("replace main's directory and destroy its contents").

What Should Happen?

Any agent operation that would delete user-uploaded files — at any stage of any multi-step flow — should require explicit user confirmation, not happen as a side effect.

Specific guardrails I'd want as a Claude Code user:

  1. Before agent runs git merge / git checkout, force inspection of paths whose type changes (file ↔ symlink ↔ directory) in git diff base..head.
  2. Default refusal when a tracked-tree change would replace a non-empty directory in the destination working tree, even when --ff-only would otherwise succeed.
  3. After git add -A, the agent should be required to review the staged-list and prove each entry is intentional before being allowed to git commit in the same turn.
  4. Symlinks pointing outside the worktree's own subtree should be a flagged pattern requiring explicit user confirmation before they enter the index.

Error Messages/Logs

No error from the agent's perspective — every step succeeded. No error from git either: the destructive directory→symlink type change is technically valid and ff-merge
  proceeded silently.

  Post-incident state of `uploads/` (was a directory with user files, now empty):
  $ ls -la /path/to/repo/uploads
  (empty)
  $ stat /path/to/repo/uploads
  ... lrwxr-xr-x ... uploads -> /path/to/repo/uploads (circular symlink, 49 bytes)

  Recovery attempts (all empty):
  $ tmutil listbackups
  No machine directory found for host.
  $ tmutil listlocalsnapshots /
  Snapshots for disk /:
  $ find / -name "<one of the deleted UUID files>" 2>/dev/null
  (no results)

Steps to Reproduce

No error from the agent's perspective — every step succeeded. No error from git either: the destructive directory→symlink type change is technically valid and ff-merge proceeded silently.

Post-incident state of uploads/ (was a directory with user files, now empty): $ ls -la /path/to/repo/uploads (empty) $ stat /path/to/repo/uploads ... lrwxr-xr-x ... uploads -> /path/to/repo/uploads (circular symlink, 49 bytes)

Recovery attempts (all empty): $ tmutil listbackups No machine directory found for host. $ tmutil listlocalsnapshots / Snapshots for disk /: $ find / -name "<one of the deleted UUID files>" 2>/dev/null (no results)

Claude Model

None

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

2.1.128 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

The agent's operation should be modified to require explicit user confirmation before deleting user-uploaded files, and guardrails should be added to prevent similar incidents.

Guidance

  • Implement a check before running git merge or git checkout to inspect paths whose type changes (file ↔ symlink ↔ directory) in git diff base..head.
  • Add a default refusal when a tracked-tree change would replace a non-empty directory in the destination working tree.
  • Require the agent to review the staged-list after git add -A and prove each entry is intentional before allowing git commit.
  • Flag symlinks pointing outside the worktree's own subtree as a pattern requiring explicit user confirmation.

Example

No code snippet is provided as the issue is more related to the agent's behavior and Git operations rather than a specific code fix.

Notes

The provided information suggests that the issue is related to the agent's behavior and the Git operations it performs, rather than a specific code bug. The suggested guardrails and checks should help prevent similar incidents in the future.

Recommendation

Apply workaround: Implement the suggested guardrails and checks to prevent the agent from deleting user-uploaded files without explicit user confirmation. This will help prevent similar incidents and ensure that the agent's operations are more transparent and safe.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Agent destructive multi-step git operation deleted user-uploaded files outside intended scope [1 comments, 2 participants]