Vscode: Allow to open a workspace without restoring any state

Created on 14 Mar 2017  路  21Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.10.2
  • OS Version: OS X 10.11.6

Is it possible to init the code editor from terminal code . with a new session?
code . -n doesn't work, it still remembers the last files and project tree I had open.

feature-request workbench-state

Most helpful comment

I think that we are missing the option to skip restoring previous session.

  • The setting "window.restoreWindows" is applied only if you trigger VS Code restart. It means it closed and reopened it, but the manual close window and start process is not a restart process. This parameter is only when VS Code restart itself (eg. during the update).
  • The setting "workbench.editor.restoreViewState" is about behaviour on opening previously closed file. It can restore view of re-opened file. Like put you in the same place where you been last time when file was open.
  • The setting "files.hotExit" is almost about sessions but only for not saved files. This feature can save those files internally and restore them when VS Code is started again. It prevents from question do you want to save this file.

Is there any option to disable remembering the last opened session?

All 21 comments

@vtimbuc code -n should work but since you tell Code to open the current folder (via .), it will restore the session. So no, there is no way for a clean session when opening a specific folder currently.

@bpasero Yeah, an option to start a clean project session would be great. Could you point me where the session is stored on OS X, I could set that folder to read-only as a temporary solution. Thanks

@vtimbuc that will not be possible I fear.

I have this issue in Linux too. No matter what i do, if i open via the terminal with code . in my project directory. The previous session is restored.

I noticed other issues with the same problem reported like https://github.com/Microsoft/vscode/issues/41039 and https://github.com/Microsoft/vscode/issues/42062 that were autoclosed.

"window.restoreWindows": "none" is still not effective when opening from the terminal.

Is there a fix for this?

What makes this a feature-request (looking at label on this issue) rather than a bug? The feature is there. It just doesn't work from the command line.

Also posted on stackoverflow looking for resolution or work around.

Actually, this occurs for me when opening VSCode from the dock in macOS. I created a screencast here that shows the behavior, and I open my preferences at the end to show that restoreWindows is none.

I would definitely call this a bug, and not a feature request. If you turn off window restore, it should be off, regardless of how you open the app.

On Windows, the same behaviour happens. Even running:
"C:\Program Files\Microsoft VS Code\Code.exe" -n
will not start a clean session for me.

Even if this were working, I would expect the "window.restoreWindows": "none" to override whatever rule exists.

This really hampers productivity, as opening a random file on disk will open the file together with the previous workspace I was working in.

Same when open code from the Context Menu in Window. I would expect in that case that a new clean instance and not two Windows of which one shows the last session is opened.

Hi, this issue is still valid for clean installation of Visual Studio Code in version 1.22.2.
Can you estimate when it will be fixed?

I'm starting the app from Menu Start in Windows 10.

I'm still seeing this in 1.25.1. Are there any plans to implement this? Or, at least, document a workaround? Even letting us know where the session information is stored would be handy. (As mentioned by @vtimbuc above).

Thanks.

Hi,

"window.restoreWindows": "none"

Still rarely works for me on the latest build. It just opens the last folder. Sometimes it randomly does work though.

On Arch Linux, latest VS build.

Any progress on this? If restoreWindows is set to none, then there should be no windows restored, irrespective of how VSCode is opened.

I have the same problem.

"workbench.editor.restoreViewState": false

"files.hotExit": "off"

"window.restoreWindows": "none"

and when i reopen folder ( CTRL+K + O ), still all files are open

Please fix it

I think that we are missing the option to skip restoring previous session.

  • The setting "window.restoreWindows" is applied only if you trigger VS Code restart. It means it closed and reopened it, but the manual close window and start process is not a restart process. This parameter is only when VS Code restart itself (eg. during the update).
  • The setting "workbench.editor.restoreViewState" is about behaviour on opening previously closed file. It can restore view of re-opened file. Like put you in the same place where you been last time when file was open.
  • The setting "files.hotExit" is almost about sessions but only for not saved files. This feature can save those files internally and restore them when VS Code is started again. It prevents from question do you want to save this file.

Is there any option to disable remembering the last opened session?

@vtimbuc (and others), is this "just" the restoring of opened editors or really all state we have associated with a window? There is a ton of stuff we store per window on shutdown and restore on the next startup (to give a concrete example: the breakpoints that you set in editors if any).

It would be relatively easy to add a setting to not restore editors, but I am not sure really starting without any state makes a lot of sense.

@bpasero for me an option to clear all state associated with a window would be great. I like to start fresh when I open my editor in the morning. For me an option we could pass when opening from the command line would be enough, such as code . --no-state. Thanks

Ok updating to reflect the intent. Keep in mind though that this will mean that everything is fresh, e.g. you will get notifications popping up that you previously maybe configured to "Do not show again".

I am of the same opinion as @vtimbuc. A completely fresh start would be really great. I need it too.
The command line option will be better than nothing, but if possible it would be good to see it in the settings (better for Win users).

This is a feature I'd love as well鈥擨 have really bad ADHD and have VSCode workspaces for different projects that I launch using an Alfred shortcut; when a bunch of files from a previous coding session pop up, it's super distracting and disrupts my workflow. This is really maddening and makes VSCode almost unusable for me. I just made the switch from Sublime Text, which has had this feature for 7+ years. ;)

Can we call this an Accessibility feature request?

This would be quite handy for an extension I'm a partner on.

cc @pschellenbach

For context, the extension allows for remote connectivity and provides some file system knowledge by constructing a workspace that is used to plumb up some essential things. It would be handy to allow the extension to intentionally launch and re-use that workspace to maintain the plumbing, but set aside any previously opened files.

So currently my workspace has 284 open editors, and will cause vscode to hang. The lack of this feature (and trying to figure out a way around it) has cost me a few hours. Having found this open issue - and no references to where this state is stored in a file (I've deleted a bunch of things but clearly not the correct ones!) - I maybe have to uninstall? Not sure. Anyway I am voicing my strong support for giving this issue attention. Thank you!

Ok, so if anybody comes by and has the same problem, at least I figured out finally where the state was living. On a Mac I did (and please, kids, don't do this at home unless you truly know what you're doing)

rm -rf ~/Library/Application\ Support/Code/User/workspaceStorage/*
rm -rf ~/Library/Application\ Support/Code/Backups/*

obvs this will kill any _other_ workspace data you have but really the learning her for me was that both of the above directories were involved.

Was this page helpful?
0 / 5 - 0 ratings