Ryan Barrett's blog

emacsclient in TRAMP remote shells

I recently started running shells inside
Emacs via
shell mode,
including ssh sessions to remote hosts using
TRAMP. I’m pretty happy with it so far,
but one thing that didn’t work out of the box was emacsclient. Ideally it would
open files in the local Emacs with TRAMP, but there’s no obvious way for
an emacsclient running remotely to connect to the local Emacs’s server.

However, there are lots of variations on
anotsoobviousway. If
you run the Emacs server over TCP instead of a local socket, and use the ssh
-R option to set up a reverse port forward, and copy the server file to the
remote host so that emacsclient can use it, you actually can connect back to the
local Emacs server!

you’re right, opening files manually from the shell buffer does automatically use TRAMP. this is for using emacsclient, which you usually set to $EDITOR so that programs will use it to open files automatically – for example, commit log messages.