To close a folder in VS Code, use File > Close Folder. The keyboard version is Ctrl+K F on Windows and Linux, or Cmd+K F on a Mac.
VS Code itself stays open. The Explorer goes blank, and you can open the next project in the same window without restarting anything.
Single folders and multi-root workspaces both use this command. When a workspace is loaded, the VS Code documentation calls it Close Workspace instead, but underneath it’s still workbench.action.closeFolder.
How to close a folder in VSCode

Run File > Close Folder. The folder is removed from the window, the Explorer empties, and the editor keeps running.
Any of these gets you there:
- Open the File menu and click Close Folder.
- Press Ctrl+K, release, then F (Cmd+K, then F on macOS).
- Open the Command Palette, type close folder, and pick the matching command.
I use the shortcut, because once your fingers know it nothing is faster. The menu is easier to remember if you only close folders now and then. And the palette is the fallback that keeps working after you’ve remapped the shortcut and forgotten what you changed it to.
Closing a folder from the File menu
Click File in the top bar and pick Close Folder. The project goes away, the editor stays open, and you land on the Welcome tab.
If a .code-workspace file is open, the entry reads Close Workspace instead. With a single folder it says Close Folder.
Closing a folder with the keyboard shortcut
Per the VS Code default keyboard shortcuts reference, the binding is Ctrl+K F on Windows and Linux and Cmd+K F on macOS.
This one is a chord, which trips people up. You press Ctrl+K, let go of both keys, and then press F by itself.
Keep holding Ctrl when you hit F and you get Ctrl+K Ctrl+F instead. That’s Format Selection, a different command entirely.
Other everyday bindings are collected in this VS Code workflow cheat sheet.
Closing a folder from the Command Palette
- Press Ctrl+Shift+P (Cmd+Shift+P on macOS)
- Type “close folder” and select the matching command
- Press Enter
The label isn’t consistent between guides. Some show File: Close Folder, others Workspaces: Close Folder. Type “close folder” and ignore whatever prefix is in front of it.
Changing the Close Folder shortcut
Open the Keyboard Shortcuts editor with Ctrl+K Ctrl+S, search for workbench.action.closeFolder, double-click the row, and press the keys you want.
Customized shortcuts end up in the keybindings.json file, so you can also write the change by hand:
{
"key": "ctrl+alt+shift+w",
"command": "workbench.action.closeFolder"
}Make sure no other command already uses that combination. Your own rules are added after the defaults and win over them, so if the keys were taken, the other command just loses its shortcut and nothing warns you about it. To check, right-click a row in the Keyboard Shortcuts editor and choose Show Same Keybindings.
What happens to the window and unsaved files after a folder closes?
Nothing on disk changes. Close Folder works on the window, not on the file system, so no file in the folder gets deleted or moved. The window just goes back to empty.
Unsaved edits are the part worth thinking about. VS Code puts a dot on the tab of any unsaved file, and the Explorer view shows a badge with the number of unsaved files. Those edits are backed up automatically, but they aren’t saved to disk yet.
How that backup behaves is up to the files.hotExit setting:
- off means no backup, and VS Code asks what to do with unsaved files
- onExit runs hot exit when the application is closed, so when the last window closes on Windows and Linux, or when the Quit/Exit command runs (File > Exit, the Command Palette or the keyboard shortcut)
- onExitAndWindowClose also covers any window with a folder opened, whether or not it’s the last window
Here’s the annoying bit. As of the VS Code documentation read in November 2026, the hot exit section does not say what Close Folder does with dirty editors. I wouldn’t gamble on it. Save first, with Ctrl+S for one file or Ctrl+K S for all of them.
The docs do mention that all windows without folders opened are restored on the next launch. So the empty window Close Folder leaves behind can come back after a restart.
How does Close Folder differ from Close Workspace, Close Window and Close Editor?
It comes down to how much each one closes. Close Folder and Close Workspace take the project out of the window, Close Window shuts the window, and Close Editor only closes one tab. Pick the wrong one and you either leave the project open or lose more than you meant to.
| Action | Shortcut | Command ID | Scope |
|---|---|---|---|
| Close Folder | Ctrl+K F | workbench.action.closeFolder | Folder open in the window |
| Close Workspace | Ctrl+K F | workbench.action.closeFolder | Whole multi-root workspace |
| Close Window | Ctrl+Shift+W (Windows and Linux) | workbench.action.closeWindow | The VS Code window |
| Close Editor | Ctrl+W or Ctrl+F4 | workbench.action.closeActiveEditor | One editor tab |
| Collapse Folders in Explorer | None by default (button or Command Palette) | workbench.files.action.collapseExplorerFolders | Explorer tree display only |
Close Folder and Close Workspace share one command ID. The multi-root documentation describes a Close Workspace command that closes the active workspace, the same way Close Folder does for a single folder.
The window and editor IDs come from the default keybindings reference. The Windows shortcuts for those two come from published VS Code shortcut cheat sheets.
Closing versus collapsing
A lot of people searching “close a folder” actually want to collapse it. Collapsing folds the tree up while the project stays open. Collapse Folders in Explorer is in the Command Palette, and there’s also a button for it in the Explorer header.
If you just want a shorter file tree, collapse. Closing is for when you’re actually leaving the project.
Which one to use
To switch projects in the same window, run Close Folder and then open the next one. If you’re finished for the day, Close Window makes more sense.
Some guides describe a right-click Close Folder item or an x icon on Explorer folders. The multi-root documentation names one context-menu command for folders, Remove Folder from Workspace, and no per-folder Close Folder item.
How to remove one folder from a multi-root workspace
Right-click that folder’s root in the Explorer and choose Remove Folder from Workspace. The other roots stay loaded.
Close Workspace goes the other way and unloads all of them. The FAQ gives two options: close the workspace and open the folder directly, or remove the folder from the workspace.
Each root is stored as a path entry in the folders array of a .code-workspace file, which is created when the workspace is saved.
Untitled workspaces work differently. They exist only as long as the VS Code instance using them is open, and closing that instance prompts you to save the workspace if you plan to reopen it. The workspaces documentation adds that VS Code deletes untitled workspaces after asking for confirmation when the window closes. If the folder list took effort to put together, save the workspace file before closing anything.
And when only one root is left, just close the workspace. Removing the last folder is the long way around.
Closing a folder in Remote – SSH, WSL and Dev Containers windows
In a remote window you probably want File > Close Remote Connection, which disconnects from the host. The default configuration has no keyboard shortcut for this command, so the File menu is the reliable route.
Close Folder on its own only clears the folder from the window. Afterwards, look at the status bar. It shows which host you’re connected to, and clicking it while connected lists the remote commands.
- With Remote – SSH, Close Remote Connection disconnects from the host, and exiting VS Code closes the connection too.
- The WSL tutorial ends a session with File > Close Remote Connection, which takes you back to running VS Code locally. The WSL documentation also shows a WSL indicator in the bottom left corner and a WSL: Reopen in Windows command that opens the current input in a local window.
- In Dev Containers, closing VS Code shuts down the containers you connected to, unless “shutdownAction”: “none” sits in devcontainer.json.
The File menu entry is documented on the SSH and WSL pages. In a container window, open the File menu and check that it’s there before relying on it. The full SSH workflow is laid out in this Remote – SSH walkthrough.
Something that catches people out: a remote window left open when you quit can come back on the next launch. A Qiita write-up describes VS Code reconnecting to the previous folder and SSH session automatically after a restart. The startup section below deals with that.
How to reopen a folder you closed
File > Open Recent is the quickest way back. Right after Close Folder, the empty Explorer also shows Open Folder and Open Recent buttons.
| Method | Where | Fits when |
|---|---|---|
| Open Recent | File menu, Ctrl+R by default | The folder was open recently |
| Open Folder | File menu, Ctrl+K Ctrl+O | The folder is not in the recent list |
| code . | Terminal, project directory | A shell is already open there |
Opening VS Code from the terminal skips the menus. The command line documentation says to navigate to the project folder and run code followed by a dot.
A couple of flags change which window you end up in. -r forces the folder into the last active window, while -n opens a new session instead of restoring the previous one.
The folder reopens the way you left it, tabs and layout included, because VS Code stores UI state per workspace. Usually that’s what you want. Not always, though (more on that further down).
On trust prompts: as of the Workspace Trust documentation read in November 2026, a new folder opens in Restricted Mode with a trust banner instead of an upfront dialog. If you’d rather be asked, set security.workspace.trust.startupPrompt to once, and VS Code asks the first time a distinct folder or workspace opens.
The built-in File: Clear Recently Opened command empties the whole Open Recent list. To drop a single entry, hover over it in the Open Recent picker (Ctrl+R) and click its Remove from Recently Opened (x) button.
How to stop VSCode from reopening the last folder at startup
Set window.restoreWindows to “none”. VS Code then never reopens any windows and always starts with an empty instance.
You can open settings.json and add the line directly:
{
"window.restoreWindows": "none"
}“none” is pretty blunt, though, and the setting has other values that might suit you better:
- none reopens nothing and starts empty
- one reopens the last opened window
- folders only restores windows that had folders opened, so empty windows get dropped
- all restores every window
- preserve always reopens all windows, even when VS Code is asked to open a specific file or folder (for example from the terminal)
If you close folders often, I’d go with folders. Empty windows stop coming back, and your real projects still do.
Which value is the default
It’s “all”. The June 2017 release (version 1.14) introduced the setting with “one” as the default, and the January 2020 release (version 1.42) changed it to restore all windows. Any guide that lists “one” was written before that change.
Open Settings and search restoreWindows to confirm what your installed version uses.
When “none” is not enough
A Stack Overflow answer warns that VS Code will still restore the workspace if it contained a tab with an unsaved file. So save everything before closing.
Tabs are the other problem. One Codidact user reports that with files.hotExit set to “off” and restoreWindows set to “none”, VS Code still left remembered tabs and unfolded folders. That looks contradictory until you remember restoreWindows only decides which windows launch. It has nothing to do with what a folder looks like when it opens.
Reopening a folder always restores its stored UI state, so closing every tab before you close the folder is the only clean reset. Turning files.hotExit off drops the backup of unsaved edits, so only do that if losing them is acceptable.
FAQ About Closing a Folder in VSCode
Does closing a folder delete my files?
No. Every file stays on disk, because Close Folder only detaches the folder from the window.
The one thing VS Code does delete is an untitled workspace, and it asks you to confirm first when you close its window.
Why does the File menu say Close Workspace instead of Close Folder?
It follows whatever is loaded. You see Close Folder with a single folder and Close Workspace when a .code-workspace file is open.
Both entries run the same command, so the shortcut doesn’t change.
How do I clear the Open Recent list?
Run File: Clear Recently Opened from the Command Palette. It wipes the whole list, with no way to pick entries.
For a partial cleanup, remove individual entries with the x button in the Open Recent picker. A community script on GitHub can also strip out entries in bulk.
Does Cmd+W close the folder on macOS?
No. Cmd+W is bound to closing editors and windows. Close Folder keeps its own chord, Cmd+K and then F.
Switching Projects Faster in VSCode
My usual way to switch projects is Close Folder followed by Open Recent, which means Ctrl+K F and then Ctrl+R, the default Open Recent binding.
Get the Ctrl+K F chord into muscle memory before anything else. Picking the next folder with Ctrl+R comes easily after that. Leave the window.restoreWindows change to folders for last, since it changes launch behavior for every project and not just the one in front of you.
Extensions can get in the way here. If one registers a chord starting with Ctrl+R, the shortcut stops working, because VS Code waits for the second key. Check the Keyboard Shortcuts editor for conflicts.
Keep in mind that the folders value brings back every window that had a folder open, tabs included, at launch. A blank start needs “none” instead, which costs you one Open Recent pick per session. I think that’s worth it, but plenty of people would disagree.
Other launch options sit among the many VS Code settings.
- How to Redo in VS Code (Shortcuts and Fixes) - December 5, 2026
- Scaling Customer Support Without Losing Quality: A Practical Guide for Growing Companies - December 5, 2026
- Top MySQL CDC Tools for Streaming Changes to a Data Warehouse - December 4, 2026



