By the time you noticed, it was already cloned, forked, cached, archived. That’s how PII leakage happens. It is fast, silent, and permanent. You don’t stop it by wishing you’d been more careful. You stop it by making it impossible to happen in the first place.
PII leakage prevention in Zsh starts at the shell, because that’s where secrets escape before they hit version control or logs. Developers often focus on server-side checks, but the damage is already done if sensitive data ever leaves your local environment. Using Zsh as your primary shell gives you hooks and features to stop PII leaks at the source.
Start with pre-execution checks. Zsh makes it simple to add a precmd or preexec function that inspects commands before they run. You can match against known PII patterns: email formats, credit card regex, national ID numbers. Block commands with risky arguments before they even touch the network or Git.
Enable command history control. Many leaks happen when credentials or personal info are accidentally typed into the terminal. Configure Zsh’s HIST_IGNORE and HISTCONTROL to prevent sensitive commands from being written to your history file at all. Once avoided, they cannot be retrieved, exfiltrated, or searched later.