A coding agent such as Claude Code, Codex or OpenClaw is a long-running process that holds a conversation, a working directory and a set of tool calls. Running it on a laptop means it stops when the lid closes. A dedicated Mac that stays on solves that, but only if you set it up so that a dropped connection or a reboot does not take your sessions with it.
Keep sessions in tmux
If you start an agent in a plain SSH shell, closing the connection ends the process. tmux keeps the terminal alive on the Mac, and you attach to it from anywhere. Install it with Homebrew and start a named session per project:
brew install tmux
tmux new -s api-agent
# start the agent inside, then detach with Ctrl-b d
tmux ls
tmux attach -t api-agentOne session per repository keeps contexts separate and makes it obvious which agent is doing what. Give each agent its own git worktree or checkout, so two agents never edit the same files.
Stop the Mac from sleeping
A remote Mac that sleeps drops your SSH connection and pauses your jobs. Check the current settings and turn system sleep off:
pmset -g
sudo pmset -a sleep 0 disksleep 0
# for a single command instead of a global setting:
caffeinate -i -s your-long-commandThe display can still turn off. That does not interrupt SSH sessions or processes. On a rented machine, check which power settings are already applied before you change them.
Survive a restart
Macs restart for updates and power events. Two details matter for an unattended machine. First, FileVault: with it on, the Mac waits for a password after a restart before your user session starts, so nothing runs until you unlock it. Decide whether the disk encryption is worth that trade for your workload. Second, anything that must come back by itself should be started by launchd, not by hand.
A LaunchAgent that starts a detached tmux server at login is enough for many setups. Save this as ~/Library/LaunchAgents/dev.local.tmux.plist, adjust the path to tmux, and load it with launchctl:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>dev.local.tmux</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/tmux</string>
<string>new-session</string>
<string>-d</string>
<string>-s</string>
<string>main</string>
</array>
<key>RunAtLoad</key><true/>
</dict>
</plist>launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/dev.local.tmux.plistAn agent that needs a logged-in graphical session, for example to use a browser, requires the user to be logged in. Agents that only use the shell do not.
Keep a log you can read later
A tmux pane keeps only a limited scrollback, so a long overnight run can push the first error off the screen. To keep everything an agent printed, write the pane to a file. Create the directory once, then start logging from inside the session:
mkdir -p ~/logs
tmux pipe-pane -o 'cat >> ~/logs/api-agent.log'Running the same command again turns logging off. Agents print a lot, so delete or rotate old logs. For short tasks, a larger scrollback is enough: add set -g history-limit 50000 to ~/.tmux.conf and start a new session.
Check the machine without attaching
You do not need to open every session to know the machine is healthy. One command from your own computer shows free disk space, memory pressure and how long the Mac has been up:
ssh mac 'df -h / | tail -1; memory_pressure | tail -1; uptime'A short uptime tells you the Mac restarted since you last looked, which means any session not started by launchd is gone and needs to be started again.
What to watch
- Disk space. Agents create checkouts, build products, node_modules and logs. A full disk is the most common reason for a stuck session. Check with df -h and clear derived data and caches on a schedule.
- Memory. Several sessions with language servers and test runners add up. Watch memory pressure in Activity Monitor or with the memory_pressure command.
- Credentials. Give each agent its own tokens with the narrowest scope that works. Do not put long-lived tokens into shell history or into a repository.
- Permissions. Run agents in a project directory, not as root, and review how much each tool is allowed to do without asking.
- Rate limits and billing. A loop that retries forever can burn your API budget while you sleep. Set a limit on the provider side.
- Updates. Update the agent tools at a time you choose, not in the middle of a long task.
A morning routine that takes two minutes
- SSH in and run tmux ls to see which sessions are alive.
- Attach to each and read the last few screens for errors or a question waiting for input.
- Check df -h and uptime.
- Review the git diff or the pull request each agent produced, as you would for a colleague's work.
Put every agent in tmux, disable sleep, decide on FileVault knowing that a restart needs an unlock, give each agent its own checkout and credentials, and check disk and memory every day. These habits keep a dedicated machine useful. See how to connect for the access options.