Plugins

The plugin system allows users to customize and extend different aspects of tmuxp without the need to change tmuxp itself.

Using a Plugin

To use a plugin, install it in your local python environment and add it to your tmuxp workspace file.

Example Workspace files

session_name: plugin-system
plugins:
  - "tmuxp_plugin_extended_build.plugin.PluginExtendedBuild"
windows:
  - window_name: editor
    layout: tiled
    shell_command_before:
      - cd ~/
    panes:
      - shell_command:
          - cd /var/log
          - ls -al | grep *.log
      - echo "hello world"
{
  "session_name": "plugin-system",
  "plugins": [
    "tmuxp_plugin_extended_build.plugin.PluginExtendedBuild"
  ],
  "windows": [
    {
      "window_name": "editor",
      "layout": "tiled",
      "shell_command_before": [
        "cd ~/"
      ],
      "panes": [
        {
          "shell_command": [
            "cd /var/log",
            "ls -al | grep *.log"
          ]
        },
        "echo \"hello world\""
      ]
    }
  ]
}

Developing a Plugin

tmuxp expects all plugins to be class within a python submodule named plugin that is within a python module that is installed in the local python environment. A plugin interface is provided by tmuxp to inherit.

uv is the chosen python package manager for tmuxp. It is highly suggested to use it when developing plugins; however, pip will work just as well. Only one of the configuration files is needed for the packaging tool that the package developer decides to use.

python_module
├── tmuxp_plugin_my_plugin_module
│   ├── __init__.py
│   └── plugin.py
└── pyproject.toml  # Python project configuration file

When publishing plugins to pypi, tmuxp advocates for standardized naming: tmuxp-plugin-{your-plugin-name} to allow for easier searching. To create a module configuration file with uv, run uv virtualenv in the module directory. The resulting file looks something like this:

[project]
name = "tmuxp-plugin-my-tmuxp-plugin"
version = "0.0.2"
description = "An example tmuxp plugin."
authors = ["Author Name <author.name@<domain>.com>"]
requires-python = ">=3.8,<4.0"
dependencies = [
  "tmuxp^=1.7.0"
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

The plugin.py file could contain something like the following:


from tmuxp.plugin import TmuxpPlugin
import datetime

class MyTmuxpPlugin(TmuxpPlugin):
    def __init__(self):
        """
        Initialize my custom plugin.
        """
        # Optional version dependency configuration. See Plugin API docs
        # for all supported config parameters
        config = {
            'tmuxp_min_version' = '1.6.2'
        }

        TmuxpPlugin.__init__(
            self,
            plugin_name='tmuxp-plugin-my-tmuxp-plugin',
            **config
        )

    def before_workspace_builder(self, session):
        session.rename_session('my-new-session-name')

    def reattach(self, session):
        now = datetime.datetime.now().strftime('%Y-%m-%d')
        session.rename_session('session_{}'.format(now))

Once this plugin is installed in the local python environment, it can be used in a configuration file like the following:

session_name: plugin example
plugins:
  - my_plugin_module.plugin.MyTmuxpPlugin
# ... the rest of your config

Plugin API

TmuxpPlugin.__init__(**kwargs)[source]

Initialize plugin.

The default version values are set to the versions that the plugin system requires.

Parameters:
  • plugin_name (str) – Name of the child plugin. Used in error message plugin fails to load

  • tmux_min_version (str) – Min version of tmux that the plugin supports

  • tmux_max_version (str) – Min version of tmux that the plugin supports

  • tmux_version_incompatible (list) – Versions of tmux that are incompatible with the plugin

  • libtmux_min_version (str) – Min version of libtmux that the plugin supports

  • libtmux_max_version (str) – Max version of libtmux that the plugin supports

  • libtmux_version_incompatible (list) – Versions of libtmux that are incompatible with the plugin

  • tmuxp_min_version (str) – Min version of tmuxp that the plugin supports

  • tmuxp_max_version (str) – Max version of tmuxp that the plugin supports

  • tmuxp_version_incompatible (list) – Versions of tmuxp that are incompatible with the plugin

TmuxpPlugin.before_workspace_builder(session)[source]

Provide a session hook previous to creating the workspace.

This runs after the session has been created but before any of the windows/panes/commands are entered.

Return type:

None

Parameters:

session (libtmux.Session) – session to hook into

TmuxpPlugin.on_window_create(window)[source]

Provide a window hook previous to doing anything with a window.

This runs runs before anything is created in the windows, like panes.

Return type:

None

Parameters:

window (libtmux.Window) – window to hook into

TmuxpPlugin.after_window_finished(window)[source]

Provide a window hook after creating the window.

This runs after everything has been created in the window, including the panes and all of the commands for the panes. It also runs after the options_after has been applied to the window.

Return type:

None

Parameters:

window (libtmux.Window) – window to hook into

TmuxpPlugin.before_script(session)[source]

Provide a session hook after the workspace has been built.

This runs after the workspace has been loaded with tmuxp load. It augments instead of replaces the before_script section of the workspace data.

This hook provides access to the LibTmux.session object for any behavior that would be used in the before_script section of the workspace file that needs access directly to the session object. This runs after the workspace has been loaded with tmuxp load.

The hook augments, rather than replaces, the before_script section of the workspace. While it is possible to do all of the before_script workspace in this function, if a shell script is currently being used for the workspace, it would be cleaner to continue using the script in the before_section.

If changes to the session need to be made prior to anything being built, please use before_workspace_builder instead.

Return type:

None

Parameters:

session (libtmux.Session) – session to hook into

TmuxpPlugin.reattach(session)[source]

Provide a session hook before reattaching to the session.

Return type:

None

Parameters:

session (libtmux.Session) – session to hook into