I'm using zsh in macOS 13.

I sometimes want to just try out a few things in Terminal without wanting to keep any history or log of these once I close the Terminal window/tab. On other occasions I do want to keep the history though. So I created two profiles in Terminal, History and No History and then I launch whichever I need. I've even given both distinct background colours so I know which window is for testing.

I initially thought I'd do that upfront via set +o history under Preference > Profiles > Shell > Startup > Run, but that doesn't quite work.

I don't want to edit the ~/.zshrc because that'd mean no history for those occasions where I do want to keep the history.

I've also tried HISTCONTROL=ignoreboth and then preceding each command with a space, meaning it won't get recorded, but that only seems to work in bash and it's only a workaround and not a solution anyway.

How can I keep no record / history for specified profiles once I close the Terminal window?


2 Answers 2


From https://unix.stackexchange.com/questions/692913/temporarily-disable-history-in-zsh: you could try running the command unset HISTFILE on startup (instead of set +o history).

See also How to disable .zsh_history & .zsh_sessions on macOS? for another option.

(The first of these, unset HISTFILE, works for me. I haven't tried the second. This is with Ventura 13.0, in case the version of OS X matters.)

  • The nice thing about this solution is that I don't have to select "Terminate" at the end of the session. Nov 9, 2022 at 13:08

One way is set an environment variable in the run command for the profile.


TTT=hello zsh -l

Terminal.app Settings

Then in ~/.zshrc test for that environment variable

  • Thanks. Can you let me know what this command does? — I've had a look, but I don't have a .zshrc, only a .zsh_history and a .zsh_sessions. Nov 8, 2022 at 10:37
  • It sets an environment variable TTT. You can test it with an if statement to alter history configuration. Use echo $TTT to see what its value is
    – mmmmmm
    Nov 8, 2022 at 12:00
  • Thanks, but what does setting TTT to hello bring about? And what is zsh -l for? Nov 8, 2022 at 12:09
  • You need to look at some zsh tutorials as these are basic shell issues. Setting TTT allows zsh to use if statements depending on its value. zsh -l starts zsh as a login shell which is what Terminal.app does
    – mmmmmm
    Nov 8, 2022 at 12:49
  • Sorry, maybe I should've been clearer: I was wondering what if-statement is executed with TTT and why starting a login shell would not keep a history. Nov 9, 2022 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .