Clear terminal and prevent restoration
Final Solution:

Remove the Terminal saved state, located in:

~/Library/Saved Application State/com.apple.Terminal.savedState/*


Then, make that folder read-only so that it can't be written to.



You can use the clear command to clear your terminal window from within a script.  As noted on this other thread, the following commands in sequence will clear the current buffer, then the scroll back buffer:

clear &amp;&amp; printf '\e[3J'



  Please note:
  (The clear command looks up the appropriate sequence for clearing the screen for the current terminal, but the “erase scroll-back” escape sequence is custom and must be hard-coded. If you put this in a shell script that you don’t know for certain will only ever be run with Terminal, you should check that $TERM_APPLICATION is Apple_Terminal before sending it.)




Alternative 1

Turn off Terminal.app's window restore functionality:

defaults write com.apple.Terminal NSQuitAlwaysKeepsWindows -bool false




Alternative 2

You can also store sensitive information in the Secure Notes section within the Keychain Access utility.