TutorialmacOSFebruary 27, 2026·8 min read

Run OpenClaw 24/7 on Mac Without Issues (Even When Locked)

Your Mac goes to sleep. Your OpenClaw agents stop responding. Your scheduled tasks never run. This is one of the most common complaints from OpenClaw users on Reddit, and it has a clean solution. This guide covers every layer of the problem so your agents stay online whether the screen is locked, the display is off, or you have been away from your desk for hours.

The Problem: Why OpenClaw Fails When Mac Sleeps

macOS has two distinct modes that people often confuse: display sleep and system sleep. Display sleep turns off the screen. System sleep suspends all processes, freezes network connections, and halts every running task. OpenClaw can survive display sleep without any issues. System sleep kills it.

The default macOS power settings on a laptop are aggressive. After a few minutes of inactivity, the display sleeps. Shortly after, the system sleeps. This is great for battery life. It is terrible for running background agents.

Scheduled tasks never run

If OpenClaw is supposed to run a task at 2 AM but your Mac entered system sleep at midnight, the task is silently skipped. There is no error. The task just does not happen.

Browser service disconnects

The OpenClaw browser service uses a persistent Chrome connection. When macOS suspends processes, that connection drops. On wake, the gateway comes back but the browser session is gone.

Telegram agent goes dark

Your Telegram bot stops responding the moment the Mac sleeps. Anyone messaging your agent during that window gets no reply until you wake your machine.

Gateway process suspended

Even if OpenClaw is actively doing something, macOS can interrupt it mid-task during system sleep. The gateway process is paused and does not resume correctly in all cases.

Fix 1: Prevent Sleep with caffeinate

caffeinate is a built-in macOS command that prevents system sleep while allowing display sleep and all other power management features to work normally. It is the fastest fix and requires zero configuration.

Basic usage — keep Mac awake indefinitely
# Prevent system sleep indefinitely (run in a terminal window)
caffeinate

# Prevent system sleep AND display sleep
caffeinate -d

# Prevent system sleep while a specific process runs
# Replace PID with the process ID of your gateway
caffeinate -w PID

# Start OpenClaw gateway and prevent sleep for its entire lifetime
caffeinate openclaw gateway start

The last form is the most useful. It ties the sleep prevention directly to the OpenClaw gateway process. When the gateway stops, caffeinate exits too. No orphaned processes, no system resources wasted.

Run gateway with caffeinate in background
# Start in background, tied to gateway process
caffeinate openclaw gateway start &

# Verify caffeinate is running
ps aux | grep caffeinate

# Check that system sleep is being blocked
pmset -g | grep "sleep prevented"

Note: caffeinate in a terminal window stops when that terminal session closes. For a persistent always-on setup, use the launchd method in Fix 3 below, which wraps both caffeinate and the gateway in a managed service.

Fix 2: Energy Saver and Battery Settings

The graphical approach: configure macOS power settings to prevent system sleep while allowing the display to sleep normally. This is the minimum required change for any always-on OpenClaw setup.

macOS Ventura, Sonoma, and Sequoia (System Settings)

1. Open System Settings (Apple menu at top left)

2. Click Energy Saver (search for it if not visible)

3. Set Prevent automatic sleeping when the display is off to ON

4. Set Turn display off after to any value you prefer (1 hour is fine)

5. On Mac Mini and desktop Macs: also enable Start up automatically after a power failure

6. On laptops: switch to the Power Adapter tab and repeat these settings for when plugged in

macOS Monterey and Earlier (System Preferences)

1. Open System Preferences

2. Click Energy Saver

3. Check Prevent computer from sleeping automatically when the display is off

4. Uncheck Put hard disks to sleep when possible (optional but helpful)

These settings persist across reboots. Once configured, your Mac will keep the system awake as long as the power adapter is connected, regardless of display state or screen lock.

Fix 3: launchd Plist for Auto-Restart on Crash or Reboot

Energy Saver settings keep your Mac awake. launchd keeps OpenClaw alive within that awake Mac. If the gateway crashes, launchd restarts it automatically. If you reboot, launchd starts the gateway on login. This is the production-grade setup.

