Launch a new tmux session from the right directory — without polluting the current one

Tools like team and adhoc (from the mux-relay framework) derive the project root from $PWD at invocation time. The natural instinct is to open a new tmux window, cd to the target directory, then run the command. That works, but it leaves a ghost window in the original session — and if that window gets cleaned up or the session reshuffles, pane working directories can silently drift to deleted paths.

A subshell avoids all of that:

(j my-project && team)

The parentheses spawn a subshell. Inside it, j (zoxide) changes directory to the project, then team launches the new session with the correct $PWD. Because new-session -d is detached and switch-client handles the jump, the new session is fully independent — no nesting, no leftover windows.

When the subshell exits (right after team returns), the original pane's $PWD is untouched. You never left it.

This pattern works for any command that reads $PWD but doesn't accept a -C / --directory flag:

(cd ~/Projects/something && explore)
(cd $(z resolve another-project) && adhoc claude)

One pane, one command, zero side effects.

Comments

  1. Markdown is allowed. HTML tags allowed: <strong>, <em>, <blockquote>, <code>, <pre>, <a>.