6.9 Why does shell mode lose track of the shell’s current directory?

Emacs has no way of knowing when the shell actually changes its directory. This is an intrinsic limitation of Unix. So it tries to guess by recognizing ‘cd’ commands. If you type cd followed by directory with a variable reference (cd $HOME/bin) or with a shell metacharacter (cd ../lib*), Emacs will fail to correctly guess the shell’s new current directory. A huge variety of fixes and enhancements to shell mode for this problem have been written to handle this problem (see How do I find an Emacs Lisp package that does XXX?).

You can tell Emacs the shell’s current directory with the command M-x dirs.