How to automatically clear clipboard secrets and API keys on macOS

Why the macOS pasteboard is vulnerable, and how to scrub sensitive tokens automatically.

1. The Problem: Clipboard Snooping

On macOS, any running application or active browser tab can inspect the contents of NSPasteboard.general without requesting special permissions. When you copy an AWS Secret Key, OpenAI API key, or Stripe token, it remains in memory indefinitely until replaced.

2. The CLI Solution: Manual Clears with pbcopy

To clear the macOS pasteboard immediately from the terminal:

pbcopy < /dev/null

Or create a shell alias:

alias cpc="pbcopy < /dev/null"

To automatically clear the clipboard after 30 seconds via a background subshell:

(sleep 30 && pbcopy < /dev/null) >/dev/null 2>&1 &

3. The Native Solution: RedactBar

Remembering to manually clear the clipboard after every secret copy is impractical. RedactBar continuously inspects pasteboard updates using 100% on-device Shannon entropy heuristics and token format signatures. When a secret is detected, it offers instant one-click notification actions: Clear Clipboard, Copy Masked, or an automatic 30-second wipe timer.

Related Guides