Unable to `snap remove --purge code` on Ubuntu 22.04.4 LTS without manually removing `code` directories in `/home/<user>/snap/code`

I’ve installed a bunch of programs with sudo snap install <app> <options> This is the SHELL output displayed after running snap list.

Name                    Version                     Rev    Tracking       Publisher      Notes
bare                    1.0                         5      latest/stable  canonical✓     base
code                    eaa41d57                    166    latest/stable  vscode✓        disabled,classic
core                    16-2.61.4-20240607          17200  latest/stable  canonical✓     core
core18                  20240612                    2829   latest/stable  canonical✓     base
core20                  20240416                    2318   latest/stable  canonical✓     base
core22                  20240419                    1439   latest/stable  canonical✓     base
core24                  20240528                    423    latest/stable  canonical✓     base
discord                 0.0.63                      203    latest/stable  snapcrafters✪  -
gnome-3-28-1804         3.28.0-19-g98f9e67.98f9e67  198    latest/stable  canonical✓     -
gnome-3-34-1804         0+git.3556cb3               93     latest/stable  canonical✓     -
gnome-42-2204           0+git.510a601               176    latest/stable  canonical✓     -
gnome-46-2404           0+git.1f00542               42     latest/stable  canonical✓     -
gtk-common-themes       0.1-81-g442e511             1535   latest/stable  canonical✓     -
hello-world             6.4                         29     latest/stable  canonical✓     -
mesa-2404               24.0.5                      44     latest/stable  canonical✓     -
postman                 10.24.26                    254    v10/stable     postman-inc✓   -
slack                   4.39.95                     158    latest/stable  slack✓         -
snap-store              41.3-77-g7dc86c8            1113   latest/stable  canonical✓     -
sublime-text            4180                        177    latest/stable  snapcrafters✪  classic
wine-platform-6-stable  6.0.4                       19     latest/stable  mmtrt          -
wine-platform-runtime   v1.0                        385    latest/stable  mmtrt         

This is the output of running the following command sudo snap remove --purge code

remove data for snap "code" (166) (failed to remove snap "code" base directory: remove /home/<user>/snap/code: directory not empty)

This is the output of running tree -L 1 snap/code/ which is consistent with the 166 error message about code directory being not empty.

snap/code/
└── 157

1 directory, 0 files

FYI if I mv snap/code/ snap/code.bak and run sudo snap remove --purge I can remove the application without any problem.

Is this the default behaviour of snap? Perhaps snap remove [--purge] is broken? I cannot think of any reason why removing the code directory should be any problem for the script unless I’m missing something.