I'm looking for a way to do something like this without attaching to the session.

tmux attach-session -c <directory> -t <session>

Per tmux(1), there isn't a way to change the default working directory (new windows and new panes) of an entire session without attaching to it.

I cannot attach to the session because I'm doing this in some automated scripts where attaching would break the automation.


You can simply

tmux attach -c directory -s session 2> /dev/null &

the attaching will exit immediately as the forked background job is not a terminal. But it will succeed in changing the working directory of the tmux session.



`tmux send-keys -t <session> 'cd <directory>'`

do what you want?

Unsure if this would apply to new windows / panes created after this, but the poor man's workaround would be just to send this to <session>:<windowID>.<paneID> after creating that window/pane.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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