How to configure zsh to clear history on exit?

This used to be the default behavior on iTerm2 before I upgraded to macOS Calalina.


This is not configured in iTerm2, but is set by macOS in Zsh itself. Since macOS Catalina, the file /etc/zshrc contains the following:

HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
HISTSIZE=2000
SAVEHIST=1000

This causes the last 1K lines of history to be saved on exit.

To override this, add the following to your ~/.zshrc file:

unset HISTFILE SAVEHIST

Documentation: http://zsh.sourceforge.net/Doc/Release/Parameters.html#index-SAVEHIST