Workspaces & Terminal

Git worktrees & launch dialog

Launch AI agents with an optional initial prompt inside isolated per-tab Git worktrees, with safe dirty-checked cleanup when closing the tab.

Running two agents on the same working directory causes file conflicts and broken git status states. muxbay solves this with the unified Launch Session dialog: launch any built-in agent or custom CLI profile with an optional Initial Prompt inside its own isolated Git worktree.

The Launch Session dialog

While every 1-click quick-launch entry in the + tab menu (and mobile new-tab sheet) remains intact, choosing Launch Session… opens the full launcher:

  1. Agent or Profile — pick any built-in target (Claude, Codex, Gemini (agy), Pi, Oh My Pi (omp), Terminal) or any enabled custom CLI Profile configured in Settings → CLI Profiles.
  2. Initial Prompt (optional) — write a multi-line task prompt (submit anytime with ⌘Enter / Ctrl+Enter).
  3. Isolated Git Worktree (toggle) — create or attach a dedicated branch checkout for this tab.
  4. Tab Name (optional) — defaults to the branch name (for worktree tabs) or the profile name.

Server-side Initial Prompt delivery

Typing a prompt into a newly spawned agent tab often fails if the CLI is still booting or pauses on a folder trust prompt.

muxbay queues the initialPrompt on the server (src/lib/initial-prompt-delivery.ts) and waits until the agent reaches cliState === 'idle':

  • It automatically waits through startup and any needs-input folder trust confirmation.
  • Once ready, it delivers the text safely via tmux send-keys -l / bracketed paste (sendPromptText), followed by submission.
  • If you picked a CLI Profile with a defaultPrompt, the Launch Session dialog pre-fills it automatically so you can review or tweak it before launching.

Isolated Git worktrees per tab

When Create isolated worktree is enabled inside a workspace pointing to a Git repository (GET /api/git/worktrees):

  • Base branch — choose from all local and remote branches detected in the repo.
  • Branch name — validated in real time (isValidGitBranchName). Click Suggest branch to auto-generate a clean slug from your Initial Prompt (for example feat/fix-oauth-callback).
  • Use existing branch — if the local branch name already exists, a checkbox lets you attach the worktree to that existing branch instead of failing.

Where worktrees live and how workspaces stay clean

Managed worktrees are created at:

~/.purplemux/worktrees/<repo>-<hash>/<slug>-<id>/
  • Worktree tabs display a purple GitBranch badge in the tab bar showing the branch name.
  • Right-click the tab and choose Copy worktree path to copy the exact directory path to your clipboard.
  • Workspace root safety: opening or focusing a worktree tab never overwrites the workspace's primary root directory (directories[0]), so new standard tabs still start in your main repository.
Auto-enable worktrees per CLI Profile
In **Settings → CLI Profiles**, toggle **Use Git worktree by default** on a profile (such as a code-review or refactor preset) so the Launch Session dialog enables worktree isolation automatically whenever you select that profile.

Multi-Agent Compare (Fan-out)

Switch Launch Session… to Compare agents to benchmark or race multiple agents on the exact same task:

  1. Select two or more providers (Claude, Codex, Gemini (agy), Pi, Oh My Pi (omp)).
  2. Enter your Initial Prompt once — every selected agent receives it as soon as its session becomes idle.
  3. With Isolated Git worktree enabled, each agent gets its own suffixed branch (<branch>-claude, <branch>-agy, <branch>-codex) so diffs never collide and can be compared side by side.

Push branch & Create PR (gh pr create)

Right-click any worktree tab and choose Push / Create PR… (WorktreePrDialog, backed by /api/git/worktree-pr) to complete the branch lifecycle from the browser:

  • Inspect ahead commit count, live diff --stat against the base branch, and uncommitted file warnings.
  • Detect any existing pull request via GitHub CLI (gh pr view) or fill in a PR title, description, and optional Draft PR flag.
  • Choose Push branch (git push -u origin <branch>) or Push & Create PR (gh pr create).

Safe cleanup on tab close

When you close a tab backed by a worktree, muxbay opens the Worktree Close Dialog (WorktreeCloseDialog) instead of silently deleting files:

  1. It runs a live status check (GET /api/git/worktrees?statusPath=...) to detect uncommitted or untracked changes (dirty + changed file count).
  2. You choose what happens next:
    • Keep on disk — closes the tab and tmux session while keeping the worktree directory and branch intact.
    • Remove worktree — removes the directory (if uncommitted changes exist, you must explicitly check Force remove even with uncommitted changes first).
    • Also delete branch — optional checkbox to delete the local Git branch when removing the worktree.
Path-containment guard
Server-side removal validates every path through `isManagedWorktreePath` so only worktrees inside `~/.purplemux/worktrees/` can ever be deleted automatically — your main repository directory is never at risk.

What's next