~/Library/LaunchAgents/ai.openclaw.gateway.plist
<?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>ai.openclaw.gateway</string>

  <key>ProgramArguments</key>
  <array>
    <string>/usr/bin/caffeinate</string>
    <string>-s</string>
    <string>/usr/local/bin/openclaw</string>
    <string>gateway</string>
    <string>start</string>
  </array>

  <key>WorkingDirectory</key>
  <string>/Users/yourusername/openclaw-server</string>

  <key>EnvironmentVariables</key>
  <dict>
    <key>ANTHROPIC_API_KEY</key>
    <string>sk-ant-your-key-here</string>
    <key>PATH</key>
    <string>/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin</string>
  </dict>

  <key>RunAtLoad</key>
  <true/>

  <key>KeepAlive</key>
  <true/>

  <key>ThrottleInterval</key>
  <integer>10</integer>

  <key>StandardOutPath</key>
  <string>/tmp/openclaw-gateway.log</string>

  <key>StandardErrorPath</key>
  <string>/tmp/openclaw-gateway-error.log</string>
</dict>
</plist>

Notice the plist wraps the gateway in caffeinate -s, which prevents system sleep for the lifetime of the gateway process. This means the plist handles both sleep prevention and auto-restart in one configuration.

Load and manage the service
# Load the service (starts immediately and survives reboots)
launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist

# Verify it is running (look for a PID in the first column)
launchctl list | grep openclaw

# View live logs
tail -f /tmp/openclaw-gateway.log

# Restart the gateway
launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist
launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist

# Stop permanently (until you load again)
launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist

Apple Silicon path: If you installed Node.js via Homebrew on an M1/M2/M3/M4 Mac, the binary is at /opt/homebrew/bin/openclaw instead of /usr/local/bin/openclaw. Update the PATH and ProgramArguments accordingly, or use the full path returned by which openclaw.

Fix 4: pmset Settings for Server-Like Behavior

pmset is the command-line tool for macOS power management. It gives you precise control over every sleep setting without using the GUI. For a Mac running OpenClaw as a server, these settings match what you would configure in Energy Saver but are scriptable and easy to audit.

View current power settings
# Show all current pmset values
pmset -g

# Show what is currently preventing sleep
pmset -g assertions | grep PreventUserIdleSystemSleep

# Show sleep schedule
pmset -g sched
Configure for always-on server use (requires sudo)
# Disable system sleep (0 = never)
sudo pmset -a sleep 0

# Disable display sleep OR set it to a long interval (minutes)
# 0 = never, 60 = 1 hour
sudo pmset -a displaysleep 60

# Disable disk sleep
sudo pmset -a disksleep 0

# Enable wake on network access (Mac Mini and desktop Macs)
sudo pmset -a womp 1

# Auto-restart after power failure (desktop Macs)
sudo pmset -a autorestart 1

# Apply settings only when on AC power (for laptops)
sudo pmset -c sleep 0
sudo pmset -c disksleep 0
Reset to macOS defaults (if needed)
# Restore all pmset settings to macOS defaults
sudo pmset -a restoredefaults

pmset settings persist across reboots. Run pmset -g to confirm your settings took effect. The sleep value should read 0.

Fix 5: Screen Lock vs Sleep — Keep Running While Locked

Screen locking and system sleeping are different things. macOS can lock the screen for security while keeping all processes running. This is the behavior you want: a locked screen that you cannot use without your password, but a system that is still processing your agent tasks in the background.

The key setting is in Screen Saver preferences. macOS often triggers system sleep when the screen saver activates. To separate the two:

1. Open System Settings and go to Lock Screen

2. Set Require password after screen saver begins or display is turned off to Immediately (for security)

3. In Energy Saver, confirm Prevent automatic sleeping when the display is off is enabled

4. Set the display to sleep after a short interval (10 or 15 minutes)

With this configuration: the display turns off after 15 minutes, the screen requires a password to unlock immediately, and the system never sleeps. Your agents keep running. Anyone who sits at your keyboard cannot access macOS without your password. Best of both worlds.

Lock screen from Terminal without sleeping
# Lock the screen immediately (display sleeps, system stays awake)
/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend

# Or use a shorter alias — add this to your ~/.zshrc
alias lock='/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend'

Browser Service Fix: Headless Chrome and No-Display Mode

