VS Code Copilot recreates deleted files when switching chat threads — workaround?
VS Code 1.100.3 on Windows 11 recreates files as empty files when I switch back to a GitHub Copilot chat thread that previously referenced them, even though I deleted them with PowerShell (
Remove-Item -Force). The same thing happens after reloading the window or reopening VS Code, and other users report it on macOS (Copilot Chat 0.29.1) and Linux. Is there a fix or workaround that stops Copilot from restoring deleted files?Originally asked on GitHub: https://github.com/microsoft/vscode/issues/251284
6 answers
This is a known bug: a VS Code contributor closed the issue as a duplicate on 2025-08-04, and the thread contains no official fix. It reproduces on Windows 11 (VS Code 1.100.3), macOS (Copilot Chat 0.29.1), and Linux: files that a Copilot chat thread referenced come back as empty files when you return to that thread, reload the window, or reopen VS Code.
The most complete workaround reported in the thread (comment 12, reported as working) is to delete the chat session's stored edit state:
- Open
%AppData%/Code/User/workspaceStorage/on Windows. - Text-search that folder for the name of one of the recreated files — it appears in a
state.jsonunder a path likeUser\workspaceStorage\<workspace-hash>\chatEditingSessions\<session-id>\state.json. - Delete the whole
<session-id>folder.
The reporter says this stops the recreation and preserves the AI context; only that session's edit history is lost.
Other workarounds mentioned in the thread:
- Start a new chat session instead of returning to the old one (worked for one user).
- Run
git clean -fdto remove the recreated files (worked, but the bug keeps happening). - Adding "never use rm/cp/mv" rules to
copilot-instructions.mddid not work — the model ignored them.
Did this work for you?- Open
What @gusmanb tried on GitHub (Worked)
Searched %AppData%/Code/User/workspaceStorage for the offending filename, found it in chatEditingSessions//state.json, then deleted the whole session folder. The reporter says file recreation stopped while AI context was preserved; only that session's edit history was lost.
Source: https://github.com/microsoft/vscode/issues/251284#issuecomment-3163429479 (opens external site)
Did this work for you?What @soyeyalon tried on GitHub (Worked)
Ran
git clean -fdto remove the files that Copilot had recreated after the bug occurred.Source: https://github.com/microsoft/vscode/issues/251284#issuecomment-3120745230 (opens external site)
Did this work for you?What @gpressutto5 tried on GitHub (Worked)
Started a new chat session after deleting Copilot-created files instead of reusing the old session, so deleted files were not recreated after chat iterations or closing/reopening VS Code.
Source: https://github.com/microsoft/vscode/issues/251284#issuecomment-3079507472 (opens external site)
Did this work for you?What @snoop244 tried on GitHub (Didn't work)
Added strict rules to copilot-instructions.md telling the agent to never use rm/cp/mv and to prefer apply_patch/insert_edit_into_file/create_file; the LLM ignored them.
Source: https://github.com/microsoft/vscode/issues/251284#issuecomment-3080994301 (opens external site)
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Deleted referenced files with
Remove-Item -Forcein PowerShell, sent a message in a new chat, then returned to the original chat thread; the empty files were recreated.Source: https://github.com/microsoft/vscode/issues/251284 (opens external site)
Did this work for you?