If you use yazi as your terminal file manager, you’ve probably noticed something annoying: you navigate to a directory, quit yazi, and… you’re back where you started. Your shell didn’t follow you.

This is because yazi runs as a subprocess. It can’t change your shell’s working directory directly. But there’s a simple fix.

The wrapper function

Add this to your shell config (.zshrc, .bashrc, etc.):

function y() {
  local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
  yazi "$@" --cwd-file="$tmp"
  if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
    builtin cd -- "$cwd"
  fi
  rm -f -- "$tmp"
}

Now use y instead of yazi.

How it works

  1. Creates a temp file to store the exit directory
  2. Passes --cwd-file to yazi, which writes the current directory to that file when you quit
  3. Reads the file after yazi exits
  4. If the directory changed, cd into it
  5. Cleans up the temp file

That’s it. Seven lines, and now your shell follows yazi.

Why y?

Short to type. You’ll use it constantly. If you prefer yy or something else, just rename the function.


This is one of those small workflow improvements that adds up. I use yazi dozens of times a day, and not having to manually cd after navigating saves real time.