Skip to content

fix(tmux): fix argument ordering that breaks spawned sessions#899

Closed
ljk53 wants to merge 1 commit intoslopus:mainfrom
ljk53:fix/tmux-spawn-argument-ordering
Closed

fix(tmux): fix argument ordering that breaks spawned sessions#899
ljk53 wants to merge 1 commit intoslopus:mainfrom
ljk53:fix/tmux-spawn-argument-ordering

Conversation

@ljk53
Copy link

@ljk53 ljk53 commented Mar 23, 2026

Two bugs in tmux argument construction cause daemon-spawned sessions to fail silently:

  1. executeTmuxCommand() appends -t <session> AFTER all args including the shell-command positional argument. tmux follows POSIX-style parsing where flags after a positional arg are treated as part of that positional arg. This means the spawned process receives -t <session> as extra argv, causing it to exit immediately. The tmux window is created but dies instantly with no log output.

    Fix: insert -t right after the subcommand name, before other args.

  2. spawnInTmux() appends -P -F "#{pane_pid}" AFTER the shell-command argument. Same POSIX parsing issue — tmux never sees -P as its own flag, so it never prints the pane PID. The daemon then fails with "Failed to extract PID from tmux output".

    Fix: push -P and -F before the shell-command (which must be last).

Both bugs are masked because tmux still creates the window (returning exit code 0), but the spawned process dies immediately. The daemon falls back to regular process spawning, making it appear as if tmux integration silently does nothing.

Tested on tmux 3.2a, Linux.

Generated with Claude Code via Happy

Three bugs in tmux argument construction cause daemon-spawned sessions
to fail silently:

1. spawnInTmux() appends `-P -F "#{pane_pid}"` AFTER the shell-command
   argument. tmux treats everything after the first positional arg as
   part of the shell command, so -P is never seen by tmux. The daemon
   fails with "Failed to extract PID from tmux output".

   Fix: push -P and -F before the shell-command (which must be last).

2. executeTmuxCommand() appends `-t <session>` after all args including
   the shell-command. Same POSIX parsing issue — the spawned process
   receives `-t <session>` as extra argv and exits immediately.

   Fix: build fullCmd with cmd[0] first, insert -t, then append
   remaining args with cmd.slice(1).

3. For `new-window`, `-t 0` is ambiguous when the session name is
   numeric — tmux interprets it as "target window index 0" rather than
   "session named 0", failing with "index in use".

   Fix: append `:` to session name for new-window (i.e. `-t 0:`) so
   tmux treats it as a session target with auto-assigned window index.

All three bugs are masked because tmux returns exit code 0 and the
daemon silently falls back to regular (non-tmux) process spawning.

Tested on tmux 3.2a, Linux.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@ljk53 ljk53 force-pushed the fix/tmux-spawn-argument-ordering branch from 18b1bbe to 34411c4 Compare March 23, 2026 00:06
@ljk53 ljk53 closed this Mar 23, 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.

1 participant