The code for this is in /etc/{bashrc,zshrc}_Apple_Terminal
, it includes details about configuration options and also lists the way to disable it as a whole.
To disable in zsh
# The save/restore mechanism as a whole can be disabled by setting an
# environment variable (typically in `${ZDOTDIR:-$HOME}/.zshenv`):
#
# SHELL_SESSIONS_DISABLE=1
To disable in bash
# The save/restore mechanism is disabled if the following file exists:
#
# ~/.bash_sessions_disable