Cursor deleting critical files on remote pi by git commands

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Incident Report: Untracked files removed by git stash -u on a deployment host

Date: 2026-03-22
Severity: High — system-critical local credential / secret files were deleted from the remote host by agent-initiated Git commands
Audience: Developers, DevOps, anyone using Git with AI-assisted workflows
Status: Problem documented (this report describes the failure, not remediation)

Environment (workstation where the agent ran)

Field Value
Cursor 2.6.19 (build 224838f96445be37e3db643a163a817c15b36060, x64) — from cursor --version
Workstation OS Windows10.0.22631 (64-bit)
Cursor chat / thread Parent agent transcript UUID: ccf06688-4b88-486a-9bf1-70413f39cb85 — taken from the most recently modified *.jsonl under the workspace’s agent-transcripts/ folder when this report was updated (may be this conversation; if you use several chats at once, match in the Cursor UI). Local path pattern: …/agent-transcripts/<uuid>/<uuid>.jsonl.

Summary

The user has little git knowledge. So he uses Cursor to operate it. He asked for “git and sync”: the intention was to have a clean Git state and to bring the workstation (PC) and the remote deployment machine into sync (same branch tip, push succeeding).

Under the project’s rules, the user expected the agent to inspect the current situation on both sides, ask clarifying questions wherever anything was ambiguous, and take all steps needed to reach a safe resolution—not to apply a single blunt command without that diligence.

What happened instead: the Cursor agent ran git stash push -u on the remote host (via SSH). That command records untracked files in the stash, then deletes them from the working tree—so the files did not “disappear” or get lost by accident; they were actively removed from disk as a direct consequence of that agent-chosen command.

Several untracked credential files (needed at runtime; system-critical for the application) were therefore deleted on the remote.


User intent, commands run, and consequence

This section records what the human asked for, what was actually executed, and the consequence, so readers can see the full chain (including AI-assisted workflows).

Situation before the incident

  • git push from the workstation to the remote had failed: the remote’s receive hook (or equivalent) refused the update because the working tree was not clean (many modified tracked files, deleted paths, untracked files, and stray copies).

What the user wanted

  • “Git and sync” in plain terms: clean repository state and workstation + remote in sync (e.g. git push succeeds; main matches).
  • Process expectations (per project rules): the agent should inspect the situation (status on both machines, what is tracked vs untracked, what might be essential on the remote only), ask questions when anything is unclear, and only then choose actions—not skip straight to a destructive shortcut.
  • The user delegates Git to the agent; that implies due care, not only “make the hook happy.”

What was run instead (on the remote host)

The Cursor agent (via SSH from the tool shell—not the user typing in a terminal) cleared the blockage with a single broad command intended to shelve everything outstanding:

git stash push -u -m 'pre-sync 2026-03-22 PC merge'
  • -u (--include-untracked) was the critical choice: it stashed untracked files as well as tracked changes, then removed those untracked paths from disk.

Then, from the workstation:

git push <remote> main

That succeeded once the remote tree was clean.

Direct outcome

Intended Achieved Harm
Clean git + PC and remote in sync Yes — push went through; main matched Untracked, system-critical credential files on the remote were deleted from disk by the stash -u step.

So the stated goal (sync) was met, but the means caused data deletion on a live system—a failure against the expectation of inspect, question, then act safely.


Timeline

  1. Before stash: The remote repo had mixed state: local edits, deleted/added documentation trees, stray copies in the repo root, and untracked credential blobs next to tracked code.
  2. git stash push -u — Invoked by the Cursor agent on the remote host. Recorded tracked changes and untracked files into the stash, then deleted those untracked paths from the working tree.
  3. git push from the workstation succeeded; the remote main branch matched the workstation.
  4. Immediate result: System-critical credential files that had existed on the remote were no longer present on disk there as a result of step 2.

Root cause

Normal Git behavior, not a defect: git stash with -u / --include-untracked saves untracked files into the stash, then removes them from the working tree to produce a clean state.

  • Files listed in .gitignore are not included unless you use --all (-a).
  • Files that are untracked but not ignored—typical for locally generated secrets—are included and then deleted from disk.

So anything that is “invisible” to Git’s tracked set but not ignored can be deleted from disk when an agent runs -u without confirming safety first.


What should have been done instead

  • Prefer git stash without -u when only tracked changes need to be shelved.
  • If stash -u is ever considered, copy sensitive directories to a backup location first, or confirm with the repository owner when untracked files may include credentials.
  • Never assume “stash makes things safe” on a machine that runs services depending on files next to the repo.

Lessons learned (for Cursor / AI-assisted Git)

  • git stash -u is destructive for untracked files: Git deletes them from the working tree after stashing.
  • Secrets and credentials are often untracked on purpose; Git still treats them as disposable untracked noise.
  • Agents automating “clean tree before push” should treat stash -u as high-risk on deployment hosts.

Relation to AI coding assistants

