-
Notifications
You must be signed in to change notification settings - Fork 35
feat(switch): add --tmux flag to run worktree creation in tmux #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add --tmux flag to `wt switch` that runs the entire worktree creation (including all hooks) in a new tmux window/session instead of the current terminal. Behavior: - If already in tmux: creates new window and switches to it - If not in tmux: creates new session and attaches (default) - With --detach: creates detached session in background The shell stays open at the worktree path after completion, so you can start working immediately. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
I'm open to something like this. Can we discuss the options? Currently I use zellij, and my workflow is "new-tab", and then What's yours? What's the advantage of having "new-tab" be within worktrunk? |
Instead of failing or creating duplicates, --tmux now: - Attaches to existing session (when outside tmux) - Switches to existing window (when inside tmux) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Pass --execute and args through to the inner wt command when using --tmux. This enables launching editors/agents in the tmux session: wt switch --create feature --tmux --execute claude -- 'Fix bug' Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
The use case is agent-initiated worktree creation — Claude Code spawning parallel worktrees for handoffs that continue in the background. Your workflow works because you do the "new-tab" step manually, but when Claude wants to spawn a handoff there's no human to press new-tab first. It needs one atomic command that creates a detached session, creates the worktree inside it, runs the handoff, and continues in background. That said, open to a more general approach. Could do something like |
When a detached tmux session fails quickly (within 2 seconds), capture the output and display it in the original shell. This helps diagnose errors without having to attach to a dead session. Uses tmux's remain-on-exit option to keep the pane around for capture, then cleans up the session after extracting the error output. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Replace consecutive str::replace() calls with char-based iteration - Reduce function arguments by introducing TmuxSwitchOptions struct - Apply cargo fmt formatting Co-Authored-By: Claude Opus 4.5 <[email protected]>
tmux.rs uses .output() for quick status checks (session exists, window exists, capture pane) that don't need shell_exec logging. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update help snapshots and skill reference docs to include the new --tmux and --detach flags on wt switch. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Environment variables from the current shell are now exported in the tmux session, so hooks and commands have access to API keys, custom paths, and other env vars. Excludes internal vars like PWD, TMUX, SHLVL, etc. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Instead of embedding all env exports in the command string (which can exceed shell limits), write them to a temp file and source it. The file is removed after sourcing. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
this is actually a very cool pattern, I haven't tried it much myself, it could be great though I'm not sure it should be something in Worktrunk... am I right that this could be: tmux new-session -d -s fix-auth-bug "wt switch --create fix-auth-bug -x claude -- \
'The login session expires after 5 minutes. Find the session timeout config and extend it to 24 hours.'"...which is verbose, but tractable could we start by having it as a Tip / Pattern at first? my preference would be to get more reps from folks running this sort of workflow before adding a feature to Worktrunk, unless it unlocks something significant we can't otherwise do — wdyt? |
|
@max-sixty I like your suggestion, what about adding it as a skill that people can install? |
|
yes great! @claude can you draft a PR which adds this as a Tip & Pattern, and a section in our existing Claude Code Skill? |
|
Claude finished @max-sixty's task in 2m 16s —— View job • Task completedTodo List:
SummaryI've added the tmux pattern for agent handoffs to the documentation as a Tip & Pattern. The documentation includes: Pattern: Launch worktree creation in a detached tmux session for parallel agent workflows: tmux new-session -d -s fix-auth-bug "wt switch --create fix-auth-bug -x claude -- \
'The login session expires after 5 minutes. Find the session timeout config and extend it to 24 hours.'"Files updated:
The pattern includes examples for both tmux and zellij users, and explains that all hooks run inside the multiplexer session, with the shell staying open at the worktree path after completion. Branch: |
Summary
--tmuxflag towt switchthat runs worktree creation in a new tmux window/session--detachflag to run the tmux session in background instead of attachingUsage
Behavior
--tmux)--detachTest plan
--tmuxconflicts with--execute(clap enforced)--detachrequires--tmux(clap enforced)🤖 Generated with Claude Code