Choosing the Right Zsh History Option: hist_ignore_space vs Alternatives
Pick the right Zsh history option for your workflow: compare hist_ignore_space, hist_ignore_all, hist_ignore_dups, and hist_no_function with a clear decision table and step‑by‑step validation guide.
09 Feb 2026, 16:51 UTC

Decision Context
When you configure zsh, you often decide how much of your command history should be kept. The hist_ignore_space option is a common choice for users who want to keep sensitive commands out of the history file while still retaining a useful log of other activity. This guide helps you weigh that option against the other history‑related flags that zsh offers.
Options Overview
Below are the four history options that most users consider:
- hist_ignore_space – Skip lines that start with a space.
- hist_ignore_all – Disable history recording completely.
- hist_ignore_dups – Skip consecutive duplicate entries.
- hist_no_function – Exclude function definitions from history.
All four are enabled with setopt and disabled with unsetopt. They can be combined, but the effects interact.
Trade‑Off Comparison Table
| Option | What it Does | Pros | Cons |
|---|---|---|---|
hist_ignore_space | Lines beginning with a space are not stored. | Selective privacy; keeps rest of history intact. | Hidden commands can hide bugs; some scripts may rely on history. |
hist_ignore_all | No history is recorded. | Maximum privacy; no accidental leaks. | Cannot reuse or search previous commands; debugging harder. |
hist_ignore_dups | Consecutive duplicates are collapsed. | Cleaner history; saves space. | Non‑consecutive duplicates still appear. |
hist_no_function | Function definitions are omitted. | Reduces clutter from scripts. | Functions cannot be recalled from history. |
When to Pick hist_ignore_space
If you occasionally run commands that contain passwords, tokens, or other sensitive data and you want those lines invisible in ~/.zsh_history but still want a full log of everything else, enable this option. It is the most granular privacy control.
When to Pick hist_ignore_all
Choose this when you never want any command logged—perhaps on a shared terminal or in a highly restricted environment. Remember you lose the ability to replay commands with history or fc.
When to Pick hist_ignore_dups
Use this if you frequently repeat the same command in a row (e.g., sudo apt update). It keeps the log tidy without affecting unrelated commands.
When to Pick hist_no_function
If you load many shell scripts that define functions, you may want to exclude those definitions from history to avoid clutter. This is useful for developers who prefer a clean command list.
Concrete Implementation & Validation
Below is a step‑by‑step example that demonstrates enabling hist_ignore_space, verifying it works, and rolling back if needed.
- Check Current State
# Run in a fresh zsh session setopt -q hist_ignore_space && echo "enabled" || echo "disabled" # Expected output: disabled - Enable the Option
setopt hist_ignore_space # Add to ~/.zshrc to persist across sessions - Run a Space‑Prefixed Command
echo "secret data" - Verify It Is Omitted
fc -l | grep "secret data" # No output should appear - Run a Normal Command
ls - Verify It Is Recorded
fc -l | grep "ls" # Should list the ls command - Rollback (if desired)
unsetopt hist_ignore_space # Verify again: the space‑prefixed command will now appear in history
Practical Verification Checklist
- Confirm
zshversion is 5.8 or newer (options behave consistently). - Run
setopt -qto test whether it is already set. - Use
fc -l(orhistory) to list the last 10–20 commands. - Test with a command that contains a space‑prefixed secret to ensure it is omitted.
- Check that non‑space commands still appear.
Caveats & Rollback
Because hist_ignore_space only hides commands from the history file, the commands still execute and can be traced through other logs (e.g., shell debugging or ps output). If your workflow relies on being able to replay or inspect every command, consider combining hist_ignore_space with hist_ignore_dups to keep the log useful while still protecting sensitive lines.
To revert to the default history behavior, simply run unsetopt hist_ignore_space and restart the shell. No history file modifications are required.
Final Decision Guideline
Use hist_ignore_space when you need selective privacy and still want a usable history. Use hist_ignore_all for full privacy at the cost of usability. Use hist_ignore_dups to reduce clutter, and hist_no_function to keep function definitions out of the log. Combine them thoughtfully, keeping in mind the trade‑offs outlined above.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.