[feat]: Add automatic port forwarding for SSH-connected projects
Feature Summary
Add automatic port forwarding for emdash projects accessed over SSH connections.
When a dev server or agent-started process listens on a remote port, emdash should detect it, create a local port forward automatically, and surface a clickable local URL in the UI, similar to VS Code Remote SSH.
Problem or Use Case
I often work on projects over SSH where dev servers run on the remote machine, usually binding to localhost, 127.0.0.1, or 0.0.0.0.
Currently, to preview those apps locally, I need to manually identify the remote port and create an SSH tunnel, for example:
ssh -L 5173:localhost:5173 user@remote-host
This adds friction when using emdash remotely, especially when agents start servers automatically or when a project chooses a dynamic port. It would be helpful if emdash could detect and expose remote dev server ports automatically so the local preview workflow feels seamless.
Proposed Solution
When an emdash project is accessed over SSH, emdash should detect ports opened by processes in that project/session and automatically create local port forwards.
The ideal UX would be:
I open an emdash project over SSH.
I or an agent runs a dev server, such as:
pnpm dev The app starts on a remote port, such as 5173. emdash detects the port and creates a local forward.
emdash shows a clickable local URL in the UI, for example:
Port 5173 forwarded to http://localhost:5173
The port forwarding UI could show:
remote port local forwarded URL forwarding status associated project/session/process, if available actions to open, copy URL, stop forwarding, or restart forwarding
It should also handle common edge cases:
If the local port is already in use, emdash should choose another available local port and clearly show the mapping. Forwarded ports should be cleaned up when the SSH session/project closes.
Port detection could come from a few sources:
parsing terminal/PTY output for URLs like http://localhost:3000, http://127.0.0.1:5173, or http://0.0.0.0:8000 checking listening ports on the remote machine for project-owned processes
Alternatives Considered
I currently work around this by manually creating SSH tunnels with ssh -L, but this is easy to forget and does not work well when the port is chosen dynamically or when an agent starts the server.
Another workaround is to bind the remote dev server to a public interface, but that is less safe and less convenient than local forwarding.
Additional Context
VS Code Remote SSH provides a similar workflow by detecting remote ports, forwarding them locally, and exposing them in the UI. Having this in emdash would make remote development and agent-driven preview workflows much smoother.
This would be especially useful for projects where agents start preview servers automatically and the user just wants to click a local URL to inspect the result.
Hi @HugoMarchant,
Thanks for the detailed write-up. This is a very relevant use case for SSH projects, especially once agents start dev servers automatically.
We’ve also just brought back an in-app browser to Emdash, which will be live in the next production release. A great workflow would be to open the forwarded URL directly inside Emdash.
We already have local dev server detection in Emdash, but SSH port forwarding needs a proper remote-aware layer around detection, tunnel lifecycle, port conflicts, cleanup, and UI state.
We’ll look into this and use this issue to track the feature.
+1 on this. We hit exactly this scenario running coding agents on a remote dev box over SSH: dev servers bind to the remote host, so today we either keep manual ssh -L tunnels open or point each repo's config (e.g. our Vite VITE_API_URL) at the remote IP, which gets tedious to maintain across many projects.
We're currently looking into implementing this ourselves and would be glad to open a PR. Before we dig in, a couple of questions for the maintainers:
- Are you open to a contribution for this, and do you have a preferred direction for port detection? (e.g. polling
ss/lsofon the remote, parsing dev-server stdout, or an explicit per-project port list in the project config.) - Would you want the forwards routed through the existing SSH connection layer (the one that already resolves
~/.ssh/config) and surfaced as clickable local URLs in the UI, similar to VS Code Remote SSH? - Anything we should align with around the per-worktree
EMDASH_PORTallocation?
Happy to sketch a short design proposal first if that helps.
thanks for the context and the offer, @fiorelorenzo ! I’m looking into the implementation details now and will follow up here with how we should best proceed
I went ahead and did a first iteration while I was looking into it. @HugoMarchant @fiorelorenzo please let me know if this is what you had in mind or if anything is missing! you can check it out here #2544
#2544 will be in the next release!
🔥 @jschwxrz
Looking forward to seeing this in the prod release:)
Awesome, thanks for turning this around so fast @jschwxrz 🙏
This is exactly the workflow we were after: we run coding agents on a remote dev box over SSH, the agents spin up dev servers that bind to the remote host, and until now we've been juggling manual ssh -L tunnels (or pointing each repo's config at the remote IP). Auto-detecting the preview URL from terminal output, backing it with an SSH tunnel, and surfacing a clickable local URL is spot on. The manual-forward fallback is a nice touch too, since it covers the dynamic-port case where stdout parsing can't catch the URL.
Looking forward to the next release. We'll put it through its paces against our setup (several repos, multiple dev servers running at once) and report back here if we hit any rough edges.
Sounds great, thanks for the detailed context. Will keep you posted once it’s out. Would be great to hear how it holds up with your setup.
Update after running v1.1.35-canary.58: the auto-forwarding works great. I start a dev server in a terminal, Emdash parses the URL from the output and forwards the port automatically, clickable local URL included. Exactly the workflow we were after.
One enhancement that would make it even better for agent-driven workflows: run the URL detection on dev servers started by the agent too, not only on terminals opened manually. In our setup the agent often runs pnpm dev as part of its task, and those servers don't get picked up today.
From a quick look at #2544, wireTerminalUrlDetector is wired into the spawnTerminal path (watchDevServer: true) on both the local and SSH providers, but the agent/conversation session (and lifecycle scripts, where watchDevServer defaults to false) don't run the detector, so an agent-started server's URL never reaches the forwarder. Extending detection to the agent session would close that gap and make the "agent spins up a preview, you just click it" flow fully automatic.
Happy to open a separate issue or PR for this if you'd rather track it on its own.
Second this ^
Also opened #2589 for a separate, concrete issue we hit with the forwarding: the SSH tunnel targets a hardcoded 127.0.0.1, so dev servers that bind to localhost (which resolves to IPv6 ::1 first on Node >= 17) aren't reachable through the forward. Details and a suggested fix are over there.
Thank you for the feedback, @fiorelorenzo, and for testing this so quickly on v1.1.35-canary.58.
The agent-started dev server case makes sense. The ideal flow is definitely that an agent can start a preview server and Emdash still detects it, forwards it, and surfaces a clickable URL without requiring the server to be started from a manually opened terminal.
Also, thanks for opening the follow-up issue and PRs. We’ll take a look ASAP and follow up with feedback there.