This is still the header! Main site

Emacs as the Best Remote Backend for Emacs

2026/12/05

Visual Studio Code has the cool feature of being able to work on remote hosts. Your GUI runs locally, but launches a backend process via ssh; you can open files quickly, run commands remotely, and generally pretend that you're working on that remote machine. Very convenient.

"Well, of course we have this in Emacs too", many might say. Of course we do! It's called "TRAMP"; see also Part 2 of the Not Using Terminals series. It can handle multiple backends; the typical way of it being used is via ssh: it logs in, fetches files, lists directories etc, and presents this as local files on the client.

It's flexible enough to do this with pretty much any host you encounter via ssh. It's armed with a gazillion regexes and special cases for some quite weird shells.

Is it as good as VS Code though?

Well yes, in theory. If you have infinite time. In practice... it's slow. Opening files takes seconds sometimes; yes it doesn't make new ssh connections every time, but... then we need to check whether the file is under version control? (Almost free locally!) Is any of the 8 levels of parent directories a Mercurial repo? how about SVN? Even if round trips are fast, it adds up.

VS Code gets around this by having a dedicated backend agent binary that it copies over & launches on the remote host. Instead of trying to use actual ssh commands each time to fetch info, the backend can just collect all of it & send it down in one go.

Now... could we do the same? Build a binary that we ssh'd over & used as an agent? TRAMP itself is very extensible; it can use e.g. PuTTYs plink, can talk via SFTP, it can even use Android ADB as its backend... we can write our own!

Except... it does sound like a lot of work; for all the possible systems we could be connecting to, we need to build a binary that collects info & translates it to something reasonably uniformly emacs-y, sending it over the wire in low-latency chunks. Also, even if we had such a thing, we'd need to install it everywhere! (Unlike bash, which is... just ubiquitous.)

If only there was a piece of software / programming language / shell that is available & easy to install on many platforms, and already has a good abstraction layer over directories / files / version control etc that's similar enough to those of Emacs; we could just write a smaller bit of code for it to serve as our Emacs backend.

Now... as for software that is similar to Emacs... well, how about Emacs itself?

TRAMP wants us to register a bunch of callbacks, "open this file" etc, which it swaps out under our actual client Emacs; that's how it pretends that files are local even though they're remote. They're the same shape as what Emacs actually does to local files. So... each time you have to e.g. list a remote directory, we can just stuff the request into a pipe almost as it is, send it over to a remote Emacs, which then lists the actual directory for us & sends over the response!

Meanwhile, the entire thing can still work over ssh. You can have your client Emacs use ssh + socat to dial into a UNIX domain socket that the server Emacs keeps open; this way, you don't even need to deal with silly TCP ports & nothing is open to the outside world.

Of course... implementing this is a Project. Optimally, we'd need responses to pre-fill caches that TRAMP already has on the client size, so that a stat on each file is not another round-trip. Running remote processes has its own tricks. I've had this idea years ago, but I haven't had the cycles to implement it. Overall, the amount of time this eventually took is...

... apparently, about 5 minutes of paying attention and... 30 minutes total? Given a running Emacs on both sides and the ability to ssh over to the other side, Gemini Neon hammered out about 1700 lines of rather reasonable-looking elisp that actually works; you can likely just point an LLM at this very post to make your own.

Humanity might not survive the next few years, but we do have some very nice things until then.