Skip to content

Commit 0b487ff

Browse files
committed
docs(topics): Add gotchas page — 7 things that will bite you
why: Troubleshooting is symptom-based (after something breaks). Gotchas are preventive — things you should know before they bite. what: - Metadata vs. content (list_panes vs search_panes) - send_keys sends Enter by default (enter=false for C-c) - capture_pane race condition after send_keys - Window names not unique across sessions (use IDs) - Pane IDs globally unique but ephemeral (reset on server restart) - suppress_history requires HISTCONTROL=ignorespace - clear_pane is two tmux commands with a brief gap - Added to topics/ toctree and grid cards
1 parent 1c69e6b commit 0b487ff

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

docs/topics/gotchas.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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`.

docs/topics/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Three-tier safety system for controlling tool access.
2929
Symptom-based guide for common issues.
3030
:::
3131

32+
:::{grid-item-card} Gotchas
33+
:link: gotchas
34+
:link-type: doc
35+
Things that will bite you if you don't know about them.
36+
:::
37+
3238
::::
3339

3440
```{toctree}
@@ -37,5 +43,6 @@ Symptom-based guide for common issues.
3743
architecture
3844
concepts
3945
safety
46+
gotchas
4047
troubleshooting
4148
```

0 commit comments

Comments
 (0)