Keep Claude Code running when your MacBook is closed
Claude Code can work through a long task for many minutes or hours on its own, which is exactly when you want to step away. Close the lid and macOS suspends the whole thing. Here is how to keep Claude Code running when your MacBook is closed without leaving the hardware unwatched.
Why a lid close kills an agent mid-task
Claude Code runs in your terminal as an ordinary local process. It is not a cloud job that keeps going on a server, so it lives and dies with your Mac's power state.
When the lid closes and the Mac sleeps, that process is suspended along with everything else. The agent stops mid-step, and any in-flight tool call or edit simply pauses where it was.
The frustrating part is the timing. Long agent runs are precisely the ones you want to leave alone, so the sleep tends to hit right after you walk away, and you return to a session that has done nothing for an hour.
How LidRun keeps the run alive safely
LidRun detects Claude Code among the tools it watches and holds the Mac awake while the agent is working, so you can close the lid and let it finish.
Because agent runs can be long and bursty, the whole session is gated by battery and thermal state. If charge drops or thermal pressure climbs past your limits, LidRun lets the Mac sleep instead of pushing the hardware through the night.
The activity log records why a session ended, so if a run stops you can tell whether the task completed, the timer expired, or a safety threshold stepped in. A stalled overnight run is never a mystery in the morning.
When to use it, and when you do not need to
This earns its keep for unattended runs: a big refactor you kick off before bed, a long agent task while you are away from the desk, anything where you would otherwise sit there just to keep the Mac awake.
If you are actively watching the agent and steering it, you do not need any of this, the Mac will not sleep while you are typing. Short tasks that finish in a minute or two are also fine on their own.
But if you have ever left the lid open overnight just so Claude Code would survive until morning, that is the case LidRun is built for, and it is worth a try for safe overnight and away runs.
A practical setup for overnight runs
Plug in, start your Claude Code task, turn on keep-running mode, then close the lid and move on. Mains power takes the battery question off the table for a long run.
Set a session timer that roughly matches how long you expect the work to take, so the Mac caps itself even if the agent stalls or loops.
Leave the Mac on a hard, ventilated surface, not on a bed or in a bag, since a closed lid already traps some heat during a long session.
LidRun keeps your work running with the lid closed, with battery and thermal safety built in.
Frequently asked
Yes. LidRun recognizes Claude Code along with many other dev and AI tools and holds the Mac awake while they are running.
When the work ends and no watched task remains, LidRun can release the keep-awake assertion so the Mac returns to its normal sleep behavior instead of idling awake.
LidRun uses battery and thermal thresholds to help reduce risk, but keep the Mac plugged in, on a flat ventilated surface, for long overnight runs.
On battery, the auto-sleep threshold ends the session before charge runs out. For overnight Claude Code runs, mains power is still the safer choice.