Tracking down a Zsh history data loss bug
47 points by stapelberg
47 points by stapelberg
Pleasantly surprised by this because I've been complaining about zsh losing my history entries for years and I'm excited about the possibility that this could be the fix.. Kudos to the author for tracking this down.
The fix: https://github.com/zsh-users/zsh/commit/bacc78ec3f
This is tagged as zsh-5.9.0.2-test, so I guess 5.9.0.2 is the earliest version that'll have the fix.
Actually, even better! Quoting from my article:
Zsh 5.9.2 (released July 12th, 2026) contains a fix for this issue — open it after reading this investigation to not spoil the fun.
I don't think I have observed this bug. However, I am sharing the history between different shells and sometimes, one shell does not see the history of another. I did not try to investigate more than that since it is infrequent.
I'm not an expert but I had the same problem and I investigated it a little bit a while ago. My understanding is zsh appends the history files as you run commands but only reads the history once on startup (or when you change the directory if you're using the per-directory history script). So the shell keeps updating the history file but doesn't receive the updates made by other shells.
I have this in my zshrc to work around this: (this is using the per-directory history script)
function per-directory-history-sync() {
[[ $_per_directory_history_is_global == true ]] && return
fc -RI $_per_directory_history_directory
zle -I
echo "Per-directory shell history reloaded"
}
zle -N per-directory-history-sync
bindkey "^O" per-directory-history-sync
When I need the update the shell history I just press C-o and get them manually.
Alternatively you could just do cd .. and cd - and it should re-read the directory's history.
With setopt share_history, Zsh reads the history after each command. Enter echo hello in one shell, then on the second press enter and up arrow and you should get echo hello.
I don't think that option works with per-directory histories. I've had that enabled since 2018 but I still need the function above. (just added it a few weeks ago actually)
I have indeed run in to this same problem and always assumed I was doing something wrong. I switched to atuin and never looked back, but it's good to know I wasn't imagining things.
Thanks for this excellent writeup! As always, I found it helpful how you describe so many advanced tools in a way that's approachable to people who have no experience with them.
I really enjoyed the benchmarking part. I'd be interested in an entire post on that.
Thanks for the kind words, and the feedback on expanding on the evals.
Yeah, there’s definitely a lot to expand on.
I’d be curious if anyone found better eval tools than Inspect. In particular, I found the leaderboard / result browser unintuitive and kept losing track of different approaches.
With better tooling, it’d be interesting to try different harnesses (and also orchestration approaches) — it’s odd that so many models run into time limits when I don’t see that behavior in coding agents day-to-day. Maybe they don’t have a task list tool available, or are lacking a scratchpad, or don’t have a memory tool, or similar…?
That said, running such evals with frontier models costs a lot of money very quickly. I think at this point, I have spent well over 500 USD in total (I did a few more experiments on top of what I described in the post). So doing it as a personal hobby is quite expensive.
Is it possible to run the evals under an unlimited plan like Claude Max? I know you'd need one subscription per vendor, but you presumably already have at least one. And then there's OpenCode Go that gets you all the open weight models for $10/mo.