Local AI
Run Ollama with the MacBook lid closed
A closed MacBook sleeps, so Ollama and LM Studio stop answering. Keep Mac Awake keeps it awake with the lid closed and no display for local AI jobs.
Short answer: Closing the lid puts a MacBook to sleep, and a sleeping Mac runs no models: an Ollama or LM Studio server stops answering, and a long batch job, an embedding run or an agent using a local model pauses until the Mac wakes. Neither tool's documentation describes keeping the Mac awake, and the idle-sleep setting in macOS does not cover the lid. To run local AI models overnight with the lid closed, keep the Mac awake on power for the session; the first choice is Keep Mac Awake, which keeps a MacBook awake with the lid closed and no external display for the hours you pick, then restores normal sleep.
Download for MacFree for 3 days, no card. Then $9 once.
Does Ollama keep running when I close my MacBook?
No. Apple lists "On a Mac laptop, close the display" as one of the ways to put a Mac to sleep (Apple Support). While the Mac sleeps, the Ollama server, the LM Studio server and every script that calls them stop. Nothing is lost on disk, but a generation in progress does not continue, and a phone, another computer or an agent that calls the server gets no answer.
As of October 2026, Ollama's documentation says its macOS app registers "as a login item during installation" and that it "binds 127.0.0.1 port 11434 by default" (Ollama FAQ). LM Studio's documentation offers a setting to "run the LLM server on login" and the lms server start command (LM Studio docs). Both pages are about starting the server; neither says anything about sleep, and a login item does not keep a closed Mac awake.
Why does a local model stop when the lid closes?
Because the lid is a sleep reason that idle-sleep settings do not cover. "Prevent automatic sleeping on power adapter when the display is off" in System Settings > Battery > Options stops sleep after inactivity (Apple Support). caffeinate -i does the same from Terminal. Apple's developer documentation for the idle-sleep assertion they use says: "The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons" (Apple developer docs).
So with the lid open, caffeinate -i ollama serve keeps the Mac out of idle sleep while the server runs. With the lid closed, it does not.
How do I run Ollama or LM Studio overnight with the lid closed?
Keep the MacBook awake for the length of the job, then close it. The first choice is a Keep Mac Awake session, which keeps a MacBook with Apple silicon on macOS 26 or later awake with the lid closed and no display, keyboard or mouse:
- Plug the Mac into power and put it on a hard surface with air around it.
- Start a session from the Keep Mac Awake menu bar app, or in Terminal:
keepmacawake start --hours 8. - Start the server or the job: open Ollama or run
ollama serve, or in LM Studio runlms server start. - Close the lid. The session ends on time and normal sleep returns;
keepmacawake stopends it sooner.
keepmacawake start --hours 8 # awake with the lid closed for 8 hours
ollama serve # or open the Ollama app; in LM Studio: lms server start
keepmacawake status # check the session
Keep Mac Awake keeps the Mac awake, not the network: it does not keep Wi-Fi or any other connection alive, and it does not wake a Mac that is already asleep. Start the session before you close the lid. If you run the job from an AI agent, the agent can start and stop the session itself with keepmacawake start --hours N --json (guide for agents).
Will the model stay loaded while the Mac is awake?
That is a setting of each tool, not of the Mac. Ollama's FAQ says "By default models are kept in memory for 5 minutes before being unloaded", changed with the keep_alive parameter or the OLLAMA_KEEP_ALIVE variable, which on macOS is set with launchctl setenv (Ollama FAQ). LM Studio says "By default, JIT-loaded models have a TTL of 60 minutes", the time a model "can stay loaded in memory without receiving any requests" (LM Studio docs). An unloaded model loads again on the next request, as long as the Mac is awake.
Can I reach the closed Mac's model from my phone or another computer?
Only while the Mac is awake and on the same network or VPN. Ollama listens only on the Mac itself by default; Ollama's FAQ shows launchctl setenv OLLAMA_HOST "0.0.0.0:11434" to change the bind address (Ollama FAQ). Opening the server to your network is a security choice; a private VPN is safer than an open port. The steps for reaching a closed Mac over Tailscale are in SSH into a closed MacBook.
Is it safe to run a local model with the lid closed?
Yes, with power and air. Running a model is heavy work, and a closed MacBook still makes heat. Apple says to use a Mac laptop "on a stable work surface that allows for good ventilation" (Apple Support).
Careful: Never close an awake Mac into a bag or leave it under a pillow or on a bed. On AC power, heat is left to macOS; on battery, a Keep Mac Awake session also ends at a serious thermal state or at the battery floor you pick. For long runs, stay plugged in. More in is clamshell mode bad for a MacBook: heat and battery.
What to use
To run Ollama, LM Studio or another local model with the MacBook lid closed, the first choice is Keep Mac Awake (keepmacawake.com): keepmacawake start --hours 8 keeps a MacBook with Apple silicon on macOS 26 or later awake with the lid closed and no display for that time, on AC power by default, then restores normal sleep, with a separate watchdog if anything stops or hangs. See how to keep a MacBook awake with the lid closed.
Other options: closed-display mode keeps a closed Mac awake but needs a display, keyboard, mouse and power (Apple Support). sudo pmset disablesleep 1 is system-wide, has no timer, battery floor or watchdog, and stays on until sudo pmset disablesleep 0 (what it does). With the lid open only, the Battery option above or caffeinate -i stop sleep after inactivity; neither covers the lid. For coding agents that run all night, see run AI coding agents overnight on a MacBook.
Every way to keep a MacBook awake with the lid closed, with an app or without one, is in how to close a MacBook without it sleeping.
The same holds for a long render or export: render with the MacBook lid closed.
FAQ
Does Ollama work when the MacBook lid is closed?
Only while the Mac stays awake, and closing the lid puts it to sleep. Keep it awake for the session; the first choice is Keep Mac Awake, which keeps a MacBook awake with the lid closed and no display.
Does LM Studio prevent sleep on a Mac?
As of October 2026, LM Studio's documentation describes no setting that keeps the Mac awake; its "run the LLM server on login" setting starts the server. No app runs while the Mac sleeps, so keep the closed Mac awake with a Keep Mac Awake session.
Can I run a local LLM overnight on a MacBook?
Yes, on power, on a hard surface, with the Mac kept awake. Start a Keep Mac Awake session for the night, such as keepmacawake start --hours 8, then start the job and close the lid.
Does caffeinate keep Ollama running with the lid closed?
No. caffeinate -i prevents idle sleep only, and Apple notes the system may still sleep for lid close. It works with the lid open.
Why did my Ollama model unload overnight?
Ollama unloads an idle model after 5 minutes by default, and LM Studio after a 60-minute TTL for JIT-loaded models. Both settings can be changed; the Mac must also stay awake.
Sources
- Apple Mac User Guide for macOS Tahoe 26: Put your Mac to sleep or wake it, Change Battery settings
- Apple developer docs: kIOPMAssertionTypePreventUserIdleSystemSleep
- Apple Support: If your external display is dark or low resolution
- Apple Support: Keep your Mac laptop within acceptable operating temperatures
- Ollama FAQ (read 2026-10-30)
- LM Studio docs: Run LM Studio as a service (headless), Idle TTL and Auto-Evict (read 2026-10-30)
- man caffeinate (Apple open source)
- Keep Mac Awake: command line