How to disable .zsh_history & .zsh_sessions on macOS?

Solution 1:

OK... Let me say this up front - in a blockquote to set it apart:

The answer to your question (and other zsh configuration questions) is dependent upon which macOS version you're using, and which terminal application you use. It is my opinion that Apple's well-intentioned (perhaps?), but ill-advised overreach is responsible for these dependencies. By this, I only mean to say that zsh is well-documented, and completely capable of handling your HISTORY preferences without any assistance from Apple. Yet, by their choosing to add their defaults to /etc/zshrc and /etc/zshrc_Apple_Terminal Apple makes it more difficult for users to change zsh defaults.
REFERENCE

All of that said, I don't know which macOS version you're running, and as my macOS is 10.15 Catalina, I couldn't verify my answer will work on your system. Also: this answer is partially redundant with an earlier answer on a similar topic, and so please refer to that answer for details I've omitted here.

Proposed Answer: Set SAVEHIST=0 and HISTSIZE=0

Open the file ~/.zshrc in your editor, and add (or modify if they exist) the following two lines which override the macOS defaults:

SAVEHIST=0
HISTSIZE=0

Ordinarily, one could put these changes into effect immediately by simply sourcing ~/.zshrc (. ~/.zshrc). However, given Apple's predilection for "improving" zsh, a reboot may be a better idea.

This change should prevent both session history and the history file from accumulating any command history. Catalina/10.15 (at least mine) does not have a file(s) named ~/.zsh_sessions. I don't know what its purpose is (other than possibly to retain session history?), but I don't believe it will override the above changes to ~/.zshrc.

Try this if you care to, and let us know if it works on your system. There are other things to try - this one seems simplest.