anomalyco / anomalyco/opencode
Windows: PowerShell -Include + Remove-Item wiped git repo during "clean junk files"
@Hona is already working on this.
Since Sep 11, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
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/HEADgone.git/objectsfile 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) .gitrestored from an old Recycle Bin backup (HEAD38ad35f, 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/buildcache
Expected behavior
- Never recursively delete from repo root without an explicit file list and user confirm
- Never touch
.git/ - Do not use PowerShell
-Includeas a file-type filter - Prefer
git cleandry-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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.