Some options in order of recommendation:
Use custom directories for extensions and user data
Your best option is probably to tell VS Code to use custom paths for extensions and user data. This would work since it would be the extensions and cache folders that take up disk space, and since the cache folders are located under the user data folder.
You provide the custom paths as command line arguments when invoking VS Code. Using /mnt/extdir/vsc-ext/
and /mnt/extdir/vsc-user-data/
as examples for desired external directories, you'd use:
$ code --extensions-dir /mnt/extdir/vsc-ext/ --user-data-dir /mnt/extdir/vsc-user-data/ .
You can add an alias to your shell startup script to facilitate this:
alias code='code --extensions-dir /mnt/extdir/vsc-ext/ --user-data-dir /mnt/extdir/vsc-user-data/'
Then you can continue to use just e.g. code .
as usual, but have VS Code use the external directories for extensions and cache.
From the CLI documentation:
--extensions-dir <dir>
Set the root path for extensions. Has no effect in Portable Mode.
--user-data-dir <dir>
Specifies the directory that user data is kept in, useful when running as root. Has no effect in Portable Mode.
Just a side note: I ran the following to confirm that the cache folders are actually under the user data directory:
$ mkdir vs-user-data && code --user-data-dir vs-user-data . && sleep 3 && ls vs-user-data | grep -i cache
CachedData
Code Cache
GPUCache
Use portable mode
Using portable mode (documentation), all user data is stored in the installation directory, which is chosen by you.
This would probably work fine in your case, but a drawback would be a non-standard way for installation and making updating VS Code more cumbersome.
Use symlinks
That would probably work as well, but would be an inferior option. The other solutions given above are officially supported and more robust.