Repository navigation
feat(tray): Data Saver, block everything but agent hosts (macOS) - #11
Merged
Merged
Conversation
… agent hosts (macOS) On a hotspot, a Mac kept awake with the lid closed can download 15 GB+ of macOS and app updates. The new "Data Saver · agents only" tray switch blocks every outgoing connection except DNS, the local network and an editable host list (Claude Code, Codex, GitHub, npm, PyPI), and turns off macOS and App Store automatic updates, restoring them afterwards. A root-owned helper (datasaver.sh) does the work. A one-time sudoers rule allows exactly `<helper> on` and `<helper> off`, and the host list is passed on stdin. Rules live in their own pf anchor, so /etc/pf.conf is never edited. The watchdog, quitting the app and startup all switch it off. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A Data Saver · agents only switch in the tray, for hotspots. A Mac kept awake with the lid closed can download 15 GB+ of macOS and app updates. While Data Saver is on:
~/.agents-dont-sleep/datasaver-hosts.txt. The defaults are Claude Code, Codex, GitHub, npm and PyPI, and Edit allowed hosts… in the menu opens the list.Before the permission is granted, the menu item reads
Data Saver · agents only…. Clicking it asks for the admin password once, and after that it's a checkbox. Settings → General has a Data Saver group with Grant/Revoke and the same switch.How
src-tauri/src/datasaver.sh, installed root-owned at/Library/PrivilegedHelperTools/agents-dont-sleep-datasaver, with a sudoers rule that allows exactly<helper> onand<helper> off(no wildcards).com.apple/250.agents-dont-sleep./etc/pf.confalready hasanchor "com.apple/*", so it's never edited. pf is enabled with a reference token, which is released onoff.quick, so anchors loaded after ours (a VPN kill switch, for example) still get the final say.onis idempotent. It only loads the rules when they're missing, so the table isn't emptied under running agents, and it adds each host separately, so one host that doesn't resolve doesn't drop the rest.src-tauri/src/datasaver.rshas the grant, apply, restore and host-list code, with stubs on Linux and Windows.has_grant()also checks that the installed helper matches this build's script. An update that changes the script asks for the permission again.lib.rsapplies the setting. A toggle wakes it, and while Data Saver is on it re-applies every 5 minutes so host-list edits and rotating CDN addresses get picked up. Ifonfails, it switches everything off, unchecks the setting and shows a notification.kill -9), on quit, and at startup (leftovers from a reboot). It comes back on at launch if the setting was on.power/macos.rssharesadmin_shelland a newsudo_user()with the new grant.Caveats
*.githubusercontent.comis commented out by default because GitHub release downloads, where many apps get their updates, use the same addresses.Testing
cargo test --workspacepasses, 44 tests. New:datasaver::tests::helper_only_passes_host_like_tokens,datasaver::tests::helper_parses_and_refuses_unknown_commands,tray::tests::data_saver_items.cargo clippy --workspace --all-targets -- -D warningsandcargo fmt --checkare clean.shellcheckis clean, the frontend builds, andpfctl -nvfparses the ruleset.pfctl -Eprints the token asToken : N, and the crash-restore path. Steps:curl -sI https://api.anthropic.comworks andcurl -m5 -sI https://swcdn.apple.comfails straight away.sudo pfctl -a com.apple/250.agents-dont-sleep -srshows the rules.defaults read /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownloadprints1.kill -9the app, and check that the anchor is empty within about 3 seconds.cfg-gated or stubbed); CI will build them.🤖 Generated with Claude Code