I'm trying to use tmux inside emacs for a long time. I want to use it to attach to remote (long living) session. Attaching to sessions works fine but I have some problems in my daily workflow because find-file does not work properly inside a tmux session.

To reproduce my problem:

M-x term


if you now do find-file (C-c C-j to enter line-mode, than C-x C-f) it will start at your current location. Change your directory using cd, than redo find-file, everything should look like expected.

Now create a tmux session inside your term

tmux new -s test

pwd ;; your current location (1)

find-file should start from (1) now cd to another directory, do find-file and it will still starts at (1)

The reason for that is, that the variable default-directory is not changed, when changing the directory inside a tmux session.

Does anybody has an idea how to fix this?

  • Just to clarify you are running tmux inside a term session of emacs not running emacs inside a tmux session?
    – stsquad
    Dec 4, 2018 at 9:49
  • Yes, I'm running tmux inside a term session of emacs.
    – zngguvnf
    Dec 4, 2018 at 10:27
  • I've had difficulties with the behavior of default-directory, too. Maybe one of my workarounds will work for you: emacs.stackexchange.com/questions/44759/… Let me know and I can type up a formal answer. Dec 4, 2018 at 21:05

1 Answer 1


term handles the changing of directories by the sub-shell by parsing ANSI terminal commands. See the function term-handle-ansi-terminal-messages. I can't seem to run tmux inside my term but I suspect the solution is to ensure the PS1 for the shell is correctly emitting the ANSI escape codes when the directory is changed. Maybe tmux is squashing those itself?

  • Thanks for your reply. What do you get for an error message when you start tmux. Can you give me a hint to check whether emitting the ANSI escape code works properly?
    – zngguvnf
    Dec 4, 2018 at 10:32
  • I don't see an error message, it just scrolls some stuff quickly beforing clearing the screen and reporting [exited]. This may be a result of running in a Termina VM on my Chromebook so it could be something about that setup although tmux runs fine in the terminal.
    – stsquad
    Dec 4, 2018 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.