Disable zsh session folder completely

I recently switched from ubuntu to macOS Big Sur 11.1, and apple is using zsh as their default shell .The .zsh_sessions folder is taking up about 100 MB and I want to disable it completely ,although I could delete normally.

I have added following in my .zshrc but it was of no use

set hist_ignore_all_dumps

setopt hist_ignore_space

setopt HIST_NO_FUNCTIONS

SHELL_SESSION_HISTORY=0

I want to disable creation of .zsh_sessions folder completely .

P.S:- I have already asked question here,but answers was not found.


Solution 1:

macOS's "Save/Restore Shell State" feature for Zsh is initialized in /etc/zshrc_Apple_Terminal. As it says in that file, to disable the feature, you need to

  1. Create a file ~/.zshenv, if you don't have one yet. Zsh will source this for each new shell, before sourcing /etc/zshrc, which, macOS, calls /etc/zshrc_Apple_Terminal.
  2. In the file ~/.zshenv, add the following:
    SHELL_SESSIONS_DISABLE=1
    

Read /etc/zshrc_Apple_Terminal for more info.


⚠️ Note: Despite its name, most environment variables (that is, export statements) should not be declared in ~/.zshenv. That file gets sourced for every single new Zsh instance, including non-interactive ones (such as when you run a script), meaning it will get sourced over and over. Be very careful what you put in there, because it can have serious impacts, particularly on performance.