Tramp wsl method

2026-Apr-02

Emacs has a built-in thing called “tramp” that lets you open files over various transports like ssh, docker, and sudo.

It doesn’t have a built-in method to use wsl files, despite Microsoft Copilot insisting this exists.

Here’s how you can make it exist:

(use-package tramp
  :config
  ;; This uses a program called pipetty, from the colorized-logs package in Debian
  (add-to-list 'tramp-methods
               `("wsl"
                 (tramp-login-program "wsl.exe")
                 (tramp-login-args (("-d" "%h") ("--user" "%u") ("pipetty" "%l"))))

  ;; A version that uses the less-obscure script
  (add-to-list 'tramp-methods
               `("wsl-script"
                 (tramp-login-program "wsl.exe")
                 (tramp-login-args (("-d" "%h") ("--user" "%u") ("script" "-qc" "%l" "/dev/null"))))
  

This works exactly like you would expect. For instance, I can now open /wsl:Debian:/etc/profile.

What makes this cool is that now I can use eshell, grep, and other stuff running inside wsl2. I can do entire builds inside wsl, with emacs running on the Windows “host”, allowing me to juggle multiple wsl2 distros.

But it won’t pass your SSH agent. More on that in another post.