Cleaning up after Cursor & VS Code

The drive on my roof-top Pi (long story) was filling up and I couldn’t figure out why. It turns out that a lot of it was from the cruft left behind by VS Code and Cursor when I SSHed and did some remote editing. It looks like it keeps all of the old versions of the remote server installed.

You can just rm -rf * these directories, but then you have to redownload the extensions the next time you login. This Stack Overflow point me to this GitHub Gist:

#!/bin/bash
rm -rf ~/.cache 2> /dev/null

if [ ! -d ~/.vscode-server ]; then
  echo "\"~/.vscode-server\" does not exist."
  exit 0
fi

shopt -s extglob

rm -rf ~/.vscode-server/data/CachedExtensionVSIXs

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)

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")
  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

I just blew it all away because it didn’t need 4 older versions of the Claude extension. Anyhow, the point is clean up after VS Code based editors if you are doing remote work.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *