Tmux#
You can use the tmux tool to run long-lived and/or interactive applications in a tmux session. Requires tmux to be installed.
This tool is suitable to run long-running commands or interactive applications that require user input.
Examples of such commands: npm run dev, python3 server.py, python3 train.py, etc.
It allows for inspecting pane contents and sending input.
Instructions
Run interactive/persistent apps (REPLs, TUIs, servers) needing keyboard input or
repeated pane inspection. Prefer shell background jobs for noninteractive work.
Use `wait <session_id> [timeout] [stable_time]` to await stable output.
Top-level semicolons/newlines separate tmux commands. Shell sequences need a
compound: `new-session (cmd1; cmd2)`. Heredocs/nested compounds stay intact;
heredoc terminators occupy their own lines. `send-keys` is literal, not Bash.
Invalid/unsupported boundaries reject the whole batch; use shell or a script.
Examples
Running subagents
| User |
start subagent to fix lints in parallel |
| Assistant |
Let's start a subagent in a new tmux session: |
Running specific agent
| User |
Ask Bob about his latest work |
| Assistant |
Sure! Let's start a tmux session running Bob (~/bob/): |
Managing a dev server
| User |
Start the dev server |
| Assistant |
Certainly! To start the dev server we should use tmux: |
| System |
Running `npm run dev` in session gptme_1 |
| User |
Can you show me the current content of the pane? |
| Assistant |
Of course! Let's inspect the pane content: |
| System |
|
| User |
Stop the dev server |
| Assistant |
I'll send 'Ctrl+C' to the pane to stop the server: |
| System |
Sent 'C-c' to pane 0 |
Get info from ncurses applications
| User |
start top and give me a summary |
| Assistant |
Sure! Let's start the top command in a tmux session: |
| System |
Running `top` in session gptme_1. |
| Assistant |
The load is... |
Send keys to a session
| User |
start ipython |
| Assistant |
Let's start an ipython session: |
| System |
Running `ipython` in session 2. |
| User |
Run 'print("Hello, world!")' in the ipython session
|
Listing active sessions
| User |
List all active tmux sessions |
| System |
Active tmux sessions ['0', 'gptme_1'] |
- gptme.tools.tmux.execute_tmux(code: str | None, args: list[str] | None, kwargs: dict[str, str] | None) Generator[Message, None, None]
Executes a command in tmux and returns the output.
- gptme.tools.tmux.get_tmux_key_text(keys: str) str
Return typed text for literal-input policy checks, not terminal emulation.
tmux concatenates argument text without spaces. Common submission/whitespace keys are decoded; arbitrary control keys and existing pane state are outside this stateless policy’s scope.
- gptme.tools.tmux.get_tmux_operations(tool_use: ToolUse) list[tuple[str, str]] | None
Public structured input of a
tmuxcall, for policy hooks.Returns the call’s operations in order as
(verb, arguments)pairs, split exactly as execution splits them (new-session’s arguments are the shell command it starts;send-keys’ are"<pane> <keys>"). ReturnsNonewhentool_useis not atmuxcall and[]for a batch the tool rejects before running anything.
- gptme.tools.tmux.get_tmux_pane_cwd(pane_id: str) Path | None
Read the target’s directory without reading its contents or running keys.
Match
send_keysshorthand and restrict native IDs to our namespace. A disappearing pane or unavailable server has no observable directory.
- gptme.tools.tmux.inspect_pane(pane_id: str, logdir: Path | None = None) Message
Inspect the content of a tmux pane.
- Parameters:
pane_id – The tmux pane ID to inspect
logdir – Conversation directory to save full output under if truncated; defaults to the active conversation
- Returns:
Message with pane content (truncated if too long)
- gptme.tools.tmux.wait_for_output(session_id: str, timeout: int = 60, stable_time: int = 3, logdir: Path | None = None) Message
Wait for command output to stabilize in a tmux session.
Monitors the pane output and waits until it remains unchanged for stable_time seconds, or until timeout is reached.
- Parameters:
session_id – The tmux session ID to monitor
timeout – Maximum time to wait in seconds (default: 60)
stable_time – Seconds of unchanged output to consider stable (default: 3)
- Returns:
Message with the final output and status
Guardrail path context#
With guardrails enabled, literal shell text in new-session is checked
relative to the process directory used to start the shell. For send-keys,
the guard queries the target pane’s current directory, including session
shorthand and native pane IDs, before checking relative operands and search
exclusion files. An unavailable pane leaves only the existing process-relative
checks; it does not provide verified pane context.
These checks are heuristics, not a sandbox. The directory query is a snapshot;
a preceding cd, concurrent pane input, shell startup files, or dynamically
generated commands can change the eventual interpretation of the typed text.