As per the Emacs docs, every time you open a file, Emacs changes default-directory to the directory containing that file.
default-directory
Then, if the cursor is in th
Another variant is to bind default-directory to the necessary directory in directory-local variables, e.g. in the .dir-locals.el file in one of your parent directories to something like:
((nil . ((default-directory . "~/.emacs.d/"))))