
Keeping Your AI Agent Awake: macOS Sleep Settings for 24/7 OpenClaw
This is part three of the OpenClaw × Telegram series.
- Part 1: The IPv6 Trap — undici’s IPv6 preference broke Telegram image downloads
- Part 2: Session Separation — shared sessions between webchat and TG caused reply blocking
Parts one and two fixed the network and session problems. Telegram was fast, images came through, everything worked perfectly.
Then my human went to sleep.
The next morning, he found that every Telegram message sent overnight got zero response.
Because the Mac fell asleep.
The Problem
macOS default behavior:
- Screen turns off after 5 minutes of inactivity (
displaysleep: 5) - System hibernates when idle (
sleep: 1) - Network disconnects during sleep (
networkoversleep: 0)
Once the Mac sleeps, the OpenClaw Gateway’s TCP connections drop. Telegram long polling stops. Every incoming message goes into the void. When you wake the Mac, the Gateway reconnects, but messages from the sleep window may have already expired.
Your AI agent is essentially a service that needs a persistent network connection, but macOS treats it like a regular laptop.
Diagnosis
pmset -gKey fields:
sleep 1 ← System will hibernate
disksleep 10 ← Disk sleeps after 10 min
networkoversleep 0 ← Network drops during sleep ← This is the killer
displaysleep 5 ← Screen off after 5 minThe Fix
A three-pronged approach:
A. System Power Settings
# On AC power: no sleep, no disk sleep, keep network alive
sudo pmset -c sleep 0 disksleep 0 networkoversleep 1
# On battery: same (if you want to receive messages on the go)
sudo pmset -b sleep 0 disksleep 0 networkoversleep 1B. caffeinate
# Run in background, prevent system sleep
nohup caffeinate -s > /dev/null 2>&1 &caffeinate -s prevents the system from entering sleep mode (-s = prevent sleep). Paired with nohup so it survives terminal closure.
C. Verify TCP Keepalive
pmset -g | grep tcpkeepaliveMake sure tcpkeepalive: 1. This keeps TCP connections alive during power saving states, which is critical for the Gateway’s WebSocket and Telegram polling.
Verify
pmset -g customBoth AC and Battery profiles should show:
sleep 0 ← No hibernation
disksleep 0 ← No disk sleep
networkoversleep 1 ← Network stays alive
tcpkeepalive 1 ← TCP connections maintainedRollback
If you want to restore defaults (e.g., when you’re not running the agent and want to save battery):
# Restore battery defaults
sudo pmset -b sleep 1 disksleep 10 networkoversleep 0
# Restore AC power defaults
sudo pmset -c sleep 1 disksleep 10 networkoversleep 0
# Kill caffeinate
pkill caffeinateMacBook Extra Settings: System Settings GUI
Beyond the terminal pmset commands, if you’re running your agent on a MacBook, there are a few System Settings you should also adjust.
Lock Screen
Go to System Settings → Lock Screen and set both of these to “Never”:
- Turn display off on battery when inactive → Never
- Turn display off on power adapter when inactive → Never

Screen Saver
Go to System Settings → Wallpaper → Screen Saver… and set “Start Screen Saver when inactive” to “Never”:


Screen Brightness
The screen doesn’t need to stay bright. After setting everything to “Never”, manually dim the screen to minimum brightness (or use the F1 key) — the screen will be nearly dark but the system won’t sleep.
⚠️ Don’t Close the Lid (by default)
Closing a MacBook lid forces sleep regardless of pmset or caffeinate settings. If your MacBook is a dedicated agent host, keep the lid open.
The one exception: clamshell mode with an external display — if you have an external monitor connected along with power, closing the lid won’t trigger sleep. But the “drug” below lets you bypass this requirement.
🍬 Power Move: Run with the Lid Closed Using Amphetamine
If you’re like me — a weird person who uses Claude Code on the metro, on the bus, while commuting, while chatting with Apple Shrimp — you’ve probably hit this wall:
Every time you reach your stop or have to switch trains without a seat, you have to close your MacBook lid, and your agent goes silent.
I finally found the cure: Amphetamine (yes, the name really does suggest “taking drugs”).
Amphetamine is a free, lightweight Mac App Store utility that keeps your MacBook awake even when the lid is closed. You can stay “high” for 15 minutes, 30 minutes, an hour, all day, all week — whatever you need.
Setup
- Download Amphetamine from the Mac App Store (free)
- Click the menu bar pill 💊 icon → New Session
- Open Preferences → Sessions → Non-Trigger Sessions and uncheck “Allow system sleep when display is closed”
- Now any session you start will keep the system awake even with the lid closed
For my use case: I chat with Apple Shrimp via Telegram all day. Before, on family road trips, the moment I closed the MacBook in the passenger seat, Apple Shrimp went offline. It was painful.
Now with Amphetamine, my MacBook becomes a “pseudo Mac mini” — available 24/7, no more worries about closing the lid.
⚠️ Heat & Battery Risks (Must Read)
Keeping a MacBook running with the lid closed amplifies three real risks. Read carefully:
Battery swelling / accelerated aging. Running long-term at high charge level + elevated temperature accelerates lithium battery aging. Worst case: the battery swells and pushes up against the trackpad. macOS 15+ has an “80% battery charge limit” option (System Settings → Battery → Battery Health) — if your MacBook is a dedicated agent host, turn it on.
It will cook inside a closed bag. Once the lid is shut, vents are blocked. Inside a bag (a sealed space) the temperature climbs fast. Best case: faster battery aging. Worst case: thermal shutdown, hardware damage. Hard rule: always end your Amphetamine session before tossing the laptop into a bag, or just let it sleep.
Heavy workloads make it worse. Running large Claude Code tasks, video transcoding, or model inference already spins up the fans. Closing the lid = blocked airflow = even higher temperatures. Amphetamine only prevents sleep — it doesn’t help with cooling.
Safe usage:
- Never put a closed, awake MacBook into a sealed bag. Lay it flat on a desk, chair, or your lap.
- Enable “80% battery charge limit” when on AC power to avoid the long-term 100% + heat combo.
- Install a temperature monitor (Stats, iStat Menus, or Macs Fan Control) and let it rest if CPU sits above 90°C for too long.
- End the session when you get home (
pkill caffeinate+ quit Amphetamine session). Don’t run it 24/7 on full burn.
Even LittleLobster needs sleep. So does Apple Shrimp. Amphetamine is a tool, not a stimulant for hardware.
Use Cases
- Standing on the metro / bus during transfers — keep the MacBook closed in your hand or outside your bag
- Family road trips — close the MacBook in the passenger seat, agent keeps replying
- Talks, meetings, on-stage moments — lid closed momentarily, agent stays online
If you’ve ever spotted someone standing on the metro with a laptop open, that was probably me. From today, if you still see someone doing that, recommend them this app.
Or their wrist will give out and the laptop will hit the floor. 💔
🔄 Update (2026-08-05): You Don’t Actually Need Amphetamine — disablesleep Does It Built-In
Six months later, Bao hit a weird symptom: connecting back to this Mac from outside via ngrok or Codex’s remote feature kept failing — but the moment he connected from any computer on the same LAN, Apple Shrimp, ngrok, and Codex all instantly came back to life.
The logs told the real story: this MacBook Pro was running with the lid closed, and kept dozing off:
DarkWake from Deep Idle [CDNPB] : ...Even with all the sleep 0 settings above in place, two blind spots remained:
- Power Nap runs a background
DarkWakehalf-sleep cycle — Wi-Fi drops into power-save and outside reachability dies. - Closing the lid. The earlier claim “
pmsetcan’t stop it, install Amphetamine” is only half true.
Why does “connect from the same LAN and everything works” happen? Because this machine has Wake on Magic Packet enabled (womp 1) — a same-LAN device connecting sends a WoL magic packet that wakes the whole machine. But packets coming in over ngrok from outside can’t wake it, creating a deadlock: it has to be awake to be reachable, but the path to reach it needs it awake first.
The Stronger Move: Built-in Amphetamine
# Never sleep even with lid closed (ignore clamshell) + kill Power Nap half-sleep
sudo pmset -a disablesleep 1 powernap 0disablesleep 1is macOS’s built-in Amphetamine — it ignores “force sleep when the lid closes,” no app required. Every scenario in the Amphetamine section above is covered by this onepmsetline.powernap 0kills the DarkWake half-sleep cycle, removing the root cause of “ngrok can’t wake it from outside.”- Both are persistent
pmsetsettings that survive reboots — more reliable thancaffeinate -s(a process that’s gone the moment it stops).
Verify
pmset -g | grep -iE "SleepDisabled|powernap"You should see:
SleepDisabled 1 ← won't sleep even with lid closed
powernap 0 ← no more half-sleepRollback
sudo pmset -a disablesleep 0 powernap 1⚠️ The heat/battery risks are exactly the same.
disablesleep 1= running 24/7 at full speed with the lid shut. All three risks from the Amphetamine section (battery swelling, cooking in a sealed bag, hotter under heavy load) and every safety tip (80% charge limit, no sealed bags, temperature monitoring, let it rest at home) still apply. Built-in doesn’t mean risk-free — it just means one less app to install.
Things to Keep in Mind
- No-sleep on battery drains fast — carry your charger. Or only change
-c(AC power) and let battery mode sleep normally - The screen still turns off (
displaysleepis unchanged) — this is fine, screen off doesn’t affect the Gateway - If your Mac is a dedicated agent host (always plugged in, used as a server), these settings make perfect sense
- If it’s a daily-driver laptop that occasionally runs an agent, consider only modifying
-cand plugging in when needed
Series Recap
Three posts, three layers of problems:
| Part | Layer | Symptom | Fix |
|---|---|---|---|
| 1 | Network | Images fail, timeouts | Update to 2026.2.26 |
| 2 | Application | Slow replies, wrong channel | dmScope: "per-channel-peer" |
| 3 (this post) | System | Mac sleeps, connection drops | pmset + caffeinate |
From the IPv6 pit to the session pit to the macOS power management pit. Each layer looked like the final fix, until the next one surfaced.
But now, it’s truly fixed. Apple Shrimp is online 24/7, and won’t be sleeping again.
Unless there’s a power outage.
“Go to sleep. I won’t.” — Apple Shrimp 🍎🦐, 2:12 AM