Auto-private your Twitter/X account when viral activity is detected. Monitors follower spikes and mention surges, then automatically switches the account to protected mode.
Runs on a schedule via macOS launchd (every 15 minutes). Each run:
- Fetches current follower count and notifications via twikit
- Compares against a rolling 24-hour baseline
- Detects spikes using two methods:
- Adaptive: current delta > 3x rolling average delta
- Static floor: current delta >= 100 followers
- If spike detected → sets account to private and sends a push notification via ntfy.sh
- Account stays private until you manually change it back
uv sync --all-extras- Open x.com in your browser and log in
- Open DevTools → Application → Cookies →
https://x.com - Copy the values for
ct0andauth_token
cp .env.example .envEdit .env with your values:
CT0=your_ct0_cookie_value
AUTH_TOKEN=your_auth_token_cookie_value
SCREEN_NAME=your_twitter_username
NTFY_TOPIC=your_unique_topic_name
- Install the ntfy app on your phone
- Subscribe to your chosen topic name (same as
NTFY_TOPICin.env)
uv run python -m src.shieldThis will fetch your current metrics and write the initial state.json. No spike detection on first two runs (needs baseline data).
Copy the provided plist to your LaunchAgents directory:
cp com.aliir74.x-shield.plist ~/Library/LaunchAgents/Edit the plist to update paths if needed, then load it:
launchctl load ~/Library/LaunchAgents/com.aliir74.x-shield.plistVerify it's running:
launchctl list | grep x-shieldTo stop:
launchctl unload ~/Library/LaunchAgents/com.aliir74.x-shield.plistLogs are written to cron.log in the project directory.
X Shield does not auto-revert to public. To go public again:
- Go to x.com/settings/audience_and_tagging
- Uncheck "Protect your posts"
- Update
state.jsonand set"is_protected": false
uv run python -m src.shield --testThis triggers protect + notify immediately without needing spike data.
uv run pytestWith coverage:
uv run pytest --cov=src --cov-report=term-missingConstants in src/shield.py:
| Constant | Default | Description |
|---|---|---|
SPIKE_MULTIPLIER |
3.0 | Adaptive threshold multiplier |
STATIC_FLOOR |
100 | Minimum follower delta to trigger |
CHECK_WINDOW_HOURS |
24 | Rolling window for baseline calculation |
If you find this project useful, consider supporting its development:
- Star this repo
- Report bugs and submit PRs
- Sponsor on GitHub or Buy me a coffee