The short answer: Install Insomnia — a free, open-source Windows app. It keeps your PC awake automatically while AI tools are working and lets it sleep the moment they stop. Setup takes under 2 minutes.
You're running Claude Code on a complex refactor. You step away for 10 minutes. Your PC's sleep timeout kicks in, the process dies, and you come back to a broken session.
The naive fix — setting Windows sleep to "Never" — means your PC never sleeps when you actually want it to, wasting power and draining your battery. You want something smarter: awake while work is happening, asleep when it isn't.
Insomnia is a lightweight Windows utility that uses Electron's powerSaveBlocker API to prevent Windows from sleeping. It evaluates whether to stay awake based on three signals:
When all signals are inactive, the sleep lock is released and Windows behaves normally.
Head to GitHub Releases and download Insomnia.Setup.x.x.x.exe. Run the installer — it takes about 10 seconds.
Open Insomnia from the system tray (or Start Menu). Click + Add in the main window.
Go to the Integrations tab and enable the tool you use:
| Tool | Detection | What it does |
|---|---|---|
| Claude Code | Smart | Awake while Claude is running tools; idle for 3 min = asleep |
| Cursor | Smart | Awake while Cursor Agent is actively working; idle for 3 min = asleep |
| OpenAI Codex | Smart | Dual-path: CLI notify hook + session transcript polling |
| Aider | Process | Awake while aider.exe is running; 30s grace after it closes |
| Ollama | Process | Awake while Ollama is running local model inference |
Go to the Apps tab. Insomnia auto-discovers every installed app on your system. Search for it and click to add. The PC stays awake while that app runs, and sleeps normally when it closes.
Use the Keep Awake toggle in the main window. Flip it on — PC stays awake. Flip it off — PC sleeps normally. Perfect for presentations. Setting persists across restarts.
Insomnia lives in your system tray:
Right-click the tray icon for a quick toggle or to open the main window. Close the window to minimize to tray — Insomnia keeps running.
When you enable Claude Code, Insomnia adds hooks to ~/.claude/settings.json that fire on:
UserPromptSubmit, PreToolUse, PostToolUse, PermissionRequest, Notification → stay awakeSessionEnd → allow sleepThis means Insomnia knows precisely when Claude is reading files, running commands, and writing code — and when it's just sitting idle waiting for your next prompt. Your PC only stays awake while work is actually happening.
Cursor writes ~/.cursor/projects/*/agent-transcripts/**/*.jsonl files during active Agent sessions. Insomnia polls these files every 5 seconds. If any transcript file changes in size or modification time, it means Cursor Agent is actively working — and the sleep lock is applied. When the files stop changing, the sleep lock is released within 3 minutes.
| Approach | Drawback |
|---|---|
| Windows power settings → "Never sleep" | PC never sleeps, even when idle. Wastes power, drains battery. |
| Screen saver disabled manually | Still sleeps when the system timer fires. Not targeted. |
| powercfg /change /standby-timeout-ac 0 | System-wide change. Affects all programs, all the time. |
| Insomnia | Targeted: awake only when your trigger is active. Automatic release when done. |
Windows 10/11 · MIT License · No accounts