How to prevent Visual Studio Code from always reopening the previous files or folders?

Visual Studio-Code

Visual Studio-Code Problem Overview


Visual Studio Code always seems to remember my session and reopen the files and/or projects that were open the last time I used it. It obviously behaves correctly when running it from the command line with a file or folder supplied, but when opening from a taskbar shortcut, I'd like it to default to an empty environment.

Is there any way to change this behavior?

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

You can also go into your settings and use the following:

"window.reopenFolders": "none"

which will not reopen the folders you were working on when you closed the editor. The other options are one (the default) and all.

Edit 2017-11-09:

The option is now changed in latest versions.

"window.restoreWindows": "none"

See Mathieu DOMER's answer.

Edit 2018-09-12:

Another setting related to this is the hotExit setting. This has been discussed in this answer to a related question. To prevent reopening and remembering unsaved files, you can set this to:

"files.hotExit": "off"

But from the test I've made, when the window.restoreWindows setting is set to none, this is not needed. I haven't tested every possible combination, so YMMV.

And to answer a question in the comments, to edit the settings, you have to open the settings file. Some documentation can be found here (at least on the date I am writing this).

Edit 2022-03-16:

If you prefer using a GUI to change the settings, see D'Arcy Rittich's answer.

Solution 2 - Visual Studio-Code

In VS Code:

  • for Windows/Linux Ctrl+, (or choose File/Preferences/Settings) to open the settings page.
  • for Mac āŒ˜+, (or choose Code -> Preferences -> Settings) to open the settings page.

then type restoreWindows in the Search settings input to filter for this setting. Set it to none and restart the browser.

restoreWindows

Solution 3 - Visual Studio-Code

With latest update, it seems that the parameter has changed, now use:

"window.restoreWindows": "none"

Solution 4 - Visual Studio-Code

You can add the -n option to the startup of VS Code and it will always start with an empty window, not restoring your previous session.

Solution 5 - Visual Studio-Code

01 December 2018

This works for me. i.e. "C:\Users\Sampath\AppData\Local\Programs\Microsoft VS Code\Code.exe" -n

enter image description here

Solution 6 - Visual Studio-Code

Below worked for me

Right-click on Shortcut and add --disable-gpu to Target as per screen shot.

enter image description here

Solution 7 - Visual Studio-Code

If "window.restoreWindows": "none" not solve the problem,
then try to run code as root -> sudo code --user-data-dir code files and restart code normally without root.

Solution 8 - Visual Studio-Code

For me, none of above is working while I'm trying to close "dirty" unsaved files which I accidentally edited 1000 files and wanted to ignore saving all of them.

My fix was adding this line into settings.json:

    "files.hotExit": "off"

Open up vscode, close vscode and just click the confirmation button to close all of the files without saving.

Then open back vscode and boom.. no more unsaved files being shown.

Solution 9 - Visual Studio-Code

For me the only solution that worked was to go to the solution root and delete the .vs folder.

Solution 10 - Visual Studio-Code

I reinstalled Visual Studio Code by downloading the latest update. I did not have to uninstall the previously installed Code. It work ok for me now.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatt PetersonView Question on Stackoverflow
Solution 1 - Visual Studio-CodeghleclView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeD'Arcy RittichView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeMathieu DOMERView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeBenjamin PaseroView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeSampathView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeVatsal ShahView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeKhaled AlamView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeWak JokoView Answer on Stackoverflow
Solution 9 - Visual Studio-Codeuser14756878View Answer on Stackoverflow
Solution 10 - Visual Studio-CodeMurali kondapiView Answer on Stackoverflow