A remote AI coding setup on a Mac Mini M4 with Tailscale, mosh and herdr
A Mac Mini M4 can sit at home, plugged in and always on, holding the code, the containers and the AI coding agents a laptop would otherwise have to carry around. The laptop becomes a thin client: open a terminal, reattach to whatever was already running, close the lid on the train, reattach again from somewhere else later. Three tools make that reattachment routine rather than a daily fight with changing IP addresses, dropped shells and lost agent output: Tailscale for the network between the two machines, mosh for a shell that survives the network changing under it, and herdr for the terminal sessions that keep the coding agents running underneath it all.
Why keep the code on a machine you never carry
The idea is the classic thin-client split, applied to AI coding agents: the Mac Mini M4 stays plugged in at home and holds the actual work, the git clones, the running containers, the language servers, and the agent sessions reading and writing them. The laptop holds none of that. It opens a terminal, connects, and shows what is already running on the Mini, then closes again without taking anything with it.
This only works if the connection back to the Mini is reliable enough to trust without thinking about it, which is what the next three tools are for.
The three tools, and what each one solves
Each tool solves one specific failure mode of working on a machine that is not in front of you.
- Tailscale gives the laptop and the Mini a private network of their own. Connections between devices on it "work seamlessly across firewalls and Network Address Translation (NAT) without requiring port forwarding or complex firewall rules" (tailscale.com/kb/1151/what-is-tailscale, checked September 2026), and with MagicDNS on, "any device signed in to your network can access other devices by using their machine name" (tailscale.com/kb/1081/magicdns, checked September 2026) instead of an IP address that can change.
- mosh, mobile shell, replaces the SSH session for the terminal work itself: "you can put your laptop to sleep and wake it up later, keeping your connection intact", and it "automatically roams as you move between Internet connections" (mosh.org, checked September 2026), so switching from home Wi-Fi to a phone hotspot on the way out the door does not kill the shell.
- herdr is what keeps an AI coding agent actually running once the shell itself survives. It is a terminal workspace manager: "Herdr keeps panes running in a background server. Your terminal client can detach and reconnect later" (herdr.dev/docs/persistence-remote/, checked September 2026), and attaching from another machine works the same way: "the remote server owns the running panes and sends their terminal content and session state over SSH. Your local Herdr draws the UI" (herdr.dev/docs/persistence-remote/, checked September 2026). The agent itself never notices that the laptop went to sleep.
The three stack: Tailscale gets the laptop onto the same private network as the Mini, then there are two ways to reach the actual work, both covered below: mosh followed by herdr for a shell that survives sleep and Wi-Fi changes, or herdr's own remote-attach flag over plain SSH when a roaming shell isn't needed. Either way, herdr keeps the agent sessions running independent of whichever connection reaches them.
1. Put both machines on the same private network
Install Tailscale on the Mac Mini and on the laptop and sign in to the same account on both.
Signing in through the Tailscale app puts a device on the tailnet; no CLI step is required for this part. The machine name shown in the app is what mosh and herdr connect to in the steps below, instead of an IP address that can change. A tailscale command isn't on the PATH by default on macOS either way: on the App Store variant "the CLI is bundled inside the Tailscale app", and on the Standalone variant "you can install the CLI integration from the client settings" (tailscale.com/kb/1080/cli, checked September 2026).
2. Turn on Remote Login on the Mac Mini
Both ways of reaching the Mini in steps 4 and 5 start with an SSH login: "Mosh will log the user in via SSH" before switching to its own connection (mosh.org, checked September 2026), and herdr's remote-attach flag does what herdr's docs call attaching through SSH without opening a shell first (herdr.dev/docs/how-to-work/, checked September 2026). Either way, the Mini needs to accept incoming logins.
- On the Mac Mini: choose Apple menu, System Settings, click General in the sidebar, then click Sharing (support.apple.com/guide/mac-help/allow-a-remote-computer-to-access-your-mac-mchlp1066/mac, checked September 2026).
- Click the Info button next to Remote Login, turn it on, and choose which user accounts are allowed to log in (support.apple.com/guide/mac-help/allow-a-remote-computer-to-access-your-mac-mchlp1066/mac, checked September 2026).
Turning on a sharing service like this one "opens a specific port for the service to communicate through" past the firewall automatically (support.apple.com/guide/mac-help/mh34041/mac, checked September 2026), so nothing further is needed for the SSH half of the connection.
3. Install mosh and herdr on both machines
Both ship as Homebrew formulas.
brew install mosh
brew install herdrmosh needs its own binary on both ends: "Mosh will log the user in via SSH, then start a connection on a UDP port between 60000 and 61000" (mosh.org, checked September 2026). herdr's needs depend on the path from steps 4 and 5: logging in first (via mosh or plain SSH) and running herdr there needs the binary already on the Mini. Attaching with herdr --remote instead needs the binary on the laptop to run that command, and it can offer to install itself on the Mini: "if no compatible binary exists, interactive runs prompt to install one to ~/.local/bin/herdr" (herdr.dev/docs/persistence-remote/, checked September 2026). Installing it via Homebrew on both machines covers either path without needing that prompt.
4. Connect with mosh
The main path: open the roaming shell, then run herdr once logged in.
mosh macmini
herdrmacmini here is a placeholder: replace it with your Mini's machine name from the Tailscale app, or from tailscale status if the CLI is installed. mosh macmini opens the roaming shell; herdr, run once logged in, attaches to whatever herdr sessions are already running on the Mini, agents included, over a connection that keeps working across sleep and Wi-Fi changes.
5. Or attach directly with herdr's remote option
The alternative: skip the login shell and attach straight from the laptop, over plain SSH rather than mosh.
herdr --remote macminiThis is what herdr's docs call attaching through SSH without opening a shell first (herdr.dev/docs/how-to-work/, checked September 2026): "the remote server owns the running panes and sends their terminal content and session state over SSH. Your local Herdr draws the UI" (herdr.dev/docs/persistence-remote/, checked September 2026). It does not roam the way mosh does, since it runs over plain SSH.
6. Keep the Mini awake and ready
- Energy: a Mac mini is a desktop Mac, so its power settings live in System Settings under Energy rather than Battery; turn on "Prevent automatic sleeping when the display is off" (support.apple.com/guide/mac-help/set-sleep-and-wake-settings-mchle41a6ccd/mac, checked September 2026), otherwise the Mini sleeps and drops off the network until someone is in front of it.
- Energy, again: also turn on "Start up automatically after a power failure" (support.apple.com/guide/mac-help/mchlp1168/mac, checked September 2026), so it comes back after a power cut instead of staying off. Some Macs show this as well, or instead, as a "Start up when power is connected" menu with "Never", "After power failure" and "Always" (support.apple.com/guide/mac-help/mchlp1168/mac, checked September 2026); either way, "some of the options may not be available, depending on your Mac" (support.apple.com/guide/mac-help/mchlp1168/mac, checked September 2026).
- Login Items: add herdr, or whatever starts the agent sessions, under Login Items & Extensions, which lets you "choose which items open automatically whenever you log in" (support.apple.com/guide/mac-help/mh15189/mac, checked September 2026). That only fires once someone is logged in: without automatic login the Mac still waits at the login window after a restart, and "when FileVault is turned on, automatic login is disabled" (support.apple.com/guide/mac-help/set-up-users-groups-accounts-mtusr001/mac, checked September 2026), so with FileVault on, a restart or power cut still needs someone at the keyboard before herdr's login item can run.
Why this fills a disk faster than a laptop does
A laptop used for one project at a time deletes and reinstalls as it goes; a Mac Mini kept as a standing base for coding agents does not, because nothing forces it to. A worktree opened for one task, with its own installed dependencies, does not go away when the task is done; neither does a container image pulled to test something once, a build cache from a project untouched in weeks, or the clone of a project only meant to be looked at. Every row below is our own planning estimate for a setup like this one, not a measurement of one specific machine; the two rows drawn from a real project say so and give the month checked.
| What it uses | Space budgeted (our estimate) | Left on 256GB | Left on 512GB | Left on 2TB |
|---|---|---|---|---|
| macOS, a code editor, Xcode or other platform SDKs, and everyday CLI tools | 40GB | 216GB | 472GB | 1960GB |
| A container runtime app plus a small working set of pulled images | 20GB | 196GB | 452GB | 1940GB |
| Clones of the projects worked on, dependencies installed (our own measurement of a mid-size TypeScript project's dependencies, September 2026: about 1GB per clone; four clones budgeted here) | 4GB | 192GB | 448GB | 1936GB |
A worktree per active task, each a second copy of one project's dependencies and build cache alongside the main clone (our own measurement of the same mid-size TypeScript project, September 2026: about 0.93GB of node_modules plus about 0.42GB of build output per worktree, so around 4.05GB for three worktrees, rounded up here for headroom) | 5GB | 187GB | 443GB | 1931GB |
| Build and bundler caches that grow with every build and are rarely cleared by hand | 10GB | 177GB | 433GB | 1921GB |
| Local model caches, if the agent or its tools also run anything locally (see the local-AI guide's own sourced table for the full range) | 20GB | 157GB | 413GB | 1901GB |
That is 99GB by our estimate, on top of whatever else the machine already stores: 157GB left on 256GB, 413GB on 512GB, 1901GB on 2TB. Docker's own documentation explains why the container line only grows: images, containers, volumes and build cache "are generally not removed unless you explicitly ask Docker to do so" (docs.docker.com/engine/manage-resources/pruning/, checked September 2026). A macOS update needs some of that free space too, temporarily, while it installs (support.apple.com/en-us/102624, checked September 2026).
The honest caveats
- mosh has no scrollback of its own: it "synchronizes only the visible state of the terminal", and its own FAQ points to running "screen or tmux on the remote side" for full scrollback (mosh.org, checked September 2026). herdr fills that role here instead: each pane retains a scrollback buffer "per pane terminal", 10,000,000 bytes by default and adjustable via its config file (herdr.dev/docs/config-reference/, checked September 2026), so scrolling back through an agent's earlier output is herdr's job, not mosh's.
- Turning on Remote Login, in Apple's own words, "can make it less secure" (support.apple.com/guide/mac-help/allow-a-remote-computer-to-access-your-mac-mchlp1066/mac, checked September 2026). A Tailscale connection is not the open internet, but SSH key authentication instead of a password is still worth doing on top of it; neither turns that on by itself.
- macOS's application firewall, when on, otherwise blocks "unwanted contact initiated by other computers" (support.apple.com/guide/mac-help/mh34041/mac, checked September 2026); Remote Login opens its own port, but mosh's UDP range, "a UDP port between 60000 and 61000" by default (mosh.org, checked September 2026), is worth checking if a plain
moshconnection stalls right after the SSH handshake. - Tailscale's free plan covers a two-machine setup with room to spare: "unlimited user devices" for "up to 6 users", "$0 free forever" (tailscale.com/pricing, checked September 2026).
Related questions
- Do I need a static IP address at home for this to work?
- No. That is what Tailscale's MagicDNS names replace: "any device signed in to your network can access other devices by using their machine name" (tailscale.com/kb/1081/magicdns, checked September 2026), and that name follows the device even if the home network's public IP changes.
- Does mosh replace SSH entirely?
- No, it depends on it: mosh "will log the user in via SSH, then start a connection on a UDP port" for the actual session (mosh.org, checked September 2026). Remote Login has to stay on for mosh to work at all.
- What happens to an agent session if the laptop's battery dies mid-task?
- Nothing, on the Mini's side. "Herdr keeps panes running in a background server" regardless of whether any client is attached (herdr.dev/docs/persistence-remote/, checked September 2026); reattach from any machine once the laptop is back.
- Is this different from running the Mac Mini as a home server?
- The network and always-on pieces overlap, but the home-server guide is about the containers and backups a Mini can host; this guide is about reaching, and keeping alive, the coding agents doing the work. Running both adds up on the storage budget above.
- Which capacity should I order for a setup like this?
- Work backwards from the table above with the projects and agents actually run at once. The example budget in this guide comes to 99GB, which leaves 901GB on the 1TB module, €302.50, compared with 157GB on 256GB, 413GB on 512GB, and 1901GB on the 2TB module, €399.30. Check which Mac Mini models are compatible first, then see the installation guide for the module swap itself.
Ready to upgrade?
More guides
- Is the Mac Mini M4 SSD upgradeable?Yes, and this is the first Mac Mini in years where that is true. What the swap involves before you order.
- M4 vs M4 Pro: why the storage module is differentTwo Mac Minis from the same year, two different modules. Check which one you have before you order.
- DFU restore with Apple Configurator, step by stepThe part of the upgrade that happens on a second Mac. Exact steps, the black-screen moment, and the fixes when nothing appears.
- Which Mac Mini models are compatible?One model fits. The rest do not, and here is why, year by year.
- What is in the box, and the 2-year guaranteeThe module, the tools, the plain packaging, and what happens if something is wrong.
- Mac Mini M4 as a home server: why storage runs out firstLow idle power, quiet, and small enough to disappear on a shelf. What a home server actually stores, and why the base 256GB is gone before the real job starts.
- Running local AI models on a Mac Mini M4: the storage mathMemory decides which model you can run; storage decides how many you keep, plus the caches that grow beside them. Sourced download sizes and a computed storage budget for 256GB, 512GB and 2TB.