Zsh precmd breaks history

The following as .zshrc or .bashrc does very close to what i want, insert a header at the top of the history of every shell session.

As is below, the bash and zsh functionality are very close to the same. in bash the insertion of the header is silent on standard out. This is what i prefer. in zsh the header appears on standard out. Not what i want but not a big deal, tho a bit weird for it to butt in after entering the first interactive command.

Seems tho like it ought to work great by changing “preexec” to “precmd”, but when i do, history is broken, nothing gets saved in history. Why?

if [ $ZSH_NAME ]
then emulate -R sh
     setopt extendedhistory incappendhistory PROMPT_PERCENT
else shopt -s histappend
HIShead(){ echo ===header $WINDOW $SUDO_USER;}
HISTwin(){ [[ $WINDo = $WINDOW ]]||{ WINDo=$WINDOW;HISneww;};}
if [ $ZSH_NAME ]
then #precmd(){ HISTwin;}       #breaks history
     preexec(){ HISTwin;}       #works but butts in after entering first command
     HISneww(){ fc -eHISplic;}  
     HISplic(){ echo \#$(HIShead)>|$1;}         #zsh, insert a header whenever WINDOW is new
else HISneww(){ history -s $(HIShead);}         #bash, same

reported as bug in opensuse tumbleweed zsh 1216391 – zsh precmd breaks history