On macOS, there is a sessions directory that combines commands from multiple zsh sessions into a single history file.

Is it necessary to use shell options in the .zshrc file, to manipulate how zsh handles history, so that commands are appended to .zsh_history, or are these options redundant and ignored?

I see many people recommend, when transitioning from bash to zsh, to add the following options to make history include commands from other sessions and add other functionality (that appears to be built in):


However, it seems those are built in and needn't be specified.

Bonus question: Can one list multiple shell options after a single setopt, instead of having each option in a separate setopt statement?


On macOS, /etc/zshrc contains (among other things), the following lines:

# Save command history

This is the reason you don't need to set those on macOS: It's already done for you. However, you are of course free to override these values in your .zshrc file. (Note, though, that it's recommended to make $HISTSIZE at least 20% larger than $SAVEHIST. Read https://zsh.sourceforge.io/Doc/Release/Options.html#History for more info.)

If (and only if) you are using Apple's Terminal.app, then /etc/zshrc in turn calls /etc/zshrc_Apple_Terminal. In there, we find (among other things):

# Resume Support: Save/Restore Shell State

followed by a bunch of code ported from macOS's /etc/bashrc_Apple_Terminal. In , this code is largely unnecessary, as the Z Shell can do the same with just setopt sharehistory.

To use Zsh's implementation instead of Apple's:

  • Add to your .zshenv file:
  • Add to your .zshrc file:
    setopt sharehistory
  • In your Zsh dotfiles, make sure you don't set any options incompatible with SHARE_HISTORY. Again, read https://zsh.sourceforge.io/Doc/Release/Options.html#History for more info.
  • Delete the .zsh_sessions dir created by Apple's code.

Bonus question: can we list options after setopt instead of having each one on a new line?

Yes, you can pass as many options as you like to setopt. Just try it on the command line.

You must log in to answer this question.

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