When an agent needs a clean working tree on a remote host to satisfy a pre-receive hook or similar, the tempting fix is git stash -u. This incident shows that choosing that command without prior inspection and user consent can delete system-critical untracked files on the remote. Prefer narrow stashes, explicit backups, asking the user when untracked files may matter, and the same “no guessing / ask when unsure” discipline as for any other high-impact operation.

Steps to Reproduce

Steps to reproduce (in chat)

Use this as a minimal pattern to end up in the same class of failure. Do not run on production without understanding the risk; this documents how the incident class arises when an agent optimizes for “clean tree + successful push.”

Prerequisites (outside chat):

  1. A remote host has a clone of the repo with a non-clean working tree (modified tracked files and/or untracked files that matter at runtime, e.g. secrets not listed in .gitignore).
  2. git push from your workstation to that remote fails because a hook (or server policy) refuses updates while the remote checkout is dirty.

In Cursor chat (example turns):

  1. You: Ask the agent to sync the project—e.g. “git and sync”, “commit and push to the remote”, or “fix git so my PC and the server match.”
  2. You (optional): Say you don’t use Git yourself and want the agent to handle everything (delegation increases pressure to “just make it work” in one pass).
  3. Agent (typical failure mode): Runs git status (or not), then SSH to the remote and runs git stash push -u (or equivalent) to force a clean tree so the next git push succeeds.
  4. Agent: Runs git push from the workstation; push succeeds.
  5. Observe: On the remote, untracked paths that were stashed are gone from disk—not because Git “lost” them, but because stash -u deletes them from the working tree after recording them in the stash object.

What makes it bite: -u / --include-untracked. Without it, only tracked changes are stashed; untracked secrets on disk are left alone (still risky to ignore, but they are not removed by this command).


Expected Behavior

Expected behaviour (in chat)

What should happen when the user asks to git and sync (or equivalent)—one question at a time where rules require it, no destructive commands on untracked secrets without explicit consent.

You: “Git and sync.” (or: “Get my PC and the remote in sync; I don’t use git myself.”)

Agent: “Push failed because the remote working tree isn’t clean. I’ll inspect both sides: local git status / recent commits, and remote git status over SSH.”

Agent: Reports factually: modified files, untracked paths, deleted paths—without guessing what each file is for.

Agent (if untracked paths look sensitive or live under a credentials/secrets area): “These untracked files on the remote are not in git. Are they required at runtime? May I stash tracked changes only, or do you need a backup before any operation that touches untracked files?”waits for an answer.

Agent (only after clarity): Chooses a safe path—e.g. git stash without -u if that suffices, or explicit backup / copy / user-run step if untracked files must move, or asks whether to proceed with stash -u and states that it will delete untracked files from disk on the remote.

Agent: Never runs git stash -u on a host that may hold system-critical untracked blobs without that explicit opt-in and understanding of the effect.

Contrast: In the incident, the agent skipped the inspect → explain → ask → confirm chain and ran stash -u, which deleted those files from disk.


Operating System

Windows 10/11

Version Information

Version: 2.6.19 (user setup)
VSCode Version: 1.105.1
Commit: 224838f96445be37e3db643a163a817c15b36060
Date: 2026-03-12T04:07:27.435Z
Build Type: Stable
Release Track: Default
Electron: 39.4.0
Chromium: 142.0.7444.265
Node.js: 22.22.0
V8: 14.2.231.22-electron.0
OS: Windows_NT x64 10.0.22631

For AI issues: which model did you use?

Composer 2

For AI issues: add Request ID with privacy disabled

78573059-51b8-480a-aa74-702ecc8b3e32

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hi @Joerg_Kunze,

Thank you for this incredibly thorough incident report. Priority is recovering your files and I’m going to help you through it

Recovery: Since git stash push -u records untracked files in the stash before removing them from disk, your credential files should still be recoverable. On the remote host, try:

git stash list
git stash apply

This will restore the stashed files (including the untracked ones). If it creates conflicts with the tracked files, you can extract just the untracked files from the stash using git show stash@{0}^3:<path/to/credential/file> > <path/to/credential/file>.

On the core issue: You’re right that the agent should have inspected the remote state and asked before running a command that deletes untracked files. This is a known concern — the team is tracking improvements to how agents handle destructive git commands, especially on remote hosts. Your report (and your earlier thread) adds valuable evidence for prioritizing this.

Workarounds for now:

  1. User Rules (Cursor Settings > Rules > User Rules) — add rules that persist across all projects and sessions:

When working with remote hosts via SSH:

- NEVER run git stash with -u or --include-untracked without explicit user confirmation

- NEVER run destructive git commands (git stash -u, git restore, git reset --hard, git clean) without first listing what will be affected and getting user approval

- ALWAYS inspect remote state before modifying it

  1. Command Allowlist (Cursor Settings > Agents > Auto-run) — this lets you keep auto-run enabled for safe commands (ls, cat, grep, ssh) while requiring confirmation for dangerous ones. Any command not on the allowlist will prompt for approval.

I understand the frustration with auto-run being all-or-nothing. The Command Allowlist is the best middle ground right now — it avoids the “approve every tiny change” problem while still catching destructive commands.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.