Skip to content

feat(tray): Data Saver, block everything but agent hosts (macOS) - #11

Merged
itsmbaqer merged 1 commit into
mainfrom
feat/data-saver
Sep 28, 2026
Merged

itsmbaqer merged 1 commit into
mainfrom
feat/data-saver

Conversation

@itsmbaqer

Copy link
Copy Markdown
Owner

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:

  • Outgoing connections are blocked except DNS, DHCP, NTP, mDNS, the local network and the hosts in ~/.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.
  • macOS and App Store automatic updates are off, and the previous values come back when it's switched off. XProtect security data updates are left alone.

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

  • New src-tauri/src/datasaver.sh, installed root-owned at /Library/PrivilegedHelperTools/agents-dont-sleep-datasaver, with a sudoers rule that allows exactly <helper> on and <helper> off (no wildcards).
    • The host list goes in on stdin, filtered to host names, IPs and CIDRs. The helper never reads a file as root.
    • Rules load into their own anchor, com.apple/250.agents-dont-sleep. /etc/pf.conf already has anchor "com.apple/*", so it's never edited. pf is enabled with a reference token, which is released on off.
    • The rules are block-first with no quick, so anchors loaded after ours (a VPN kill switch, for example) still get the final say.
    • on is 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.
  • New src-tauri/src/datasaver.rs has 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.
  • One thread in lib.rs applies 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. If on fails, it switches everything off, unchecks the setting and shows a notification.
  • It's switched off by the watchdog (crash or kill -9), on quit, and at startup (leftovers from a reboot). It comes back on at launch if the setting was on.
  • Small refactor: power/macos.rs shares admin_shell and a new sudo_user() with the new grant.
  • Docs: SECURITY.md (every change, with undo commands), a README section, and CONTRIBUTING. This also fixes the stale "no network requests" line left over from the usage-limits PR.

Caveats

  • It allows by destination, not by app. macOS has no per-app firewall without a signed Network Extension, which this ad-hoc-signed app can't use. Any app that talks to an allowed host also gets through. *.githubusercontent.com is commented out by default because GitHub release downloads, where many apps get their updates, use the same addresses.
  • Some things are blocked until you add their hosts: VPN gateways, Claude Code's WebFetch, and MCP servers with their own endpoints.
  • Connections that are already open get cut when it turns on. Update downloads stop, and an agent's in-flight request is retried.

Testing

  • cargo test --workspace passes, 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 warnings and cargo fmt --check are clean. shellcheck is clean, the frontend builds, and pfctl -nvf parses the ruleset.
  • A release build is installed locally and launches.
  • Not tested end to end yet: the admin prompt, pf actually blocking traffic, and prefs being restored. Two things to confirm then: that pfctl -E prints the token as Token : N, and the crash-restore path. Steps:
    1. Grant, then check that curl -sI https://api.anthropic.com works and curl -m5 -sI https://swcdn.apple.com fails straight away.
    2. Check that sudo pfctl -a com.apple/250.agents-dont-sleep -sr shows the rules.
    3. Toggle it off, then check that defaults read /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload prints 1.
    4. Turn it on, kill -9 the app, and check that the anchor is empty within about 3 seconds.
  • The Linux and Windows builds were read through by hand (the macOS-only code is cfg-gated or stubbed); CI will build them.

🤖 Generated with Claude Code

… 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>
@itsmbaqer
itsmbaqer merged commit 8cd2f0b into main Sep 28, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant