Steps to Reproduce:
code and it says Command is only available in WSL or inside a Visual Studio Code terminal.
Does this issue occur when you try this locally?: No
Does this issue occur when you try this locally and all extensions are disabled?: Yes
Having this same problem
I have found that the terminal work if from the terminal execute the next command for open vscode, you could try with code --verbose
➜ qr_hfe git:(master) code -s
Unable to connect to VS Code server.
Error in request
➜ qr_hfe git:(master) code -v
1.45.1
5763d909d5f12fe19f215cbfdd29a91c0fa9208a
x64
➜ qr_hfe git:(master) code --verbose
Ignoring option verbose: not supported for code.
At least one file or folder must be provided.
I use the following workaround
cat /usr/bin/vscode_fix_path
#!/bin/bash
OLD_CSUM=`echo $PATH | grep -oP "(?<=\/home\/$USER\/.vscode-server-insiders\/bin\/).*?(?=\/bin)" | head -1`
NEW_CSUM=`ls -tr /home/$USER/.vscode-server-insiders/bin/ | tail -n 1`
export PATH=`echo $PATH | sed "s/$OLD_CSUM/$NEW_CSUM/g"`
export GIT_ASKPASS=`echo $GIT_ASKPASS | sed "s/$OLD_CSUM/$NEW_CSUM/g"`
export VSCODE_GIT_ASKPASS_MAIN=`echo $VSCODE_GIT_ASKPASS_MAIN | sed "s/$OLD_CSUM/$NEW_CSUM/g"`
export VSCODE_GIT_ASKPASS_NODE=`echo $VSCODE_GIT_ASKPASS_NODE | sed "s/$OLD_CSUM/$NEW_CSUM/g"`
export VSCODE_IPC_HOOK_CLI=`ls -tr /tmp/vscode-ipc-* | tail -n 1`
cat /usr/bin/vscode_shell
#!/bin/zsh
tmux new-session -A -D -s <SESSION>
tmux list-windows -t <SESSION> | cut -d: -f1|xargs -I{} tmux send-keys -t $session:{} ENTER "source /usr/bin/vscode_fix_path" ENTER
return 0
And in remote ssh settings
"terminal.integrated.shell.linux": "/usr/bin/vscode_shell",
I have the same problem but with Extension/Connection Type: Containers. I'm happy to open up a different issue if anyone feels it is unrelated. I imagine it's the same root problem, though.
I had a similar problem with remote WSL (code either wouldn't work or would open in a new window) which is also fixed by resetting the environment variables. I found that in some cases @PavanNikhilesh's script didn't work due to it finding the wrong files but I think I found a pretty simple solution for updating the environment variables.
In .tmux.conf:
# update VSCODE variables from integrated terminal so that `code` command opens in current window
set-option -ga update-environment ' VSCODE_GIT_ASKPASS_NODE VSCODE_GIT_ASKPASS_MAIN VSCODE_IPC_HOOK_CLI PATH GIT_ASKPASS'
vscode_fix_path.sh
#!/bin/bash
export "`tmux showenv PATH`"
export "`tmux showenv GIT_ASKPASS`"
export "`tmux showenv VSCODE_GIT_ASKPASS_MAIN`"
export "`tmux showenv VSCODE_GIT_ASKPASS_NODE`"
export "`tmux showenv VSCODE_IPC_HOOK_CLI`"
update-environment will make sure tmux has the right environment when making new windows/panes and then we can use the previous idea of having a script update the already running shells.
This is a pretty common problem for various SSH variables as well so there's a bit written about it.
I just run the script myself since I have persistent applications and it's not too hard to fix the shells when I notice a problem.
I came up with a reliable workaround:
In the login shell (i.e. not within tmux), run
nc localhost 9876 -lk | while read filename; do code "$filename"; done &
In any of your tmux windows, you can run
echo filename | nc localhost 9876
You can streamline this by adding #1 to your bashrc, and creating an alias for #2.
The biggest caveat is that the filename needs to be relative to your login shell's current directory.
Most helpful comment
I had a similar problem with remote WSL (
codeeither wouldn't work or would open in a new window) which is also fixed by resetting the environment variables. I found that in some cases @PavanNikhilesh's script didn't work due to it finding the wrong files but I think I found a pretty simple solution for updating the environment variables.In .tmux.conf:
vscode_fix_path.sh
update-environmentwill make sure tmux has the right environment when making new windows/panes and then we can use the previous idea of having a script update the already running shells.This is a pretty common problem for various SSH variables as well so there's a bit written about it.
I just run the script myself since I have persistent applications and it's not too hard to fix the shells when I notice a problem.