Keep Screen On
A tiny VSCode extension that prevents your display from going to sleep or locking while VSCode is open.
- Click the activity-bar icon on the left, then click the status item to toggle.
- When active, a small
1 badge appears on the activity-bar icon.
- The state is shared across every open VSCode window — turning it on/off in one window updates them all.
- Closing every VSCode window releases the wake lock automatically. Nothing persists across sessions.
How it works
- Windows — spawns a hidden PowerShell child that calls
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_AWAYMODE_REQUIRED). When the process dies, Windows restores normal sleep behaviour.
- macOS — spawns
caffeinate -di.
- Linux — spawns
systemd-inhibit --what=idle:sleep:handle-lid-switch sleep infinity.
All helper processes are non-detached children of the VSCode extension host, so killing every VSCode window kills every helper.
Cross-window sync is done via a small JSON file in the OS temp directory (vscode-hold-light-state.json). Each window registers its PID with a heartbeat; dead PIDs are pruned on read, so a crashed VSCode does not leave a stale "on" state after restart.
Install
Download the latest .vsix from the releases page (or build it yourself, see below), then:
code --install-extension keep-screen-on-<version>.vsix
Reload VSCode after installation.
Usage
- Reload the window after install.
- Click the light-bulb icon in the activity bar on the left.
- Click the single status row inside the view to toggle the wake lock.
- A
1 badge on the activity-bar icon confirms the wake lock is active.
Commands (also available via the command palette):
Keep Screen On: Toggle
Keep Screen On: Enable
Keep Screen On: Disable
Build from source
npm install
npm run compile
npx @vscode/vsce package --allow-missing-repository --no-dependencies
The resulting keep-screen-on-<version>.vsix can be installed with code --install-extension or uploaded to the VSCode Marketplace / Open VSX.
Publish to the Marketplace
Requires a publisher account on https://marketplace.visualstudio.com/manage and a Personal Access Token from Azure DevOps with Marketplace (Manage) scope.
npx @vscode/vsce login <publisher>
npx @vscode/vsce publish
License
MIT