Recover Unsaved VS Code Files
VS Code keeps unsaved edits in a hidden Backups folder, so a closed tab or a crash usually hasn't lost your work. First try reopening VS Code — it restores the last session automatically. If not, the raw text is in %appdata%\Code\Backups. Steps below.
First: reopen VS Code
VS Code restores your previous session by default — unsaved tabs reappear with their content. If they don't, don't open or edit anything yet; go straight to the two recovery paths below. Which one works depends on whether the file was ever saved to disk.
If the file was saved at least once: use the Timeline (Local History)
This is the fastest fix and most people miss it. Since VS Code 1.66, Local History is on by default and quietly snapshots every file each time you save or make a big edit — even if you later overwrote or lost the content.
- Open the file (or create one with the same name and path).
- Open the Timeline view: in the Explorer sidebar, expand the Timeline panel at the bottom, or run
Timeline: Focus on Timeline Viewfrom the Command Palette (Ctrl/Cmd+Shift+P). - You'll see a list of timestamped Local History entries. Click one to preview it, right-click to Compare with File or Restore Contents.
If you don't see a Timeline panel, confirm workbench.localHistory.enabled is true in Settings.
If the file was NEVER saved: the Backups folder
Brand-new, never-saved editors don't have Local History — their text lives in the hidden Backups folder instead:
- Windows:
%appdata%\Code\Backups - macOS:
~/Library/Application Support/Code/Backups - Linux:
~/.config/Code/Backups
Inside Backups you'll find folders named with a hash per workspace. Open workspaces.json in that folder to match a hash to your project path. The backup files inside hold your unsaved text as plain content — open them in any editor and copy it out.
Restore cleanly
- Copy the recovered text into a new file and save it under a real name before editing further.
- If you use the Insiders build, the path is
Code - Insidersinstead ofCode. - Enable Hot Exit (Settings → search
files.hotExit, set toonExitAndWindowClose) so VS Code always keeps unsaved state next time. - Turn on Auto Save (Settings →
files.autoSave→afterDelay) to stop relying on recovery at all.
If the backup file is empty or missing
If the Backups subfolder is gone or holds empty files, the editor was likely never dirtied long enough to flush a backup. Before giving up: close VS Code completely, make a copy of the whole Backups directory (so nothing overwrites it), then search your drive for recently-modified files matching your content — these often sit beside the editor's temporary (.tmp/.temp) files, so widen the filter to include those extensions. Cloud-synced folders (OneDrive, Dropbox, iCloud) sometimes keep their own version history for the saved file — check the provider's "version history" too.
FAQ
Where does VS Code store unsaved files?
Two places. Files you saved at least once are snapshotted by Local History (viewable in the Timeline panel). Files you never saved live in a hidden Backups folder: %appdata%\Code\Backups on Windows, ~/Library/Application Support/Code/Backups on macOS, or ~/.config/Code/Backups on Linux.
I closed VS Code without saving — is my work gone?
Usually not. Reopen VS Code; it restores the last session with unsaved tabs. If that fails, check the Timeline panel for a Local History snapshot (for saved files), or open the Backups folder and copy your text out (for never-saved files) before doing anything else.
What is the Timeline / Local History in VS Code?
Local History is a built-in feature (on by default since v1.66) that automatically saves timestamped snapshots of each file as you edit and save. Open the Timeline panel in the Explorer sidebar, pick an entry, and choose Restore Contents to roll back to it.
How do I match a backup folder to my project?
Open workspaces.json inside the Backups folder — it lists each workspace's directory path next to its hash, so you can find the subfolder that belongs to your project.
How do I stop losing unsaved VS Code work in future?
Enable Hot Exit (Settings → files.hotExit → onExitAndWindowClose) so VS Code preserves unsaved editors when you close it, and turn on Auto Save (files.autoSave → afterDelay) so your files are written to disk automatically.
Does Local History work for a file I never saved?
No. Local History only snapshots files that exist on disk. A brand-new editor you never saved has no Local History entry — recover it from the Backups folder instead.
Other file types explained
- Microsoft Edge Download Stuck or Not Finishing — How to Fix It
- Recover an Unsaved File in Sublime Text After a Crash
- Is a .crdownload File Safe to Delete? (Unfinished Chrome Downloads)
- .swp vs .swo — What's the Difference? (Vim Swap Files)
- Is desktop.ini a Virus? Is It Safe to Delete?
- Are .dmp Files Safe to Delete? (Memory Dumps)
- Are .log Files Safe to Delete?
- Is Thumbs.db a Virus? Is It Safe to Delete?