How to clear the Cache in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
5 min

banner

# Table of Contents

  1. Clearing VS Code editor history
  2. Clearing VS Code search history
  3. Clearing the Cache in Visual Studio Code
  4. Clearing the Visual Studio Code cache on Windows
  5. Clearing the Visual Studio Code cache on macOS
  6. Clearing the Visual Studio Code cache on Linux
  7. Clearing the Local Storage cache in Visual Studio Code

# Clearing VS Code editor history

When you modify a file, a copy of the old contents is kept in local history.

This allows you to compare a file with an older version from history, however, it can sometimes slow VS Code.

If you need to clear the editor history:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Clear editor history and select the option.

clear editor history

Here is a short gif that demonstrates the process of clearing the editor history.

clear editor history

This option is especially useful for clearing deleted or moved files.

# Clearing VS Code search history

Visual Studio Code also keeps track of your searches.

To clear the search history:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type "Clear search history".

clear search history

  1. Select Search: Clear Search History.

Here is a short GIF that demonstrates the process.

clear search history

The same approach can be used to clear your command history.

vscode clear other history

Once you start typing clear after you press Ctrl + Shift + P, the options are shown.

# Clearing the Cache in Visual Studio Code

The article has instructions on how to delete your VS Code cache on Windows, macOS and Linux.

VS Code has 2 folders that you have to delete Cache and CachedData.

# Clearing the Visual Studio Code cache on Windows

On Windows, the Cache and CachedData folders are located under:

  • C:\Users\<YOUR_USER>\AppData\Roaming\Code

Make sure to replace the YOUR_USER placeholder with your actual username.

delete contents of cache cachedata

You can also access the folder by pasting %APPDATA%\Code in Explorer.

%APPDATA%\Code is the equivalent of the previous path.

Once you find the directory, open the CachedData folder and delete its contents.

delete cached data contents

You can delete all folders in the CachedData directory to clear the cache.

Then go up one directory and open the Cache directory.

If your Cache directory contains a CachedData directory, open the CachedData directory and delete its contents.

Otherwise, delete the contents of the Cache directory.

delete all files in cache directory

Alternatively, you can use a command to delete the contents of the CachedData and Cache directories.

Open the command prompt (CMD) application and run the following commands.

The following command deletes the contents of the Cache directory.

cmd
del /S "%APPDATA%\Code\Cache\*"

windows delete cache command line

Note that you will get prompted multiple times and you have to type Y and press Enter.

If you want to delete the folder without a prompt for confirmation, use del /F /Q.

cmd
del /F /Q /S "%APPDATA%\Code\Cache\*"

The following command deletes the contents of the CachedData directory.

cmd
del /S "%APPDATA%\Code\CachedData\*"
Note that you will get prompted multiple times and you have to type Y and press Enter.

If you want to delete the contents without a prompt for confirmation, use del /F /Q.

cmd
del /F /Q /S "%APPDATA%\Code\CachedData\*"

Once you clear the cache, make sure to restart VS Code by closing it completely and reopening it.

# Clearing the Visual Studio Code cache on macOS

On macOS, the Cache and CachedData folders are located under:

  • $HOME/Library/Application\ Support/Code

You might also access the path as:

  • ~/Library/Application\ Support/Code

The easiest way to clean the cache on macOS is to use the rm command.

You can first print the contents of the directories before deleting them.

Open a bash shell and run the following commands.

shell
echo ~/Library/Application\ Support/Code/Cache/* echo ~/Library/Application\ Support/Code/CachedData/*

The following command deletes the contents of the Cache directory.

shell
rm -rf "~/Library/Application\ Support/Code/Cache/*"

You might get prompted. Type y and press Enter if you do.

The following command deletes the contents of the CachedData directory.

shell
rm -rf "~/Library/Application\ Support/Code/CachedData/*"

Once you clear the cache, make sure to restart VS Code by closing it completely and reopening it.

# Clearing the Visual Studio Code cache on Linux

On Linux, the Cache and CachedData folders are located under:

  • $HOME/.config/Code

linux location of cache

One way to delete the contents of the directories is to enter the following commands in your terminal.

shell
cd $HOME/.config/Code nautilus .

The commands will open the Code directory.

You can then open the Cache directory and delete its contents and then open the CachedData directory and delete its contents.

delete cache contents

Alternatively, you can use a command.

You can first print the contents of the directories before deleting them.

Open a bash shell and run the following commands.

shell
echo $HOME/.config/Code/Cache/* echo $HOME/.config/Code/CachedData/*

The following command deletes the contents of the Cache directory.

shell
rm -rf "$HOME/.config/Code/Cache/*"

linux delete cache directory

You might get prompted. Type y and press Enter if you do.

The following command deletes the contents of the CachedData directory.

shell
rm -rf "$HOME/.config/Code/CachedData/*"

linux delete cached data directory

Once you clear the cache, make sure to restart VS Code by closing it completely and reopening it.

# Clearing the Local Storage cache in Visual Studio Code

Visual Studio Code also stores information about which tabs were open before you closed the editor.

This sometimes causes issues, such as the editor always opening multiple projects at launch.

To clear the local storage:

  1. On Windows and Linux:
  • Press Alt to show the top bar and click on Help.

  • Click "Toggle Developer Tools".

  1. On macOS:
  • Click on Help in the top bar and click "Toggle Developer Tools".

toggle developer tools

On both platforms, enter the window.localStorage.clear() command in your developer tools.

shell
window.localStorage.clear()

vscode clear local storage

Once you issue the command, restart VS Code.

You can also clear the local storage in Visual Studio code by issuing a command.

The location of the local storage directory is:

  • on Windows: %APPDATA%\Code\Local Storage
  • On macOS: ~/Library/Application\ Support/Code/Local\ Storage
  • On Linux: $HOME/.config/Code/Local\ Storage

If you need to delete the contents of the local storage directory on Windows, open CMD and issue the following command:

cmd
# Windows del /S "%APPDATA%\Code\Local Storage\*"

delete local storage on windows

Make sure to type y and press Enter when you get prompted for confirmation.

To delete the contents of the local storage directory on macOS, issue the following command.

shell
# macOS rm -rf "~/Library/Application\ Support/Code/Local\ Storage/*"

Make sure to type y and press Enter when you get prompted for confirmation.

To delete the contents of the local storage directory on Linux, issue the following command.

shell
# Linux rm -rf "$HOME/.config/Code/Local\ Storage/*"

delete local storage directory on linux

Make sure to type y and press Enter when you get prompted for confirmation.

Once you delete the local storage directory, close VS Code completely and then reopen it.

I've also written an article on how to solve the issue where VS Code takes up too much memory or CPU.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.