Terminal assigns each terminal session a unique identifier and communicates it via the TERM_SESSION_ID environment variable so that programs running in a terminal can save/restore application-specific state when quitting and restarting Terminal with Resume enabled.
A new folder (~/.bash_sessions/) is used to store HISTFILE's and .session files that are unique to sessions.
During shell startup the session file is executed. Old files are periodically deleted.
The default behavior arranges to save and restore the bash command history independently for each restored terminal session. It also merges commands into the global history for new sessions.
You may disable this behavior and share a single history by setting
If HISTTIMEFORMAT is defined, per-session history is disabled by default (read more in /private/etc/bashrc_Apple_Terminal)
The save/restore mechanism is disabled if the following file exists:
Apple already changed some behavior since El Capitan release, so it is better to go read more about this here