Bash History Not Preserved Between Terminal Sessions on Mac

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

export SHELL_SESSION_HISTORY=0

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:

~/.bash_sessions_disable

Apple already changed some behavior since El Capitan release, so it is better to go read more about this here less /private/etc/bashrc_Apple_Terminal


I noticed something similar after the El Capitan upgrade. Simply adding the file .bash_sessions_disable file in your home directory disables the new bash sessions and the .bash_history is back in use.

This Reddit thread has more info and further links.


You can solve RVM problem by updating to latest RVM version or executing this:

  echo 'shell_session_update' > $HOME/.bash_logout

See https://github.com/rvm/rvm/issues/3540 for more info.