tmuxp-plugin-worktree
A tmuxp plugin that lets you pick the git worktree a session starts in.
When the repository of a session's start_directory has more than one worktree,
tmuxp load <session> first shows a picker with the configured directory
preselected:
worktree>
Session myapp: pick a worktree (Enter = start, Esc = cancel)
> myrepo [main] (default)
myrepo-feature-x [feature/x]
myrepo-hotfix [hotfix/login]
Picking another worktree:
- moves every session, window and pane
start_directoryinside the repository into that worktree (relativecdcommands in your panes keep working), and abefore_scriptthat lives in the repository; - renames the session to
<session>-<worktree>(for examplemyapp-feature-x), so it can run next to the default session.
A branch may not have every directory your workspace uses. A directory that
exists in the default worktree but is missing in the chosen worktree is replaced
by its nearest existing parent, with a note on stderr (tmux would otherwise
silently start the pane in $HOME). Window and pane directories are checked
after before_script, so setup can create them first. The session directory is
resolved earlier to provide setup with a working directory.
A before_script the chosen worktree does not have, such as an untracked file,
keeps running from the default worktree. Its arguments are preserved, including
quoting and spaces; only the executable's path is rewritten.
With a single worktree, or when the start directory is not a git repository, nothing changes and no picker is shown.
Requirements
- tmuxp 1.73 or newer for the no-install setup (
workspace_builder_paths); tested with tmuxp 1.73, 1.74 and 1.76 - git
- fzf (optional; without it you get a numbered menu)
- Python 3.10 or newer (the Python that tmuxp runs on)
Installation
Option A: install from PyPI (recommended)
Install the package into the Python environment tmuxp runs in; then only the
plugins key is needed in your workspace files.
# tmuxp installed with pipx
pipx inject tmuxp tmuxp-plugin-worktree
# tmuxp installed with uv
uv tool install tmuxp --with tmuxp-plugin-worktree
# tmuxp installed with pip in a virtualenv (activate it first)
python -m pip install tmuxp-plugin-worktree
Not sure which one you have? which tmuxp tells you: ~/.local/bin/tmuxp
is pipx or uv, /opt/homebrew/... (or /usr/local/...) is Homebrew.
Homebrew installs tmuxp in a private virtualenv without pip, and brew upgrade
would wipe anything you add to it. To use the PyPI package, switch to pipx
(or use Option B):
brew install pipx && pipx ensurepath # open a new shell afterwards
brew uninstall tmuxp
pipx install tmuxp
pipx inject tmuxp tmuxp-plugin-worktree
To upgrade the plugin later:
pipx upgrade tmuxp --include-injected # pipx
uv tool upgrade tmuxp # uv
python -m pip install -U tmuxp-plugin-worktree # pip
session_name: myapp
start_directory: ~/code/myrepo
plugins:
- tmuxp_plugin_worktree.WorktreePlugin
windows:
- window_name: editor
panes:
- nvim
Option B: no install (works with Homebrew's tmuxp)
Homebrew installs tmuxp in a private virtualenv without pip. Since 1.73, tmuxp
can add import paths per workspace with workspace_builder_paths, so you can
point it at a checkout instead:
git clone https://github.com/rhelling/tmuxp-plugin-worktree.git ~/Documents/Projects/tmuxp-plugin-worktree
session_name: myapp
start_directory: ~/code/myrepo
workspace_builder_paths:
- ~/Documents/Projects/tmuxp-plugin-worktree/src
plugins:
- tmuxp_plugin_worktree.WorktreePlugin
windows:
- window_name: editor
panes:
- nvim
Relative entries in workspace_builder_paths are resolved against the directory
of the workspace file.
Check that it works
tmuxp load myapp # picker when the repo has 2+ worktrees
WT_PATH=myrepo-feature-x tmuxp load -d myapp # straight into that worktree, detached
Usage
- fzf picker: Enter starts the highlighted entry (the default is preselected),
typing filters the list, Esc or Ctrl-C cancels without starting anything.
FZF_DEFAULT_OPTSandFZF_DEFAULT_OPTS_FILEare ignored for this picker to keep its output format predictable. - Without fzf: type a number and press Enter, or press Enter for the default. Esc, Ctrl-C or Ctrl-D cancels.
- No picker:
WT_PATH=myrepo-feature-x tmuxp load myapp. A relativeWT_PATHis resolved against the directory that contains the default repository; absolute paths and~/...work too. An unknown worktree aborts with the list of valid choices. A session whose start directory is not in a git repository (or that has nostart_directory) ignoresWT_PATH, with a note. - No terminal (scripts, cron, CI): the default worktree is used unless
WT_PATHis set. - Prunable worktrees (their directory is gone) and bare repositories are not offered.
How it works
tmuxp creates plugins after it has expanded the workspace file, but before it checks for an existing session and builds the windows. The plugin uses that moment to rewrite the expanded configuration: every path inside the default repository is moved into the chosen worktree and the session name gets the worktree suffix. tmuxp does not pass the configuration to plugins, so the plugin finds it in the calling frames; this is verified against tmuxp 1.73, 1.74 and 1.76.
When a directory fallback needs to wait for before_script, the plugin runs
setup once through tmuxp's script runner in its before_workspace_builder hook,
then finalizes the window and pane paths. Existing sessions do not rerun setup.
For this case, tmuxp's script-progress callbacks are bypassed. If using other
plugins, list this plugin last so their preparation hooks still run before setup.
Limitations
- Absolute paths inside
shell_commandorshell_command_beforeare not rewritten; usestart_directoryand relativecdcommands instead. - The session-name suffix comes from the worktree's directory name:
myrepo-feature-xbecomesfeature-x, any other name is used as is. Dots and colons become-, because tmux does not allow them in session names. If multiple worktrees produce the same session name, selecting one aborts with a list of the conflicting paths. Rename those worktree directories rather than silently reusing another worktree's session.
Development
python3 -m venv .venv
.venv/bin/pip install -e '.[test]'
.venv/bin/pytest
The end-to-end tests need tmux and git. They create throwaway repositories
and run tmuxp against a private tmux server, so your own sessions are never
touched. The fzf tests are skipped when fzf is not installed.
See TESTING.md for what the tests cover, running a subset or another tmuxp version, a manual test checklist and troubleshooting.
Releasing
- Bump
__version__insrc/tmuxp_plugin_worktree.pyand commit. - Tag and push:
git tag vX.Y.Z && git push origin main vX.Y.Z. - The
publishworkflow builds the package and uploads it to PyPI with trusted publishing; no API token is needed.
License
MIT.
Metadata
Release files for tmuxp-plugin-worktree 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tmuxp_plugin_worktree-0.2.0.tar.gz | 16.7 kB | With provenance | Details for tmuxp_plugin_worktree-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tmuxp_plugin_worktree-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for tmuxp_plugin_worktree-0.2.0-py3-none-any.whl |
Total release size: 27.3 kB
Release files / tmuxp_plugin_worktree-0.2.0.tar.gz
| Download URL | tmuxp_plugin_worktree-0.2.0.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e39dde7edebfae26b367037a808aeb5e9eff55cdd5ac77dd2d187f0f56a44936
|
|
BLAKE2b-256 checksum How to use checksums |
0abe34d3fa78d327b767a184698833ac809bb4d9e17692201f685e6c622aae9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / tmuxp_plugin_worktree-0.2.0-py3-none-any.whl
| Download URL | tmuxp_plugin_worktree-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ca3b53bec5484b7a7e578c4c18eb983949801acc3ae99fe44800f23abe4e0f8
|
|
BLAKE2b-256 checksum How to use checksums |
6c413cada53a97b9148a638bb0bff90cf222b1537119620c3a8b28d94b12bb53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for tmuxp-plugin-worktree 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tmuxp_plugin_worktree-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.