Skip to content

Instantly share code, notes, and snippets.

@eta-orionis
Forked from XDflight/README.md
Created August 8, 2026 13:42
Show Gist options
  • Select an option

  • Save eta-orionis/417489274c14cf2c49951bd372cad83f to your computer and use it in GitHub Desktop.

Select an option

Save eta-orionis/417489274c14cf2c49951bd372cad83f to your computer and use it in GitHub Desktop.
Remove cache and old extensions under "~/.vscode-server/" on your Linux server

If you often connect to your Linux server using VSCode, the "~/.vscode-server/" folder (and sometimes the ~/.cache/ folder too) can get very large because VSCode:

  1. Does NOT clean its download cache after installing extensions;
  2. Does NOT delete old extensions after updating them;
  3. Does NOT remove old VSCode servers after installing a new version.

If your server storage space is limited, you might consider cleaning "~/.vscode-server/" (and ~/.cache/) regularly using the bash script I wrote. Simply run the following command:

curl -sL https://gist.githubusercontent.com/XDflight/5f3509eb84fc282b88059c909036f5bc/raw/fe2a3e7dab19160c17efc7025d138f5350964c0f/clean_vscode-server.sh | bash -s

This command will automatically download and run the script for you.

I programmed this thing because CMU only provides each student 2GB of AFS cloud storage in normal circumstances, unless maybe the courses you take requested for more, and since I often use VSCode to connect to Virtual Andrew via SSH to do homework, my "~/.vscode-server/" gets too big now and then that I have to clean it manually to keep my storage usage within the quota. This script automates the process to make my life easier.

#!/bin/bash
# Discussions at:
# - https://gist.github.com/XDflight/5f3509eb84fc282b88059c909036f5bc
# - https://www.reddit.com/r/vscode/comments/1ocqftt/a_tool_that_helps_you_free_up_vscodeserver_if_you/
rm -rf ~/.cache 2> /dev/null
if [ ! -d ~/.vscode-server ]; then
echo "\"~/.vscode-server\" does not exist."
exit 0
fi
pkill -u "$USER" -f '\.vscode-server'
shopt -s extglob nullglob
rm -rf ~/.vscode-server/data/CachedExtensionVSIXs
rm -f ~/.vscode-server/.cli.*.log
if [[ -f ~/.vscode-server/cli/servers/lru.json ]]; then
SERVER_VERSION=$(grep -oE '[0-9a-f]{40}' ~/.vscode-server/cli/servers/lru.json | head -n1)
echo "[\"Stable-$SERVER_VERSION\"]" > ~/.vscode-server/cli/servers/lru.json
rm -rf ~/.vscode-server/cli/servers/Stable-!($SERVER_VERSION)
rm -f ~/.vscode-server/code-!($SERVER_VERSION)
else
rm -rf ~/.vscode-server/cli
rm -f ~/.vscode-server/code-*
fi
rm -rf ~/.vscode-server/extensions/*.vsctmp
declare -A exts
for lsout in $(cd ~/.vscode-server/extensions && ls -rvd */); do
ext_fullname=${lsout::-1}
ext_version=$(grep -oP '\-\d+\.\d+\.\d+' <<< "$ext_fullname")
# Skip extensions whose directory names do not end in semver
[[ -z "$ext_version" ]] && continue
ext_name=${ext_fullname/$ext_version}
ext_version=${ext_version:1}
if [[ -n "${exts[$ext_name]+isset}" ]]; then
rm -rf ~/.vscode-server/extensions/$lsout
else
exts[$ext_name]=$ext_version
fi
done
shopt -u extglob nullglob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment