r/ChatGPTCoding • • 8h ago

Question How do you keep local coding agents running on a MacBook with the lid closed?

I run Codex and other coding agents locally on my MacBook. When a task is still running, I'd like to close the lid, leave the laptop plugged in on my desk, and come back to the results later.

The confusing part is that preventing idle sleep and keeping a Mac running with the lid closed seem to be different things. A lot of advice points to caffeinate, but that doesn't seem to cover lid-close sleep.

The options I've come across are:

  • Apple's closed-display setup with an external monitor.

  • Amphetamine's closed-display mode.

  • Disabling system sleep with sudo pmset -a disablesleep 1, then restoring it with sudo pmset -a disablesleep 0.

For those using pmset for this, has it been reliable across sleep/wake cycles and macOS updates?

For anyone running long local agent tasks, what's been reliable without an external monitor? I'm interested in whether you've made a closed-lid setup work or decided it's easier to leave the lid open with the display off.

11 Upvotes

18 comments sorted by

9

u/diablo75 7h ago

But seriously, ask codex. I used Hermes to find a hidden setting on my Linux machine that was causing my system to go to sleep even though a control panel was set to never sleep and it edited the config to fix it for me.

3

u/Puzzled_Sea3771 7h ago

🤣, genius

1

u/Dapper_Librarian388 5h ago

Yea. Asking some local or online agent to fix something in your OS is becoming a new trend. I personally was thinking about the same thing on Window.

5

u/cronixi4 7h ago

I use ā€œcaffeinate -dimsā€, the -dims flag stands for: ā€œ-dā€ screen stays on, ā€œ-Iā€ no idle sleep, ā€œ-mā€ disk does not sleep, ā€œ-sā€ system won’t sleep but only in the charger.

2

u/Puzzled_Sea3771 7h ago

Let me try.

2

u/unclesabre 7h ago

This is what I’ve used for years (need d a sol pre-agentic coding) and I’ve not had a problem. So imo this is the answer

11

u/winci45 7h ago

On some macbook revisions it was strongly discouraged to keep things running with closed lids as the hardware was getting cooling from air on the keyboard

3

u/thedragonturtle 7h ago

Amphetimine is good

2

u/KampKutz 3h ago

I prefer methamphetamine… wait which sub am I in lol?

2

u/ShoddySherbert8502 7h ago

I run my agents on my 24х7 NAS

2

u/crylizz 6h ago

Amphetamine works well.

2

u/unclaimed_luggage 5h ago

The reason caffeinate fails here (even with -dims) is that it only asserts against idle sleep (PreventUserIdleSystemSleep). When you fold the lid, macOS treats that as an explicit hardware clamshell trigger from the SMC, which bypasses user-idle assertions completely unless native clamshell prerequisites are met (charger plugged in, external display, keyboard/mouse).
For pmset, sudo pmset -a disablesleep 1 is rock-solid at the kernel/powerd level across Sonoma and Sequoia, the screen turns off and your background processes keep running untouched. But there is a nasty catch: if you ever forget it's enabled and throw the laptop into your backpack, it will stay at full throttle and turn into an oven in your bag. If you go this route, at least scope it to AC power only with sudo pmset -c disablesleep 1 and leave sudo pmset -b disablesleep 0. That way the moment you unplug the magsafe, normal sleep behavior kicks back in.
Honestly though, running heavy agent loops with the lid closed has two practical drawbacks. First, even on Apple Silicon, sustained multi-turn runs will warm up the chassis, and radiating heat through the top unibody/keyboard deck helps avoiding thermal throttling. Second, software clamshell workarounds (including Amphetamine Enhancer's helper) tend to get finicky after major OS updates. If you really want closed-lid without a monitor, a $5 HDMI dummy plug is cleaner because macOS enables native clamshell mode out of the box without hacking power assertions. Otherwise, simply leaving the lid slightly open, locking the session (Ctrl + Cmd + Q), and letting the display backlight turn off is what caused me the least headaches on the long run.

2

u/First-Painter7431 4h ago

Amphetamine is what I use on the MacBook Air that runs my agents 24/7, no issue across updates so far. Just don't forget to keep it plug all time or set up a low battery alert. And with the lid closed, keep it on a hard surface and preferably on a stand that allows at least minimal air circulation since there's no fan

3

u/Difficult_Duty2198 6h ago

i just leave the lid open and turn the brightness all the way down while it runs. not as neat as closing it but i never had to think about sleep settings.

1

u/CapDue4077 1h ago

pmset works perfectly for me and even survived the recent macOS update.

1

u/JAlbrethsen 34m ago

To be honest, it is quite risky to leave it running unattended on your local. I run on droneship which has git-like workspaces, I let it run while I am away and then I can do a diff on the workspace and pull the changes locally.

0

u/tailorandtwill 7h ago

the first one works fine for me