Shared history lets multiple Zsh terminals exchange commands through the same history file while those terminals are still open. It helps when work moves between tabs or panes and the last command from one shell should be available in another without closing either shell.
Interactive Zsh stores history through HISTFILE, HISTSIZE, SAVEHIST, and history options. share_history appends typed commands to the history file and imports entries written by other Zsh shells that use the same HISTFILE.
A safe verification path writes sample command text with print -s, then imports and lists it from a second Zsh process. That proves the shared-history path without running real deployment commands.
Related: How to manage Zsh command history
Related: How to set Zsh shell options
$ touch ~/.zshrc $ cp ~/.zshrc ~/.zshrc.bak
HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history"
HISTSIZE=5000
SAVEHIST=5000
unsetopt inc_append_history
unsetopt inc_append_history_time
setopt share_history
setopt hist_ignore_dups
share_history already performs the append behavior needed for active terminals. Keep inc_append_history and inc_append_history_time off when share_history is enabled.
$ zsh -n ~/.zshrc
No output means Zsh parsed the startup file without finding a syntax error.
$ source ~/.zshrc
$ printf 'HISTFILE=%s\nSAVEHIST=%s\nshare_history=%s\ninc_append_history=%s\n' "$HISTFILE" "$SAVEHIST" "$options[sharehistory]" "$options[incappendhistory]" HISTFILE=/home/user/.zsh_history SAVEHIST=5000 share_history=on inc_append_history=off
$ zsh -ic 'print -s "deploy --dry-run"; print -s "deploy --apply"; print -r -- "history_written=yes"' history_written=yes
print -s adds a command to the history list without executing that command, which keeps the verification safe.
$ fc -RI
$ fc -l 1
1 deploy --dry-run
2 deploy --apply
fc -RI imports entries that other Zsh shells wrote after this shell started. A newly opened interactive terminal usually imports the file during startup, but the explicit import keeps the check repeatable.
Shared history can expose sensitive commands across terminals sooner than exit-time history saving. Avoid typing secrets directly into commands, and remove accidental secret-bearing entries before sharing logs.