Disabling zsh history for a given shell session

This last week I've been doing a few bits of working with secrets - some of which I've needed to store in local environment variables, or pass as arguments to commands, and I've been going in and scrubbing my ~/.zsh_history after the fact, to make sure the secrets don't retain in my history, on disk.

However, I wondered if there was a way to temporarily disable history storing. I started by asking GitHub Copilot, and GPT-4.1 responded with running the following:

unset  HISTFILE
export HISTSIZE=0
export SAVEHIST=0

This was actually a valid thing to do stops that zsh session from retaining any history, until you start a new shell, where it will be reset.

After running this, i.e. ~/.zsh_history won't contain any of the commands, other than noting that you disabled history.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

πŸ€– Content in this blog post includes code derived from the following LLMs:

PurposeModelNotes
Codegpt:4.1
Editorial supportNo usage
Prose (verbatim or edited)No usage
Images, visualisation, data and/or metricsNo usage

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.