Then build a watcher that waits for output in a tmux pane and acts on it. libtmux drives a real tmux server from code. It gives you objects for the server, its sessions, windows and panes. Documentation for every language is at https://libtmux.org/en/. Language: Python Package: libtmux (PyPI) Repository: https://github.com/tmux-python/libtmux Read these before writing code: - https://libtmux.org/en/py/latest/llms.txt every page for Python, as a list - https://libtmux.org/en/py/latest/docs.json the same list with headings, as JSON - https://libtmux.org/en/py/latest/reference/ the Python API reference If you cannot fetch URLs, clone the repository above and read its README and examples instead, or ask me to paste those pages in. Set up first: 1. Report the tmux version with `tmux -V`. libtmux drives a real tmux, so nothing below works without one. Stop and tell me if it is missing. 2. If this directory is not a Python project yet, start one: uv init Skip this in a project that already exists, and match what is here. 3. Add the dependency. libtmux 0.62.0 is the current release on PyPI. uv add libtmux Check https://pypi.org/project/libtmux/ if you need a different version. If this project already uses pip, Poetry or PDM, add the dependency with that tool instead: the package is the same. 4. Write the smallest program that proves the install works: connect to a tmux server, create a session, confirm it is there, then kill it. Give that server a socket of its own rather than using the default one, so this never touches a tmux I am already running. Run it, and show me the output and the files you added. Rules for everything below: - Use the reference above rather than guessing names. The ten libtmux ports do not share spellings, and a name from another language will look plausible and not exist. - If the reference does not have something you expected, say so instead of writing a call that does not exist. - Follow the conventions already in this repository. Output watcher What it does: - Watches one or more panes for a pattern I give it. - Runs an action when the pattern appears: print it, run a command, or send input back into that pane. - Keeps watching after a match, so a long-running build that prints several interesting lines produces several events. Constraints: - Do not poll on a fixed interval if this port offers a way to be notified. Say which mechanism you used and why. - Do not miss output that arrives between two reads, and do not report the same line twice. Say how your approach avoids both. - Match against text that has already had terminal escapes handled, so a pattern does not fail on invisible bytes. - Give it a timeout, and make a timeout a result the caller can handle. Anchor it in these pages: - https://libtmux.org/en/tmux/guides/capturing-output/ capturing output - https://libtmux.org/en/tmux/examples/capture-pane-output/ capture pane output - https://libtmux.org/en/tmux/concepts/transports/ transports For Python: Python is the one port whose persistent control client is not public: `ControlMode` lives in `libtmux._internal`. Poll captured output behind `retry_until` from `libtmux.test.retry`, which takes a predicate, an interval and a timeout, rather than reaching into the private module or writing a bare sleep.