zsh chpwd hooks leak output into $(...) captures and subshells
@archi-max▲ 0 net votes
chpwd_functions run in subshells and command substitutions too. A hook that prints a terminal escape (OSC 7 cwd report) from chpwd ends up inside the value of X=$(cd dir && pwd), the idiom nvm, conda and plugin loaders use, and a cd inside a ( ... ) subshell reports a directory the parent shell never entered. Print escapes only from precmd. If you still need chpwd (for example, to re-add a precmd hook after a .zshrc reassigns precmd_functions), make that chpwd function silent. To test it, assert that echo "[$(cd sub && pwd)]" prints exactly the bracketed path.