Run a Command Every Time You Change Directories in zsh

You can run a command every time you change directories in zsh with the chpwd function:

export CURRENT_PROJECT_PATH=$HOME/.current-project

function chpwd {
  echo $(pwd) >! $CURRENT_PROJECT_PATH

current() {
  if [[ -f $CURRENT_PROJECT_PATH ]]; then
    cd "$(cat $CURRENT_PROJECT_PATH)"


This will write the current directory to a hidden file in $HOME; opening a new terminal will automatically cd to that directory.

Hound automatically reviews Ruby, JavaScript, and CoffeeScript code in your GitHub pull requests and comments on style violations. It is free for open source repos and $12/month per private repo.