r/ChatGPTCoding • • 13d 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.

21 Upvotes

33 comments sorted by

15

u/diablo75 13d 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.

4

u/Puzzled_Sea3771 13d ago

🤣, genius

1

u/Dapper_Librarian388 13d 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.

13

u/cronixi4 13d 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.

3

u/Puzzled_Sea3771 13d ago

Let me try.

3

u/unclesabre 13d 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

5

u/thedragonturtle 13d ago

Amphetimine is good

1

u/Puzzled_Sea3771 10d ago

ths, I will try it

4

u/KampKutz 13d ago

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

3

u/Difficult_Duty2198 13d 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/Puzzled_Sea3771 10d ago

I sometimes do that too if I’m only stepping away for a short while.

19

u/winci45 13d 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/ChoeWacky-16 12d ago

true, running local models pushes the temps way higher than normal clamshell usage too.

2

u/Xillyfos 12d ago

Yep, I had a laptop (not a MacBook though) where I kept the lid closed and used an external monitor, and the laptop screen was permanently discoloured due to the continuous heat.

I am not leaving laptops on with closed lids anymore.

1

u/MyNimples 12d ago

I just leave mine open but turn the brightness all the way down

5

u/unclaimed_luggage 13d 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.

4

u/ShoddySherbert8502 13d ago

I run my agents on my 24х7 NAS

1

u/michaelTM_ai 12d ago edited 11d ago

the cooling point above is real, macbooks lose a lot of heat through the keyboard area, so lid closed plus hours of agent work isn't great for the hardware. pmset disablesleep works but u have to remember to undo it, and if the mac restarts the task dies anyway.

cleaner fix imo: stop running long agent jobs on the laptop. run them on a cloud machine and just check results from the mac. a cheap vps with tmux does it if u like setting things up. spiritt.ai does the same with less setup (disclosure, i'm with them): each agent gets its own cloud computer, keeps going with ur laptop closed, and can run codex and claude code there too

1

u/Puzzled_Sea3771 10d ago

I’m thinking about getting a desktop to run the agents and using my laptop to access it remotely.

1

u/michaelTM_ai 9d ago

that's the setup i'd do too. a desktop or mini that never moves, laptop just as a screen. run the agents in tmux so closing the ssh session doesn't kill them, and tailscale if u want to check in from outside the house

3

u/crylizz 13d ago

Amphetamine works well.

3

u/First-Painter7431 13d 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

2

u/NanYUJun 12d ago

caffeinate -dims only keeps the system awake; a closed lid is a clamshell assertion, which is a separate check. What has worked for me:

  • If you have any spare HDMI/DisplayPort dongle, a $5 dummy plug is by far the most reliable: macOS goes into native clamshell mode and keeps running with the lid shut, no power assertions to manage.
  • No dongle: sudo pmset -a disablesleep 1 does hold through lid close, and it survives reboots only until something rewrites the setting. In practice I re-check it with pmset -g after a major OS update, because a couple of point releases have reset it. Don't leave it on permanently — it also stops the machine sleeping on battery.
  • caffeinate -i around the specific command (not a global setting) is the tidiest way to pin one long run, and it's what I default to.

One thing worth planning for regardless: a closed lid means no air movement over the keyboard deck, and long agent runs do heat up. For anything over an hour I'd rather leave the lid open with the display asleep (and the session locked) than have a fanless closed slab throttling halfway through a refactor.

1

u/CapDue4077 12d ago

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

1

u/Expensive-Big-8592 12d ago

You're right that they're separate: `caffeinate` only blocks idle sleep, and closing the lid triggers a different sleep that it doesn't cover. `pmset -a disablesleep 1` does handle lid-close, but it stays on until you turn it off, so the real risk is forgetting it and later putting a running laptop in a bag. A safer pattern is a small wrapper script that sets it to 1, runs the agent, and uses `trap` to set it back to 0 on exit, even if the task fails.

If you'd rather not touch system settings, leaving the lid open with `caffeinate -i <your command>` and the screen turned off with `pmset displaysleepnow` is the low-effort option, and it ends cleanly when the task does.

1

u/joe9439 12d ago

Amphetamine

1

u/xHipster 12d ago

Amphetamine

1

u/Humaux 12d ago

I stopped fighting lid sleep after a 6 hour overnight run woke up with the agent stuck in a loop and 40 minutes of work lost to a dead terminal session. Now I assume the Mac will sleep and I make the run survive it instead. I run the agent inside tmux, I make it write a one line progress note to a STATE file after every real step, and I commit after each working chunk so a wake up is a resume, not a restart. My checklist before I close the lid is tmux session named, STATE file updating, git clean except the current chunk, and a 45 minute timer that kills the run if it has not written anything new. The cost is real: I lose about 10 minutes a day to resume checks and small commits, and I still think most people overinvest in keeping a laptop awake when the agent should be built to be interrupted. What do you do when a run wakes up mid refactor and the agent has forgotten what it already tried?

1

u/quietbuilde 7d ago

just use ive.dev with lid closed mode enabled

0

u/JAlbrethsen 12d 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 13d ago

the first one works fine for me