I use ZSH with Oh My Zsh. I would like each new ZSH shell to start with an empty history. Commands typed in one shell should never show up in the history of another shell. How can I achieve this?

I've tried appending the following to my ~/.zshrc to no avail:

setopt no_share_history
unsetopt share_history
unsetopt inc_append_history
unsetopt append_history

I have also tried following this answer to make the arrow keys only show local history, but that seemed to have no effect.

Currently, if I open a new shell, it imports history. I cannot seem to delete the history; when I delete ~/.zsh_history, it re-appears with the entire old content once I open a new shell. inc_append_history does prevent history from being written right away, but the history will still eventually be saved once the shell is closed.

2 Answers 2


Add this to your ~/.zshrc file:

function erase_history { local HISTSIZE=0; }

It will erase the history each time you start an interactive zsh shell.

  • Somehow I missed this ingenious solution. I had come across how to clear history before. However, I was too focused on preventing it from being written in the first place so I did not consider just clearing it every time I start a new shell.
    – bgfvdu3w
    Commented Jun 2, 2020 at 5:39
  • 1
    You could shorten that to (){ local HISTSIZE=0; } Commented Jun 2, 2020 at 6:23

The zsh history is only saved if you set both the HISTFILE variable (to the path of the history file) and SAVEHIST variable (to the amount of entries to store there).

So it should only be a matter of removing those variable definitions from wherever they're being set (probably your ~/.zshrc or any file included from there). Even not setting only one of them would be enough.

Note that setopt no_share_history and unsetopt share_history (or set +o nonosharehistory, etc or options[sharehistory]=off) are strictly equivalent.

  • Thanks. I think I like this approach more because, if I understand correctly, it prevents history from being written in the first place. For posterity, I appended unset SAVEHIST to my ~/.zshrc and it worked like a charm.
    – bgfvdu3w
    Commented Jun 2, 2020 at 5:41
  • @bgfvdu3w, note that those variables are not set by default, so it must be set by some of your startup scripts. You could run zsh -x from within script and then do grep -we HISTFILE -e SAVEHIST typescript to figure out where it is. Commented Jun 2, 2020 at 6:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .