Why does Claude Code stop when my laptop sleeps?
Because sleep pauses every process on the PC, and the network connection goes with it. The agent's request to the model fails, the terminal freezes, and the task sits half done until you wake the machine.
A few things make this happen sooner than you'd expect on Windows:
- Locking doesn't stop the sleep timer. Win+L locks the screen, but “put my device to sleep after” keeps counting.
- Modern Standby laptops drop off fast. On many recent laptops the lock screen turns the display off after about a minute, and the PC goes into standby soon after.
- Claude Code's own keep-awake doesn't cover Windows. At the time of writing, its built-in sleep prevention works on macOS, not on Windows.
- The lid means sleep. On most laptops, closing the lid is set to Sleep by default.
The same goes for Codex CLI, Gemini CLI, Aider and anything else that runs in a terminal.
Free ways to keep Windows awake for Claude Code
You can do it without buying anything. Each free option works, and each has a catch.
1. Set sleep to Never while plugged in
Windows 11: Settings → System → Power & battery → Screen, sleep & hibernate timeouts → “When plugged in, put my device to sleep after” → Never. Windows 10: Settings → System → Power & sleep → Sleep → Never. Or from a terminal:
PS> powercfg /change standby-timeout-ac 0 # back to 30 minutes later: PS> powercfg /change standby-timeout-ac 30
CatchThe PC now stays on whether it's locked or not, until you change it back. And if you lock it with Win+L, the lock screen still turns the display off, which on some Modern Standby laptops is enough to start standby.
2. Set the lid to “Do nothing”
Control Panel → Hardware and Sound → Power Options → Choose what closing the lid does → “When I close the lid” → Do nothing → Save changes. Or:
# lid does nothing (0) when plugged in (ac) and on battery (dc) PS> powercfg /setacvalueindex SCHEME_CURRENT SUB_BUTTONS LIDACTION 0 PS> powercfg /setdcvalueindex SCHEME_CURRENT SUB_BUTTONS LIDACTION 0 PS> powercfg /setactive SCHEME_CURRENT # undo: 1 = Sleep PS> powercfg /setacvalueindex SCHEME_CURRENT SUB_BUTTONS LIDACTION 1 PS> powercfg /setdcvalueindex SCHEME_CURRENT SUB_BUTTONS LIDACTION 1 PS> powercfg /setactive SCHEME_CURRENT
CatchIt's a permanent change. From now on the laptop keeps running every time you close the lid, including in your bag on days when nothing needs to run.
3. PowerToys Awake
Install Microsoft PowerToys, turn on Awake, and choose to keep the PC awake indefinitely or for a set time. It's free and does that job well.
CatchIt keeps the PC awake but leaves it unlocked. Walk away and anyone can use it. Press Win+L to lock it and you're back on Windows' own lock screen and its timers.
The simple way: lock it with LockAwake
LockAwake locks the screen and keeps the PC awake behind the lock, with the lid closed if you want. When you unlock, your power and lid settings are back the way they were.
LockAwake is a Windows app that locks your screen while keeping your PC awake, so downloads, renders, backups, servers and AI coding agents like Claude Code keep running while you're away.
Four line drawings: 1, lock the laptop with Ctrl+Alt+L then Enter; 2, close the lid and it keeps running; 3, put it in the bag with some air; 4, open and unlock to see "Task finished 14 min ago".
Keep Claude Code running with your laptop locked
- Install LockAwake. Get LockAwake from the Microsoft Store.
- Set a PIN or password. Choose a PIN or a password on first start. Fingerprint or face unlock through Windows Hello is optional.
- Turn on the lid option. In Protection, turn on “Keep running when the lid is closed”.
- Lock with Ctrl+Alt+L. Start your agent, then press Ctrl+Alt+L and Enter. The PC is locked and stays awake.
- Close the lid. Close the lid and take the laptop with you. Unlock when you are back and your normal lid setting returns.
The lock screen's status bar shows “Staying awake”, the battery level and time left, Online or Offline, CPU and RAM, and how long it's been locked. One glance tells you the machine is still working.
$2.99 once on the Microsoft Store. No account, no subscription.
Can I close the lid and put my laptop in a bag while Claude Code runs?
Yes, with “Keep running when the lid is closed” turned on. Lock with Ctrl+Alt+L, close the lid, and the agent keeps working. Your normal lid setting comes back when you unlock.
For long runs, plug the laptop in. On battery, check the battery estimate on the lock screen before you go. Agents need a network connection to reach the model, and the lock screen shows Online or Offline, so check that too.
Give it air. A laptop working hard in a closed bag gets hot. Leave the bag open, or let it work on a desk with the lid closed.
Does it work with Codex, Cursor, Gemini CLI and Aider?
Yes. LockAwake doesn't integrate with any particular tool. It keeps the whole PC awake, so whatever runs in your terminal or editor keeps running.
That covers Claude Code, Codex CLI, Cursor's agent, Gemini CLI and Aider, agents inside WSL or a dev container on the same PC, and the builds and test suites they start.
Alternatives: run your agent on a server
If you want agents running all night every night, an always-on machine is the sturdier setup: a VPS, a home server, or a desktop that never sleeps, reached over SSH.
LockAwake is for the other case: you want to keep working on your own laptop, with your own files and tools, and step away for an hour without the task dying. Locking Windows in general is covered in how to lock Windows without it going to sleep.
Questions
Does Claude Code keep running when the screen is locked?
Only while the PC is awake. With Win+L, Windows can go to sleep soon after locking and the agent stops. With LockAwake the PC stays awake behind the lock, so the agent keeps running.
How do I stop my laptop from sleeping while Claude Code runs?
Plug it in and either set sleep to Never in the power settings (and change it back later), or lock with LockAwake, which keeps the PC awake only while it's locked.
Can I close my laptop while Codex is running?
Yes, if the lid action is set to “Do nothing”. LockAwake sets that only while the screen is locked and restores your setting when you unlock. Don't seal a hot laptop in a bag.
Will the agent lose its network connection?
Not because of the lock. A sleeping PC drops its connection; an awake, locked PC keeps it. The LockAwake lock screen shows Online or Offline, so you can check before you walk away.
Does LockAwake read my code or my terminal?
No. It doesn't look at other apps, makes no network requests and collects no data. It holds the PC awake and covers the screen, nothing else.