Skip to main content

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_directory inside the repository into that worktree (relative cd commands in your panes keep working), and a before_script that lives in the repository;
  • renames the session to <session>-<worktree> (for example myapp-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

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
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_OPTS and FZF_DEFAULT_OPTS_FILE are 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 relative WT_PATH is 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 no start_directory) ignores WT_PATH, with a note.
  • No terminal (scripts, cron, CI): the default worktree is used unless WT_PATH is 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_command or shell_command_before are not rewritten; use start_directory and relative cd commands instead.
  • The session-name suffix comes from the worktree's directory name: myrepo-feature-x becomes feature-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

  1. Bump __version__ in src/tmuxp_plugin_worktree.py and commit.
  2. Tag and push: git tag v0.1.0 && git push origin main v0.1.0.
  3. The publish workflow 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tmuxp-plugin-worktree 0.1.0
File Size Uploaded Provenance Actions
tmuxp_plugin_worktree-0.1.0.tar.gz 16.4 kB With provenance Details for tmuxp_plugin_worktree-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tmuxp-plugin-worktree 0.1.0
File Interpreter ABI Platform Actions
tmuxp_plugin_worktree-0.1.0-py3-none-any.whl Python 3 none any Details for tmuxp_plugin_worktree-0.1.0-py3-none-any.whl

Total release size: 26.7 kB

Release files / tmuxp_plugin_worktree-0.1.0.tar.gz

Download URL tmuxp_plugin_worktree-0.1.0.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
583dd6b747fed101ff48cde88ef6417812c65f6f38775e4a2dd5345d1dc87ed3
BLAKE2b-256 checksum
How to use checksums
1e60945d2385102d0ea23b4bcd5a5dab9afe4e5992fc1efab77ff8a142833f20
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 log

Release files / tmuxp_plugin_worktree-0.1.0-py3-none-any.whl

Download URL tmuxp_plugin_worktree-0.1.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d04ef8aff2bf838e4291f7f14d43ddc260b95220a6f6e1981e9913559cc4e2d1
BLAKE2b-256 checksum
How to use checksums
d7ab4dba7e2d0a2dbb260c8f29d43689e66aa64d92633318b6421c61531790fa
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 log

Security for tmuxp-plugin-worktree 0.1.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.

Select from 2 files

Attestation for tmuxp_plugin_worktree-0.1.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 log

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page