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?
Untitled-1
tab. It drives me nuts
"window.reopenFolders" : "all"
opens every single file no matter if it is in the currently active directory or not. Sadly it seems that VS code still doesn't support having multiple active directories because of all that "active directory = workspace".
"window.reopenFolders" : "all"
. To test, 1) go to File>Close Folder
, 2) drag and drop any random file into VS Code, 3) go to File>Exit
, 4) Relaunch VS Code, 5) Notice you get a blank VS Code editor again. In order to restore sessions, you need to have an active directory open. Any session, regardless of file location, will be remembered as long as you have an active directory. Btw, you can install Project Manager
extension to jump between multiple active directories.
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"
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.
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 VS Code.
https://i.stack.imgur.com/TccTQ.png
With latest update, it seems that the parameter has changed, now use:
"window.restoreWindows": "none"
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.
code --help
displays -n, --new-window Force to open a new window.
) but it still reopens all previous windows. I think it's only meant to do something meaningful when the program is already running.
01 December 2018
This works for me. i.e. "C:\Users\Sampath\AppData\Local\Programs\Microsoft VS Code\Code.exe" -n
https://i.stack.imgur.com/tcUve.png
Below worked for me
Right-click on Shortcut and add --disable-gpu to Target as per screen shot.
https://i.stack.imgur.com/SYKnG.png
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.
settings.json
?
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.
For me the only solution that worked was to go to the solution root and delete the .vs folder.
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.
Success story sharing
window.reopenFolders
as a setting option. Instead I havewindow.restoreWindows
code .
command. Always restores open editors and I can't stand it