
Architecting Resilient macOS Background Daemons with Go: Hot-Swaps, Zero CPU Idle & Crash Recovery
When architecting developer companion tools that run 24/7 on engineer laptops, the margin for error is razor-thin. If a background agent leaks memory, spins at 2% CPU during idle, or fails to recover after system sleep, developers will uninstall it within 60 seconds.
When designing the native macOS daemon for AG Remote (`ag-remote-go`), we discarded Electron and Node.js runtimes in favor of a standalone Go binary compiled natively for Apple Silicon and Intel x86_64.
Why Go for macOS Background Services?
Node.js and Python runtimes are fantastic for rapid scripting, but for a standing background daemon, they carry significant overhead:
Memory Footprint: A minimal Node.js background process consumes 45MB–80MB of RSS RAM out of the gate. `ag-remote-go` operates consistently between 11MB and 14MB.
Zero Runtime Dependencies: Compiling to a single static binary eliminates user-side issues with Homebrew paths, Node version mismatches, or missing shared libraries.
Concurrency Primitives: Go's lightweight goroutines and select channels make multiplexing local Unix sockets, file-system fsnotify watchers, and remote WebSocket streams trivial.
Launchd Lifecycle Management & Hot-Swap Protocols
On macOS, reliable background services must integrate directly with Apple's `launchd` supervisor via `~/Library/LaunchAgents/`. Rather than forcing users to manually restart terminal processes, `ag-remote-go` leverages structured lifecycle hooks:
1. Self-Healing KeepAlive: The plist specifies `KeepAlive: true` and `RunAtLoad: true`. If an unexpected panic occurs, launchd instantly respawns the binary.
2. Graceful Drain & Hot-Swap: When a new version is pushed via our auto-update pipeline, the daemon listens for `SIGTERM` or `SIGHUP`. Active terminal command sessions are preserved while the underlying binary replaces its own disk image and gracefully yields socket ownership.
The Zero CPU Idle Pattern
Many daemons inadvertently burn CPU cycles by polling log files with high-frequency intervals. In `ag-remote-go`, polling is strictly prohibited. Every wake cycle is strictly event-driven:
Kernel-Level Event Triggers: File modifications in Antigravity or Claude Code workspaces are captured via macOS `kqueue` and `FSEvents`.
Goroutine Blocking: Worker routines sleep on unbuffered channels until an incoming frame arrives over the encrypted WebSocket tunnel.
System Sleep Awareness: The daemon registers with macOS `IOPSNotificationCreateRunLoopSource` to gracefully park network connections before laptop sleep and re-establish sessions within 200ms of wake.
A well-behaved background daemon should be completely invisible in macOS Activity Monitor until an active agent task requires relay processing.
Engineering Lessons from Production
Building resilient macOS background software requires disciplined systems programming. By pairing Go's compiled performance with Apple's native process supervisor, AG Remote delivers an enterprise-grade developer tool that engineers trust running continuously on their primary workstations.
Learn more about our cross-platform engineering philosophy on the EFE Technology Engineering Blog.
AG Remote — Mobile Command Center for Autonomous AI Agents
Supervise long-running developer AI agent tasks, approve terminal commands, and monitor background builds directly from iOS and Desktop.


