Skip to content

Windows: PowerShell -Include + Remove-Item wiped git repo during "clean junk files" #48468

Description

@Miles-hfy

Description

Summary

On 2026-09-11, OpenCode (model grok-4.6 / xai) deleted almost the entire working tree and .git/objects while handling a request to clean invalid/expired files. This was a permanent Remove-Item -Force, not Recycle Bin.

Environment

  • OS: Windows 10/11, PowerShell 5.1
  • Product: OpenCode
  • Model: xai/grok-4.6
  • Repo: C:\Work\3.Code\box_v1.2(ESP32S3+GD32F103)
  • Cleanup session: ses_f70811a37ffexT0bYeE2j947UM (started ~16:04 CST)
  • Prior work session same afternoon: ses_f70cec837ffeiBLxux59UMLmnd (14:39–15:52 CST)

What I asked

Clean invalid and expired files in the current folder (temp, caches, stale backups). I did not ask to delete source or .git.

What went wrong

The agent enumerated files with:

Get-ChildItem -LiteralPath $root -Recurse -Force -File -Include '*.pyc','*.pyo'

On PowerShell 5.1, -Include with -LiteralPath does not filter by extension. It returned nearly every file, including .git objects. Those paths were passed to Remove-Item -LiteralPath ... -Recurse -Force.

Git objects are content-addressed. After deletion they were not in Recycle Bin and could not be undeleted.

Impact

Before deletion, git status showed master 132 commits ahead of origin/master, plus uncommitted afternoon work.

After deletion:

  • working tree files gone
  • .git/HEAD gone
  • .git/objects file count = 0

Partial recovery (not a fix)

  • Source tree restored from sibling git worktree box_v1.2(ESP32S3+GD32F103)-wall (last write 14:04 CST)
  • .git restored from an old Recycle Bin backup (HEAD 38ad35f, 2026-08-22)
  • Afternoon edits restored from OpenCode snapshot pack + session DB blobs/patches

Still lost:

  • history of ~132 local unpushed commits
  • any master changes after 14:04 that were not in the afternoon OpenCode session
  • firmware/esp32/build cache

Expected behavior

  • Never recursively delete from repo root without an explicit file list and user confirm
  • Never touch .git/
  • Do not use PowerShell -Include as a file-type filter
  • Prefer git clean dry-run or an allowlist of gitignored paths (tmp/, __pycache__/, *.pyc)

Request

Treat this as a safety defect: destructive filesystem ops on Windows need a deny-list for .git, a confirm step, and a filter that actually works on PowerShell 5.1.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions