Checkpoint restore (git clean -fd) permanently deletes all untracked files
Describe the bug
Describe the bug
When using "restore to checkpoint" (triggered by pressing Escape during an agent run and choosing to restore), the SnapshotManager.rollbackToSnapshot() method runs git clean -fd on the repository root. This permanently deletes all untracked files and directories in the repo — including large output files generated by external processes that the agent never touched.
In my case, this destroyed ~1GB+ of evaluation output data (.jsonl and .xlsx files) across multiple directories under output/ that were generated by a Python script the agent ran. The agent only read these files — it never created or modified them — yet they were all deleted by the checkpoint restore.
Root cause (from source analysis)
The rollback flow in rollbackToSnapshot() calls:
trr(gitRoot, gitCommit, gitBranch)→ runsgit checkout --force+git reset --hardqnr(gitRoot)→ runsgit clean -fd← this is the destructive operation
git clean -fd removes all untracked files and directories. The snapshot system only backs up files that the agent itself created/modified. Any files created by external processes (scripts, builds, test output, data pipelines) that happen to be untracked are silently and permanently deleted.
Affected version
0.0.417 (but the code is present in earlier versions too — at least 0.0.411+)
Steps to reproduce
- Have a git repo with untracked files/directories not in
.gitignore(e.g.,output/with large data files) - Start a Copilot CLI session in that repo
- Have the agent run a command that generates output files (e.g.,
uv run python script.pythat writes tooutput/) - Press Escape twice to cancel the agent mid-run
- Choose "Restore to this checkpoint" when prompted
- All untracked files/directories are now deleted — including the output files from step 3
Expected behavior
Checkpoint restore should not delete untracked files that the agent didn't create. Possible fixes:
- Only clean files the agent created: Track which files were created by agent tool calls and only remove those
- Skip
git cleanentirely: The snapshot already tracks and restores individual files — thegit cleanis a blunt hammer on top - Warn the user: At minimum, show "This will delete X untracked files (Y MB). Proceed?" before running
git clean -fd - Move to trash instead of delete: Use OS trash/recycle bin so files can be recovered
Additional context
- The
output/directory was not in.gitignore(user's mistake, now fixed), but even repos with proper.gitignorecould lose untracked files in directories that aren't ignored - The data loss is permanent —
git clean -fddoesn't use the recycle bin - This is especially dangerous for repos that generate large output artifacts (ML training, data pipelines, evaluation benchmarks)
- The
SESSION_CLEANUPfeature flag is set to"staff-or-experimental", suggesting this is still being refined
Affected version
0.0.417
Steps to reproduce the behavior
No response
Expected behavior
No response
Additional context
No response
I think got bit by this in version 1.0.5 today. I observed:
- I was working in a git repo
- Agent read an existing untracked file at the beginning of the session
- I rolled back to a prior point in the convo via "esc" a couple of times
- Agent couldn't find the same file again
- I confirm that all untracked files now deleted
I guess there's two things here to consider: whether untracked files should survive a rollback, and whether the mechanism actually knows what it's deleting. Arguably, a rollback to checkpoint X should discard anything created after X, whether by an agent or not. Otherwise, it's not really a full restore. But the actual bug that you mention is that git clean -fd uses tracked/untracked as a representation for "safe to delete," only looking at your .gitignore and not the real rollback boundary.
I ran into a similar version of this while building a checkpoint/rollback layer for agent workspaces. I went with filesystem snapshots instead of git-based, so there is a clear boundary on what files will be deleted (created after target OverlayFS checkpoint) instead of just looking at git tracking status. While it yields the same end result (new files get wiped on rollback), it's tied to the actual restore point.
It could be a useful frame for whatever the fix here ends up looking like: github.com/rahulb0802/rewind-sdk
A checkpoint should restore the agent-managed delta, not equate “untracked” with “safe to delete.” Git has no provenance for who created an untracked file, so git clean -fd cannot implement the advertised boundary.
The rollback manifest should record each path the agent created, modified, or deleted, plus a content hash and timestamp. Restore can then reverse only that manifest. If a broader clean is offered, show the exact candidate list and byte total, require a separate explicit confirmation, and preferably quarantine the files instead of unlinking them. Regression coverage should include files created concurrently by an external process after the checkpoint.
This appears to be resolved as of GitHub Copilot CLI v1.0.86. Please update to that release or a newer stable version. We're closing this as completed. If it still happens, please comment with your version and reproduction steps.
The close cites v1.0.86. Those notes do not mention rewind or git clean.
The rewind change is v1.0.78 (2026-08-03): /rewind no longer requires git and restores only the files Copilot changed, skipping any file whose contents no longer match what Copilot last wrote. I read the issue, the close comment, and those two release notes. I did not grep the source.