Minor updates to @michael-ekstrand answer
tmux calls with simnple builtin tests$SSH_AUTH_SOCK contains whitespaceif [[ -n $TMUX ]]; then
_update_ssh_agent() {
if ! [[ -S $SSH_AUTH_SOCK ]]; then
eval "$(tmux show-environment -s SSH_AUTH_SOCK 2>/dev/null)"
fi
}
add-zsh-hook precmd _update_ssh_agent
fi