Separate zsh histories after restart (iTerm2)

itermterminalzsh

I am running iTerm2 (v 3.2.9) and zsh (v 5.7.1). I normally have 3-4 iTerm tabs opened at the same time and each tab has its own history thanks to the following settings in my .zshrc file

SAVEHIST=10000 # Number of entries
HISTSIZE=10000
HISTFILE=~/.zsh_history

unsetopt inc_append_history
unsetopt share_history
setopt appendhistory

However, when I close and re-open iTerm2 all tabs share the same history (I suppose they are reading from the very same HISTFILE): for example, if I have two tabs (say A and B), where the last command from A is foo and the last command from B is bar, when I close and re-open iTerm2 both tabs see either bar or foo (depending on the latest command which has been run, regardless of A or B) as the last entered command (arrow up key).

My question is: it is possible to keep separate histories even after re-launching iTerm2?

Best Answer

I don't use iTerm, but I think this is a property of its Session Restoration feature: https://iterm2.com/documentation-restoration.html

Try turning it off and see if it makes any difference.

Besides, starting with macOS Big Sur, you don't even need this feature. macOS now comes with "Resume Support: Save/Restore Shell State", which is by default enabled for both Bash and Zsh, no matter what terminal you use, and which support per-session history. Read the file /etc/zshrc_Apple_Terminal for more info.