Skip to content

fix: detached new-window/split-window inherit the caller's working directory (tmux parity) - #101

Closed
marhel wants to merge 3 commits into
Helvesec:mainfrom
marhel:fix/new-window-caller-cwd
Closed

fix: detached new-window/split-window inherit the caller's working directory (tmux parity)#101
marhel wants to merge 3 commits into
Helvesec:mainfrom
marhel:fix/new-window-caller-cwd

Conversation

@marhel

@marhel marhel commented Jul 13, 2026

Copy link
Copy Markdown

Fixes #99

Summary

A detached new-window or split-window invoked without an explicit -c
inherited the session's original start directory instead of the working
directory of the process that issued the command. tmux uses the caller's
working directory in this case, so running either command from a directory
other than the one the session was created in diverged from tmux.

Both commands are covered here so the issue can be closed as a whole.

Reproduction (Linux, isolated sockets)

SOCK=cwdchk
S=$(mktemp -d); C=$(mktemp -d)               # S = session dir, C = caller dir

( cd "$S" && rmux -L $SOCK new-session  -d -s s0 )
( cd "$C" && rmux -L $SOCK new-window   -d -t s0 -P -F '#{pane_current_path}' )
( cd "$C" && rmux -L $SOCK split-window -d -t s0 -P -F '#{pane_current_path}' )
command tmux rmux (before) rmux (after)
new-window $C (caller) $S (session) $C
split-window $C (caller) $S (session) $C

Verified head-to-head against tmux 3.2a on Linux.

Cause

The CLI forwarded only an explicit -c value and sent None otherwise, so the
server fell back to the session's cwd. new-session already falls back to the
caller's working directory in the same situation — new-window and
split-window simply didn't.

Fix

Fall back to the caller's current working directory when no start directory is
given, mirroring new-session. The server already prefers an explicit start
directory over the session cwd, so no server change is needed.

  • Extracted a shared caller_current_working_directory() helper in crate::cli.
  • new-window: applied the fallback in run_new_window.
  • split-window: applied it in both the target-action and legacy paths, and in
    the request-variant routing condition (the plain SplitWindow request cannot
    carry a start directory, so a resolved cwd now routes through SplitWindowExt).

Tests

A single parametrized regression test (tests/detached_caller_cwd.rs) runs the
same scenario for both subcommands: it creates a session in one directory and
runs the detached command from another, asserting the new pane inherits the
caller's directory. RED before the fix (for the command not yet fixed), GREEN
after.

Docs

Added a row to docs/tmux-compat-decisions.md recording this as ISO required
(rmux must match tmux), backed by the regression test per the doc's CI policy.

Checks

  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo build --workspace — clean
  • cargo test --workspace --all-targets — all green except one pre-existing,
    environment-sensitive rmux-server live-attach PTY test
    (live_attach_large_bracketed_paste_survives_irregular_chunks,
    handler_send_keys_tests/input_capture.rs). This change touches zero
    rmux-server files, so that test binary is unaffected by it.

Tested on Linux and Windows.

marhel and others added 3 commits July 13, 2026 23:43
A detached `new-window` invoked without an explicit `-c` inherited the
session's original start directory instead of the working directory of
the process that issued the command. tmux uses the caller's working
directory here, so running `new-window` from a directory other than the
one the session was created in diverged from tmux.

Fall back to the caller's current working directory when no start
directory is given, mirroring what `new-session` already does. Add a
regression test that creates a session in one directory and runs a
detached `new-window` from another, asserting the new pane inherits the
caller's directory.

Tested on Linux.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Martin Hellspong <martin.hellspong@factor10.com>
A detached `split-window` without an explicit `-c` inherited the session's
original start directory instead of the caller's working directory, diverging
from tmux (same bug already fixed for `new-window`). Apply the caller-cwd
fallback in both the target-action and legacy split paths, extracting the
shared `caller_current_working_directory` helper. Parametrize the caller-cwd
regression test over both subcommands.

Tested on Linux.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Martin Hellspong <martin.hellspong@factor10.com>
…reation

Add a compatibility-matrix row noting that a detached `new-window` or
`split-window` without an explicit `-c` inherits the caller's working
directory rather than the session's start directory, matching tmux. Both
paths are now fixed and covered by a parametrized regression test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Martin Hellspong <martin.hellspong@factor10.com>
@shideneyu

Copy link
Copy Markdown
Contributor

Thanks @marhel — this work was incorporated in adapted form in 7069f01 and shipped in RMUX v0.9.0. The released implementation covers new-window and split-window across the full CLI, tiny CLI and queued/source-file paths. Contributor attribution was preserved.

Thank you again !

@shideneyu shideneyu closed this Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tmux parity: new-window / split-window ignore the caller's cwd

2 participants