Not by default: closing a MacBook lid sleeps the Mac, so Ollama, LM Studio, llama.cpp and MLX stop generating and their API stops answering other devices and agents. Free fixes work with the lid open (Apple's sleep settings, or an external display setup with the lid closed). To keep a local model serving with the lid shut and no monitor, arm Clamshell for Mac and keep the Mac on power.
Clamshell for Mac keeps the Mac awake and on the network with the lid closed while armed, so your local model keeps answering. Free for 7 days.
Download free trialApple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or buy now, $9.99
A MacBook with Apple Silicon is a capable local model box. You start ollama serve, LM Studio's server, llama-server or mlx_lm.server, point a coding agent, an editor plugin or your phone at it, and then you want to fold the laptop and walk away while a long batch job or an overnight eval runs. Whether that works depends on one thing: is the Mac awake?
What happens to a local model server when you close the lid?
Closing the display is one of Apple's documented ways to put a Mac laptop to sleep. In sleep, apps stop running, and a model server is just an app:
- Inference pauses. A generation in progress stops mid-token. A batch script that loops over prompts stops with it.
- The endpoint disappears. Other devices, editors and agents that call the API get timeouts or connection errors until the Mac wakes. A sleeping Mac does not answer HTTP.
- Clients may give up. Whether a request is retried after wake is up to the client. Some agents and scripts treat a timeout as a failure and move on.
Lid-close sleep is separate from idle sleep. Tools that hold off idle sleep, such as caffeinate, do not stop lid-close sleep: see why caffeinate does not work with the lid closed.
Serve the model to other devices, LAN or Tailscale
Most local servers listen only on the Mac itself by default, so a phone or a second computer cannot reach them even while the Mac is awake. Change that first, then deal with sleep.
Ollama
The Ollama FAQ says it binds 127.0.0.1 port 11434 by default and that OLLAMA_HOST changes the bind address. For the macOS app, run launchctl setenv OLLAMA_HOST "0.0.0.0:11434" and restart Ollama.
LM Studio
Turn on Serve on Local Network in the server settings, or run lms server start --bind 0.0.0.0. LM Studio's own docs recommend enabling authentication when you do. Its examples use port 1234.
llama.cpp
llama-server listens on 127.0.0.1 unless you pass --host, per its README. Set --port explicitly so clients know where to connect. It serves OpenAI-compatible routes.
MLX
mlx_lm.server defaults to 127.0.0.1 port 8080 in the mlx-lm source. Pass --host to listen on another address.
Binding to 0.0.0.0 exposes the model to everyone on that network, so keep it on a home LAN you trust, or reach it over a private network such as Tailscale, which links your own devices into a tailnet. Do not forward the port to the internet without authentication in front of it. The Ollama FAQ also covers Nginx, ngrok and Cloudflare Tunnel if you need a proxy.
None of this keeps the Mac awake. Apple's Wake for network access lets a sleeping Mac wake briefly for shared services, but it is not a substitute for an awake server; the MacBook home server guide explains why.
Your options, from free to lid shut
Lid open, display off, on power
In System Settings, Lock Screen, set Turn display off on power adapter when inactive, and in Battery, Options, turn on Prevent automatic sleeping on power adapter when the display is off, from Apple's sleep settings guide. Free, and the best choice if the lid can stay up.
caffeinate, lid open
caffeinate -i ollama serve holds off idle sleep for as long as the server runs. -s also blocks system sleep, but only on AC power. Neither survives closing the lid.
External display setup
Apple's closed-display mode keeps a closed MacBook awake when it is connected to power, an external display, and an external keyboard and mouse (Apple). Fine at a desk you already have.
sudo pmset disablesleep 1
Stops lid sleep, but it is a global admin switch with no timer and no heat check, and a restart does not reset it. Nothing turns it off if the Mac heats up. See pmset disablesleep explained.
Clamshell for Mac
Keeps the Mac awake with the lid closed while armed, without an external display, sudo or admin rights, with always-on thermal safety. $9.99 once after a 7-day free trial.
Try it freeKeep a local model serving with the lid closed
- Start the server and, if other devices need it, set the bind address as above. Test the endpoint from the other device while the lid is still open.
- Plug in. Sustained inference is one of the heaviest loads you can put on a laptop. Clamshell works on battery too, but long jobs belong on the power adapter.
- Disconnect external displays. With a display connected Clamshell pauses instead of arming, and arms once displays disconnect.
- Arm Clamshell. From the menu bar for the next close, by right-click to stay armed across lid reopenings, or from a script with
open "clamshell://arm". The request is asynchronous, so check the menu bar state before closing the lid. - Close the lid on a hard, open surface. The built-in display stays black, the Mac stays on the network, and opening the lid locks the Mac.
Clamshell does not know about Ollama or any model server. It will not disarm when a job finishes, and it does not restart a crashed server. If you start jobs from a script, wrap them with open "clamshell://arm" and open "clamshell://disarm", or use the Arm and Disarm Clamshell Shortcuts actions.
Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once for one Mac. 14-day money-back guarantee.
Download free trialHeat and power under sustained inference
A model generating tokens for hours keeps the chip busy in a way most coding work does not. With the lid shut, the Mac has to shed that heat through its body and vents, so the setup matters more than usual.
- Ventilation. Apple's guidance asks for a stable surface with good ventilation, and not a bed, pillow or bedding. A closed bag is the worst case: see running a MacBook in a bag.
- Power adapter for long jobs. An overnight batch on battery can empty it well before morning. On power, turn on Charge Limit or Optimized Battery Charging so the battery is not held at 100 percent: details in is it safe to run a MacBook with the lid closed.
- Display off saves a little. A model server does not need the screen. Turning off Clamshell's "Let agents use the screen while the lid is closed" setting sleeps the display with the lid closed, which uses less battery and keeps the Mac cooler.
- Battery cutoff. On battery, Clamshell's optional Disarm on low battery (off by default) lets the Mac sleep below a level you choose. More in running lid-closed on battery.
- Unload when idle. Ollama keeps a model in memory for 5 minutes after use by default (
OLLAMA_KEEP_ALIVEchanges it), and LM Studio can auto-unload just-in-time loaded models. Shorter keep-alive frees memory between jobs.
Local models behind coding agents
If a coding agent on the same Mac calls the local model, both stop at lid close, and both resume only if the agent tolerates the gap. If the agent runs on another machine and calls your MacBook over the LAN or a tailnet, the agent keeps going and its model calls fail. Either way, the fix is an awake Mac. The overnight checklist in how to run AI agents overnight on a MacBook applies to local inference too: power, ventilation, and a quick check in the morning that work really continued.
Frequently asked questions
Does Ollama keep running when I close my MacBook lid?
No, not by default. Closing the lid puts the MacBook to sleep, so Ollama stops generating and its API on port 11434 stops answering until the Mac wakes. The same applies to LM Studio, llama.cpp and MLX servers.
Does caffeinate keep Ollama running with the lid closed?
No. caffeinate -i prevents idle sleep, which helps while the lid is open. Closing the lid still sleeps the Mac unless an external display, keyboard, mouse and power are connected.
How do I use Ollama on my MacBook from another device with the lid closed?
Make Ollama listen beyond localhost with OLLAMA_HOST, for example 0.0.0.0:11434, then keep the Mac awake with the lid closed. Clamshell for Mac does that while armed and keeps the Mac on the network, so devices on your LAN or tailnet can reach the API.
Is it safe to run a local LLM on a closed MacBook for hours?
Use a hard, ventilated surface and the power adapter. Sustained inference makes the Mac work hard, so never run it in a bag or on bedding. Clamshell disarms toward normal lid sleep if macOS reports serious or critical thermal pressure.
Can I run a local model on battery with the lid closed?
Yes, but expect the battery to drain much faster than at idle. For long jobs, plug in. On battery, Clamshell's optional Disarm on low battery lets the Mac sleep below a charge level you choose.
Related guides
- Use a MacBook as a home server with the lid closed
- Run AI coding agents overnight on a MacBook
- Is it safe to run a MacBook with the lid closed?
- Run a MacBook with the lid closed on battery
- Why caffeinate does not work with the lid closed
- Is sudo pmset disablesleep 1 safe?
Sources checked October 14, 2026: the Ollama FAQ, LM Studio's server, network, settings and headless docs, the llama.cpp server README, the mlx-lm server source, Tailscale's install docs, Apple's guides on sleep, sleep and wake settings, closed-display mode and laptop operating temperatures, and the macOS caffeinate manual page. Clamshell behavior is described from its published facts. Clamshell is an independent app, not affiliated with or endorsed by Apple, Ollama, LM Studio, the llama.cpp or MLX projects, or Tailscale.