Repository navigation
How Keep Awake Works
Keep computer awake holds the display and the system awake while the mode is On, or while an agent works in Agent mode. The user side is Keep Computer Awake.
An agent can work for an hour. If the Mac's screen turns off, locks or the Mac sleeps meanwhile, the run stalls. On, Agent and Off cover the cases: always, only while agents work, or never.
flowchart LR
Mode["settings.computerAwakeMode"] --> Store["keepAwakeStore"]
Agents["terminalStore: agent states"] --> Store
Store -->|"only on change"| Cmd["set_keep_awake(active)"]
Cmd --> KA["keep_awake.rs: requests per window"]
KA -->|"first request"| Start["caffeinate -d -i -s -w pid"]
KA -->|"last request ends"| Stop["kill caffeinate"]
keepAwakeModel.wantsAwake(mode, states): always in On, never in Off, and in Agent while any agent is starting or working (not waiting for the user, done or exited). keepAwakeStore runs in every app window (started from App.svelte), follows the mode and its window's agents, and calls set_keep_awake only when the answer changes.
keep_awake.rs counts which windows ask (Requests): the first one starts a guard, the last one to stop ends it, and a closed window's request is released (release_window).
-
macOS:
/usr/bin/caffeinate -d -i -s -w <app pid>.-dkeeps the display on (so it does not lock from idle),-istops idle sleep,-sstops system sleep on power, and-wends caffeinate when the app ends, even after a crash. A caffeinate killed from outside is started again on the next change. -
Windows:
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)on a thread of its own, reset when the guard drops. -
Linux:
systemd-inhibit --what=idle:sleep ... sleep infinity.
KeepAwake.svelte draws the control: a coffee cup, the mode and a dot filled while the computer is held awake; its menu has the title and status ("Agent · Active") and the three modes with what each does. Settings > AI has the same choice.
| File | What it does |
|---|---|
src-tauri/src/keep_awake.rs |
Requests per window and the guard per system |
src-tauri/src/commands/ai.rs |
set_keep_awake |
src/lib/ai/keepAwakeModel.ts |
When to hold it, the words |
src/lib/ai/keepAwakeStore.svelte.ts, KeepAwake.svelte
|
Following the agents, the status bar control |
One caffeinate with -w. It cannot outlive the app, so the Mac never stays awake by mistake.
Display too. Without keeping the display awake, the screen locks and some setups sleep anyway.
Waiting does not count. An agent waiting for an answer is not working; holding the computer awake for it would keep it awake all night.
It did not build on Windows. The Guard::Process variant is only made on macOS and Linux, so the Windows build saw dead code and failed. It is now built only off Windows; see Windows Bugs We Fixed.
- Rust: requests start and stop the guard at the first and last window; on macOS, caffeinate runs while asked and is gone after.
-
keepAwakeModel.test.ts: the three modes and agent states, the words, the lid notes. - Checked in the app with a stand-in agent: no caffeinate when idle, one while the agent worked, none once it finished.
- Retake
keep-awake.pngwhen the control changes.
These pages are generated from docs/wiki. To correct something, open a pull request against the source file; edits made here are overwritten.
Using Nibtree
- Getting Started
- Welcome Screen
- Workspaces
- Files Panel
- File Operations
- File Icons
- Rounded Panels
- Editor and Tabs
- Pin Reorder and Wrap Tabs
- Single Tab Title
- Split Editor
- New File and Unsaved Changes
- Unload Hidden Tabs
- Editing Code
- Code Appearance
- Markdown Editor
- Image and PDF Preview
- Search Everywhere
- Recent Files
- Navigation Bar
- Find and Replace
- Changes and Commits
- Sign In Prompts
- Commit Box Layout
- Repository Actions
- Commit Options
- Ignoring Files
- Diffs
- Inline Diffs
- Staging View
- Revert a Change
- Resolving Conflicts
- Merge Tool
- Blame
- History and Log
- Merge Commits
- Branches and Tags
- Branches Popup
- Remotes
- Stashes
- Shelf
- Git Menu
- Git Dialogs
- Interactive Rebase
- Worktrees
- AI Agents
- AI Tasks
- AI Usage
- Keep Computer Awake
- Submodules
- Git LFS
- GitHub
- Git Console
- Terminal
- Terminal Features
- Scripts
- Navigation
- Menus
- Settings
- Settings Search
- Color Themes
- Settings Terminal and Automation
- Settings Files
- Updates
- Status Bar and Help
- Notifications
- Memory Use
- Clear Cache
- MCP and CLI
- Git Mergetool
- Keyboard Shortcuts
- Keyboard Shortcuts Editor
- Troubleshooting
- Troubleshooting Git
Developers
- Developer Guide
- Architecture
- Project Layout
- Backend
- How Folder Watching Works
- Folder Watching Bugs We Fixed
- How Workspace Files Work
- How the Preview Scheme Works
- Backend Services
- How Terminal Features Work
- Terminal Bugs We Fixed
- Frontend
- How the Rich Markdown Editor Works
- Rich Markdown Bugs We Fixed
- Git Menu Links
- Menu Keys and Routing
- Frontend Modules
- Blame Bugs We Fixed
- Project Color And Title Bar
- One Diff View
- Diff Bugs We Fixed
- Merge Tool Layouts
- Merge Tool Bugs We Fixed
- Color Theme Bugs We Fixed
- How the Connected Diff Works
- Rounded Panels Bugs We Fixed
- Update Bugs We Fixed
- Status Bar Bugs We Fixed
- MCP and CLI Bugs We Fixed
- Repository Actions Bugs We Fixed
- How the Changes Tab Works
- CodeMirror Patterns
- How the Cursor Works
- How Editor Features Work
- How the Path Bar Works
- Commands and Events
- Settings Reference
- Commands Workspace and Changes
- Commands Branches and Remotes
- Commands History and Extras
- Commands App and Tools
- Testing
- Test Suites
- Debugging
- Debugging with MCP
- Measuring Setting Memory
- How Terminal Memory Is Measured
- How Markdown Diagrams Work
- Releases and CI
- Publishing the Wiki
- Versioning and Changelog
- Browser Version Packages
- Browser Release Checks
- Docker Image
- Platforms and Signing
- Windows Support
- Windows Bugs We Fixed
- Windows MCP and CLI
- Docs and Screenshots
- UI Library
- UI Library MCP
- UI Library Bugs
- UI Library Migration
- Contributing
How features work
- Welcome screen
- Workspaces and folders
- Files panel
- File operations
- File icons
- Editor and tabs
- Pin, reorder and wrap tabs
- Single tab title
- Split editor
- New File and unsaved changes
- Unload hidden tabs
- Editing code
- Code appearance
- Markdown editor
- Image and PDF preview
- Search Everywhere
- Recent Files
- Navigation Bar
- Find and replace
- Changes and commits
- Sign-in prompts
- Commit box layout
- Repository actions
- Commit options
- Ignoring files
- Diffs
- Inline diffs
- Staging view
- Revert a change
- Resolving conflicts
- Merge tool
- Blame
- History and log
- Merge commits
- Commit tabs
- Branches and tags
- Branches popup
- Remotes
- Stashes
- Shelf
- Git menu
- Git dialogs
- Interactive rebase
- Worktrees
- AI agents
- AI usage
- Keep computer awake
- AI tasks
- Submodules
- Git LFS
- GitHub account
- Git Console
- Back and Forward
- Integrated terminal
- Scripts tool window
- Menu bar
- Settings
- Search in Settings
- Color themes
- Rounded panels
- Updates and release channels
- Status bar and help links
- Notifications
- Memory readout and memory log
- Clear Cache
- MCP server and command line tool
- git mergetool mode