|
| 1 | +(gotchas)= |
| 2 | + |
| 3 | +# Gotchas |
| 4 | + |
| 5 | +Things that will bite you if you don't know about them in advance. For symptom-based debugging, see {ref}`troubleshooting <troubleshooting>`. |
| 6 | + |
| 7 | +## Metadata vs. content |
| 8 | + |
| 9 | +{ref}`list-panes` and {ref}`list-windows` search **metadata** — names, IDs, current command. They do not search what is displayed in the terminal. |
| 10 | + |
| 11 | +To find text that is visible in terminals, use {tool}`search-panes`. To read what a specific pane shows, use {tool}`capture-pane`. |
| 12 | + |
| 13 | +This is the most common source of agent confusion. The server instructions already warn about this, but it bears repeating: if a user asks "which pane mentions error", the answer is `search_panes`, not `list_panes`. |
| 14 | + |
| 15 | +## `send_keys` sends Enter by default |
| 16 | + |
| 17 | +When you call `send_keys` with `keys: "C-c"`, it sends Ctrl-C **and then presses Enter**. For control sequences, set `enter: false`: |
| 18 | + |
| 19 | +```json |
| 20 | +{"tool": "send_keys", "arguments": {"keys": "C-c", "pane_id": "%0", "enter": false}} |
| 21 | +``` |
| 22 | + |
| 23 | +The `enter` parameter defaults to `true`, which is correct for commands (`make test` + Enter) but wrong for control keys, partial input, or key sequences. |
| 24 | + |
| 25 | +## `capture_pane` after `send_keys` is a race condition |
| 26 | + |
| 27 | +`send_keys` returns immediately after sending keystrokes to tmux. It does **not** wait for the command to execute or produce output. |
| 28 | + |
| 29 | +```json |
| 30 | +{"tool": "send_keys", "arguments": {"keys": "pytest", "pane_id": "%0"}} |
| 31 | +{"tool": "capture_pane", "arguments": {"pane_id": "%0"}} |
| 32 | +``` |
| 33 | + |
| 34 | +The capture above may return the terminal state **before** pytest runs. Use {tool}`wait-for-text` between them: |
| 35 | + |
| 36 | +```json |
| 37 | +{"tool": "send_keys", "arguments": {"keys": "pytest", "pane_id": "%0"}} |
| 38 | +{"tool": "wait_for_text", "arguments": {"pattern": "passed|failed|error", "pane_id": "%0", "regex": true}} |
| 39 | +{"tool": "capture_pane", "arguments": {"pane_id": "%0"}} |
| 40 | +``` |
| 41 | + |
| 42 | +See {ref}`recipes` for the complete pattern. |
| 43 | + |
| 44 | +## Window names are not unique across sessions |
| 45 | + |
| 46 | +Two sessions can each have a window named "editor". Targeting by `window_name` alone is ambiguous — always include `session_name` or use the globally unique `window_id` (e.g., `@0`, `@1`). |
| 47 | + |
| 48 | +Pane IDs (`%0`, `%1`, etc.) are globally unique and are the preferred targeting method. |
| 49 | + |
| 50 | +## Pane IDs are globally unique but ephemeral |
| 51 | + |
| 52 | +Pane IDs like `%0`, `%5`, `%12` are unique across all sessions and windows within a tmux server. They do not reset when windows are created or destroyed. |
| 53 | + |
| 54 | +However, they reset when the tmux **server** restarts. Do not cache pane IDs across server restarts. After killing and recreating a session, re-discover pane IDs with {ref}`list-panes`. |
| 55 | + |
| 56 | +## `suppress_history` requires shell support |
| 57 | + |
| 58 | +The `suppress_history` parameter on `send_keys` prepends a space before the command, which prevents it from being saved in shell history. This only works if the shell's `HISTCONTROL` variable includes `ignorespace` (the default for bash, but not universal across all shells). |
| 59 | + |
| 60 | +## `clear_pane` is not fully atomic |
| 61 | + |
| 62 | +`clear_pane` runs two tmux commands in sequence: `send-keys -R` (reset terminal) then `clear-history` (clear scrollback). There is a brief gap between them where partial content may be visible. |
| 63 | + |
| 64 | +For most use cases this is not a problem. If you need guaranteed clean state, add a small delay before the next `capture_pane`. |
0 commit comments