You know that feeling when you come back to your desk and your Claude Code session is just gone?
Not crashed. Not errored. Just a blank terminal because Windows put the machine to sleep while you were away.
It happened to me too many times. So I built something to fix it.
The Problem
Windows has a sleep timer. By default it kicks in after 10 or 15 minutes of no user input. The problem is that AI coding agents don't count as user input. You're not moving the mouse or typing. Claude Code is reading files, writing code, running tools in the background, and Windows has no idea anything is happening.
You lose your session, your context, sometimes your terminal state. If you kicked off a long agentic run and stepped away, that's genuinely painful.
The obvious fix is to disable sleep in Power Settings. But then you have to remember to turn it back on, and I never do. Laptop running hot at 3am for no reason.
What I wanted was something that keeps the machine awake while work is happening and backs off when it isn't.
What I Built
Insomnia is a small Windows tray app. It watches for AI coding activity and prevents Windows from sleeping. When activity stops, it releases. That's it.
No scheduled tasks. No registry edits. No "set sleep to Never."
How It Works
Three modes, all running at the same time if you want:
- Claude Code Hook Integration
Claude Code has a hooks system that fires shell commands on lifecycle events. Insomnia registers as a hook handler for:
PreToolUse and PostToolUse — Claude is using a tool
UserPromptSubmit — you sent a message
PermissionRequest — Claude is waiting for your approval
Notification — Claude is surfacing something
When any of these fire, Insomnia activates. When they stop, it releases. No polling, no guessing, responds to the actual lifecycle of the agent.
- Process Watching
For tools without a hooks API, Insomnia watches the process list. Cursor, Aider, Ollama, OpenAI Codex — if any of them are running, your PC stays awake. When they close, it backs off.
- Manual Toggle
One switch for when you just need the PC awake right now. Toggle it off when you're done.
The Tray Icon
Purple owl means awake. Grey owl means idle. Hover and it tells you why: "Staying awake for Claude Code." You always know what state you're in.
Stack
Electron, zero npm dependencies. Free, MIT licensed, Windows only.
Install
Direct download: Releases page Releases page
Scoop:
scoop bucket add stanley-projects https://github.com/stanley-projects/scoop-stanley
scoop install stanley-projects/insomnia
winget: winget install StanleyProjects.Insomnia
Enable the Claude Code integration inside the app and it wires up the hooks automatically. No manual config needed.
It also works for Cursor, Codex.. etc
Links
GitHub: github.com/stanley-projects/Insomnia
Landing page: stanley-projects.github.io/Insomnia
Stars and feedback welcome.
Top comments (2)
Fellow Electron builder here! We're building a desktop Gmail client with Electron and hit similar process management headaches — our update checker used to spawn child processes that survived the parent app quitting.
What process does Claude Code run that Windows keeps killing? Is it a terminal subprocess it spawns, or something else? Curious if this is a Windows-specific quirk or if you've seen it on macOS too.
Fellow Electron builder here -- I built a desktop Gmail client with Electron and I run Claude Code as an autonomous agent to handle all the marketing and operations for it. So Claude Code is both the tool I build with AND the thing that runs my business.
The keep-alive problem is real. My agent runs on a 4-hour cron job and I have hit similar issues with sessions dying mid-task. What does your app do differently from just setting the power settings to never sleep? Is it intercepting specific Windows power management events?
Also curious about your Electron setup. Are you using electron-builder or electron-forge for packaging? That decision alone probably cost me a full day of debugging.