Member-only story
After Editing zsh History, Check the Running Shell Too
Not a Medium member? Read the full story for free.
You edit a command in the history file, inspect the saved text, and find the old command still listed by the open terminal. Checking the file again will not explain that mismatch: zsh also keeps an in-memory history list.
Before trusting a history-editing tool, check what the running shell lists after the edit and what its undo operation restores. The distinction is small enough to demonstrate without touching your real history.
A file path and a history list can disagree
This demonstration starts a separate zsh -f process, unsets HISTFILE, and creates two temporary fixture files. History persistence is disabled with SAVEHIST=0. It never loads or rewrites your real history, and fc -ln lists the fixture commands without executing them.
zsh -f <<'ZSH'
set -eu
unset HISTFILE
HISTSIZE=20
SAVEHIST=0
demo_dir=$(mktemp -d) || exit 1
trap 'rm -f -- "$demo_dir/before" "$demo_dir/after"; rmdir -- "$demo_dir"' EXIT
print -r -- 'echo old-name' > "$demo_dir/before"
print -r -- 'echo new-name' > "$demo_dir/after"
fc -p "$demo_dir/before" 20 0
HISTFILE="$demo_dir/after"
print -r -- 'File selected by HISTFILE:'
cat -- "$HISTFILE"
print -r -- 'Current history list:'
fc -ln 1
fc -p…