The OpenClaw browser service spins up a Chrome instance to handle web browsing tasks. If this service keeps disconnecting after sleep/wake cycles, two things help: running Chrome in headless mode, and ensuring the browser service restarts cleanly when the gateway restarts.

Configure headless browser in OpenClaw config
# Check your current browser service configuration
openclaw config get browser

# Enable headless mode (no visible Chrome window)
openclaw config set browser.headless true

# Set Chrome flags for stability in background mode
openclaw config set browser.args "--headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage"

# Restart the gateway after config changes
openclaw gateway restart

Headless mode runs Chrome without a display, which means it does not depend on your screen state. It is also more memory-efficient and more stable in background environments. The --headless=new flag uses Chrome's newer headless implementation, which is significantly more reliable than the legacy headless mode.

Verify browser service is connected
# Check browser service status
openclaw gateway status

# Look for browser service in the process list
ps aux | grep -E "chrome|chromium" | grep -v grep

# Check browser logs
tail -50 /tmp/openclaw-gateway.log | grep -i browser

Gateway as a Background Daemon with launchd

The launchd plist from Fix 3 makes the gateway a managed background service. Here is a more complete version with environment variable handling for multiple API keys and a log rotation setup so your logs do not grow indefinitely.

Production plist with full environment setup
<?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>ai.openclaw.gateway</string>

  <key>ProgramArguments</key>
  <array>
    <string>/usr/bin/caffeinate</string>
    <string>-s</string>
    <string>/opt/homebrew/bin/openclaw</string>
    <string>gateway</string>
    <string>start</string>
  </array>

  <key>WorkingDirectory</key>
  <string>/Users/yourusername/openclaw-server</string>

  <key>EnvironmentVariables</key>
  <dict>
    <key>ANTHROPIC_API_KEY</key>
    <string>sk-ant-your-key-here</string>
    <key>OPENAI_API_KEY</key>
    <string>sk-your-openai-key-here</string>
    <key>NODE_ENV</key>
    <string>production</string>
    <key>PATH</key>
    <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
    <key>HOME</key>
    <string>/Users/yourusername</string>
  </dict>

  <key>RunAtLoad</key>
  <true/>

  <key>KeepAlive</key>
  <true/>

  <key>ThrottleInterval</key>
  <integer>10</integer>

  <key>StandardOutPath</key>
  <string>/Users/yourusername/openclaw-server/logs/gateway.log</string>

  <key>StandardErrorPath</key>
  <string>/Users/yourusername/openclaw-server/logs/gateway-error.log</string>
</dict>
</plist>
Set up log directory and deploy
# Create the log directory
mkdir -p ~/openclaw-server/logs

# Deploy the plist (save the XML above to this path first)
cp ~/Downloads/ai.openclaw.gateway.plist ~/Library/LaunchAgents/

# Load the service
launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist

# Confirm it is running
launchctl list | grep openclaw
# Output: 12345  0  ai.openclaw.gateway
# (PID in first column means it is running)

# Watch logs in real time
tail -f ~/openclaw-server/logs/gateway.log

Monitoring: Simple Health Check Script

Even with launchd and caffeinate in place, it is good practice to have a simple health check that verifies the gateway is actually responding, not just running as a process. This script pings the gateway endpoint and sends a Telegram alert if it is unreachable.

~/openclaw-server/scripts/healthcheck.sh
#!/bin/bash

GATEWAY_URL="http://localhost:18789/health"
TELEGRAM_TOKEN="your-bot-token-here"
CHAT_ID="your-chat-id-here"
LOG_FILE="$HOME/openclaw-server/logs/healthcheck.log"

timestamp() {
  date "+%Y-%m-%d %H:%M:%S"
}

send_alert() {
  local message="$1"
  curl -s -X POST \
    "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
    -d "chat_id=$CHAT_ID" \
    -d "text=$message" \
    > /dev/null 2>&1
}

# Check if gateway responds
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$GATEWAY_URL")

if [ "$HTTP_STATUS" != "200" ]; then
  echo "$(timestamp) - Gateway unreachable (HTTP $HTTP_STATUS). Restarting..." >> "$LOG_FILE"
  send_alert "OpenClaw gateway is down (HTTP $HTTP_STATUS). Attempting restart."

  # Restart via launchctl
  launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist
  sleep 3
  launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist

  echo "$(timestamp) - Restart triggered." >> "$LOG_FILE"
