Get Moshi
deep dive

Debugging the gateway

Diff and browser preview ride on a local gateway at 127.0.0.1:24543. When they go quiet, this is the page to walk through.

updated 2 weeks ago33 min readpage 32 / 32

The gateway runs on 127.0.0.1:24543 and serves a WebSocket at /events that streams terminal context (CWD, git state) and detected dev servers to the iOS app. When diff or browser preview isn't working, this is the first thing to check.

Is the gateway alive?

probe the gateway
$curl -s http://127.0.0.1:24543/v1/diff/start
# Expected: 405 Method Not Allowed (GET not accepted, but proves the server is up)

If this times out, the daemon isn't running or the gateway failed to bind:

daemon checks
$brew services list | grep moshi
$tail -50 ~/Library/Application\ Support/Moshi/hook.log | grep gateway

Connect with wscat

Install wscat if needed (bun i -g wscat / bunx wscat, or npm i -g wscat / npx wscat).

No session (server discovery only)

discovery only
$wscat -c ws://127.0.0.1:24543/events

You'll get servers but context will be absent. Good enough to verify the gateway is broadcasting.

With SSH session

Find your SSH_CONNECTION value from inside the remote shell:

remote shell
$echo $SSH_CONNECTION
192.168.1.10 52431 192.168.1.20 22

Then connect:

ssh session
$wscat -c "ws://127.0.0.1:24543/events?session=ssh&sshConnection=192.168.1.10 52431 192.168.1.20 22"

With Mosh session

First, find the mosh-server's bind address and port:

find mosh-server
$lsof -i UDP | grep mosh
mosh-serv 67724 jyo 4u IPv4 ... UDP 100.96.116.120:60002

Then connect using the IP and port from the output:

mosh session
$wscat -c "ws://127.0.0.1:24543/events?session=mosh&moshHost=100.96.116.120&moshPort=60002"

If connecting over Tailscale MagicDNS, moshHost is the Tailscale IP (100.x.y.z), not the MagicDNS hostname.

Reading the response

A healthy connection returns a JSON message immediately:

{
  "context": {
    "kind": "tmux",
    "tmux": { "session": "main", "window": "1", "pane": "%5" },
    "cwd": "/home/user/project",
    "git": { "repo": "/home/user/project", "branch": "main", "dirty": true }
  },
  "servers": [
    {
      "id": "server_1",
      "name": "Vite",
      "host": "127.0.0.1",
      "port": 5173,
      "origin": "http://127.0.0.1:5173",
      "process": "node",
      "pid": 12345,
      "cwd": "/home/user/project",
      "isCurrentContext": true
    }
  ]
}

What to check

  • context missing — session lookup failed; wrong SSH_CONNECTION or moshHost:moshPort.
  • context.cwd missing — shell PID found but CWD unreadable.
  • context.git missing — CWD is not inside a git repo; diff will show "unavailable".
  • context.kind — should be tmux, zellij, herdr, or shell.
  • servers: [] — no dev servers detected on this host.
  • error — session resolution error message from the daemon.

No updates after the first message?

The daemon only pushes when state changes. To force an update:

  • Switch tmux windows or panes.
  • cd to a different directory.
  • Start or stop a dev server.
  • Make a git commit or stage a file.

Common failures

context is null with no error

No session identifier was provided. Add ?session=ssh&sshConnection=... or ?session=mosh&... params.

error: "no matching sshd process"

The daemon can't find an sshd process matching the SSH_CONNECTION value:

inspect sshd
# On the host, list sshd processes:
$ps aux | grep sshd
# Verify the connection is still alive:
$ss -tnp | grep ssh

error: "no matching mosh-server"

The moshHost:moshPort doesn't match any running mosh-server:

inspect mosh
$lsof -i UDP | grep mosh

Common cause: connecting over Tailscale but the mosh-server bound to the LAN IP (or vice versa). The IPs must match exactly.

Gateway connects but iOS still shows "Diff unavailable"

The gateway works but the iOS app can't reach it. The app connects via SSH local port forward (not directly). Check:

  • Is the terminal session still alive in the iOS app?
  • Was the app reinstalled? (wipes saved connections)
  • Was brew services restart moshi-hook run after the terminal opened? (kills the forward target)

Reopen the terminal in the iOS app to re-establish the SSH tunnel.

Daemon log

The daemon logs gateway events at DEBUG level:

tail the log
$tail -f ~/Library/Application\ Support/Moshi/hook.log | grep gateway

Key log lines:

  • gateway events: websocket connected — a client connected to /events.
  • gateway events: context request resolved — session lookup succeeded (shows CWD, shellPID).
  • gateway events: context request failed — session lookup failed (shows error).
  • gateway events: server probe — dev server discovery results.