else
  echo "$(timestamp) - Gateway OK (HTTP $HTTP_STATUS)" >> "$LOG_FILE"
fi
Schedule the health check every 5 minutes with cron
# Make the script executable
chmod +x ~/openclaw-server/scripts/healthcheck.sh

# Open crontab editor
crontab -e

# Add this line to run the check every 5 minutes
*/5 * * * * /Users/yourusername/openclaw-server/scripts/healthcheck.sh

# View your cron jobs
crontab -l

The health check runs every 5 minutes. If the gateway does not respond, it attempts an automatic restart and sends you a Telegram message. If the gateway is healthy, it logs the status silently. You get notified only when something goes wrong.

When to Use a Dedicated Mac Mini

All the fixes in this guide work on any Mac. But if you find yourself managing sleep settings, worrying about closing your laptop lid, or running into battery-related interruptions regularly, the better solution is a dedicated Mac Mini.

A Mac Mini never has a lid to close. It sits on a shelf, draws 5-15 watts, and was designed for always-on use. With the launchd setup from this guide applied to a Mac Mini, your OpenClaw agents are as reliable as a VPS but faster and cheaper to run long-term. A refurbished M1 Mac Mini costs around $350 and pays for itself in 6 months compared to a comparable VPS.

See the Mac Mini deploy guide for a complete walkthrough including remote access, Tailscale setup, and data source connections.

Related Guides

Frequently Asked Questions

Does OpenClaw stop working when I lock my Mac screen?

Screen lock by itself does not stop OpenClaw. The problem is macOS often combines screen lock with display sleep and system sleep. If your Mac goes into system sleep mode after locking, all background processes — including the OpenClaw gateway — are suspended. The fix is to prevent system sleep independently of screen lock using caffeinate or pmset, while keeping the screen lock active for security.

What is the difference between display sleep and system sleep on Mac?

Display sleep turns off the screen to save power but keeps all processes running. System sleep (also called suspend or hibernation) suspends all CPU and network activity, freezing every running process. OpenClaw can survive display sleep without any problems. System sleep is what kills it. You want display sleep ON (good for the display) and system sleep OFF (keeps agents alive).

Will running caffeinate all the time damage my Mac?

No. caffeinate is a standard macOS utility designed exactly for this use case. It prevents idle system sleep while allowing display sleep, fan management, and thermal throttling to work normally. Your Mac will still cool itself, manage power, and sleep the display. The only thing caffeinate blocks is the CPU and network from going completely idle. Apple ships caffeinate on every Mac for this reason.

Why does my OpenClaw browser service disconnect when the Mac sleeps?

The OpenClaw browser service uses a Chrome or Chromium instance to handle web-based tasks. When macOS suspends a process, any open network connections — including the WebSocket connection between the gateway and the browser service — are dropped. On wake, the gateway resumes but Chrome may not reconnect automatically. Using headless mode (--headless=new flag) and running via launchd with KeepAlive helps, but the root fix is preventing system sleep in the first place.

How do I check if my OpenClaw gateway is still running after my Mac wakes from sleep?

Run launchctl list | grep openclaw in Terminal. If you see a PID next to the service label, the gateway is running. If the PID column shows a dash, the service stopped and launchd has not restarted it yet. You can also check the gateway logs with tail -f /tmp/openclaw-gateway.log to see the last activity timestamp. The health check script included in this guide automates this check and sends a Telegram alert if the gateway goes offline.

Should I use a Mac Mini instead of my laptop for running OpenClaw 24/7?

If you rely on OpenClaw agents for business-critical tasks, yes. A Mac Mini never closes its lid, sits in one place, and is designed for always-on use. Laptops are portable by design, which means macOS aggressively manages power when the lid closes or the battery is low. A Mac Mini on a wired connection with the launchd setup from this guide is more reliable than any laptop configuration. See the Mac Mini deploy guide for a complete walkthrough.

Get Your OpenClaw Agent Running in Minutes

Skip the manual configuration. CrewClaw generates your SOUL.md, launchd plist, and full agent package. Download and deploy on your Mac in under 10 minutes.