Terminal & background tasks
Run anything long-lived, backgrounded, or interactive inside tmux so the user has observability and can attach.
Core rules
- Reuse before creating. Check
$TMUX and tmux ls first. Only make a new session if nothing suitable already exists.
- Inside tmux (
$TMUX set): open a new window in the current session, detached (tmux new-window -d ...). Never start a nested session. Do not switch the user's active window unless asked — -d is what keeps you from hijacking their focus.
- Outside tmux: start one detached session and tell the user its name so they can
tmux attach -t <name>.
- Launch and read output in the same turn. Chain
send-keys with capture-pane in one shell call. Splitting "run" and "check" across turns wastes a round trip and hides failures.
- Only kill what you created. Never
kill-session/kill-window on something you didn't start without confirming.
Step by step
Detect tmux:
echo "$TMUX"; tmux ls
Pick the session:
- If
$TMUX is set, use the current session: tmux display-message -p '#S'.
- Else create one:
tmux new-session -d -s <session>.
Open a new window for the task in the background (-d is critical — without it tmux switches the user away from their current window):
tmux new-window -d -t <session> -n <name>
Name the window after the task (dev, tests, repl) so the user can find it. To start a command in the same call, append it: tmux new-window -d -t <session> -n <name> '<cmd>'.
Send the command and capture output in one call:
tmux send-keys -t <session>:<name> '<cmd>' C-m && sleep 1 && tmux capture-pane -t <session>:<name> -p -S -200
For follow-up input (REPL prompts, password prompts, interactive menus), repeat step 4 one logical line at a time. Do not pipe multi-line stdin into interactive programs (printf '...\n...\n' | python3 -i) — indentation and prompt state get mangled. If the work is non-interactive, write a script file and run it instead of driving a REPL line by line.
Re-read output later:
tmux capture-pane -t <session>:<name> -p -S -500
Clean up when done (only sessions/windows you created):
tmux kill-window -t <session>:<name>
tmux kill-session -t <session>
Universal pattern for long-running processes
Whether it's a dev server, build, watcher, log tail, tunnel, or supervised agent, the shape is the same:
- One named window per process.
- Pipe output through
tee /tmp/<name>.log so history survives scrollback limits and grep works later.
- Wait for a readiness signal — a log line, an open port, a sentinel echo — not a fixed
sleep.
- Read recent state from
capture-pane, historical state from the log file.
- Leave the window alive so the user can attach and watch.
Deeper guides (load on demand)
references/long-running.md — dev servers (next/vite/rails/django), test watchers (jest/vitest/pytest-watch), log tailing (kubectl/docker/journalctl), long builds, tunnels (ngrok/ssh -L/port-forward), docker compose, supervised agents, ssh sessions. Read this whenever you're about to start any of those.
references/repls.md — interactive REPLs (Python, Node, psql, ipython, sqlite3). Indentation handling, multi-line blocks, when to bail out and write a script.
references/troubleshooting.md — capture returns nothing/stale, send-keys lands wrong, nested sessions, truncated output, hung prompts, ANSI noise.
Source: Try3D/skills — distributed by TomeVault.
1---2name: terminal3description: Run background, long-lived, or interactive terminal commands inside tmux so the user can observe and intervene. Use this skill whenever you are about to start a dev server, watcher, REPL (python/node/psql/etc.), tail logs, or any process that runs longer than a single shell call — even if the user did not say "tmux". Use when this capability is needed.4---56# Terminal & background tasks78Run anything long-lived, backgrounded, or interactive inside tmux so the user has observability and can attach.910## Core rules1112- **Reuse before creating.** Check `$TMUX` and `tmux ls` first. Only make a new session if nothing suitable already exists.13- **Inside tmux (`$TMUX` set): open a new window in the *current* session, detached** (`tmux new-window -d ...`). Never start a nested session. Do not switch the user's active window unless asked — `-d` is what keeps you from hijacking their focus.14- **Outside tmux: start one detached session and tell the user its name** so they can `tmux attach -t <name>`.15- **Launch and read output in the same turn.** Chain `send-keys` with `capture-pane` in one shell call. Splitting "run" and "check" across turns wastes a round trip and hides failures.16- **Only kill what you created.** Never `kill-session`/`kill-window` on something you didn't start without confirming.1718## Step by step19201. Detect tmux:21 ```22 echo "$TMUX"; tmux ls23 ```24252. Pick the session:26 - If `$TMUX` is set, use the current session: `tmux display-message -p '#S'`.27 - Else create one: `tmux new-session -d -s <session>`.28293. Open a new window for the task **in the background** (`-d` is critical — without it tmux switches the user away from their current window):30 ```31 tmux new-window -d -t <session> -n <name>32 ```33 Name the window after the task (`dev`, `tests`, `repl`) so the user can find it. To start a command in the same call, append it: `tmux new-window -d -t <session> -n <name> '<cmd>'`.34354. Send the command and capture output in one call:36 ```37 tmux send-keys -t <session>:<name> '<cmd>' C-m && sleep 1 && tmux capture-pane -t <session>:<name> -p -S -20038 ```39405. For follow-up input (REPL prompts, password prompts, interactive menus), repeat step 4 one logical line at a time. **Do not pipe multi-line stdin into interactive programs** (`printf '...\n...\n' | python3 -i`) — indentation and prompt state get mangled. If the work is non-interactive, write a script file and run it instead of driving a REPL line by line.41426. Re-read output later:43 ```44 tmux capture-pane -t <session>:<name> -p -S -50045 ```46477. Clean up when done (only sessions/windows you created):48 ```49 tmux kill-window -t <session>:<name>50 tmux kill-session -t <session>51 ```5253## Universal pattern for long-running processes5455Whether it's a dev server, build, watcher, log tail, tunnel, or supervised agent, the shape is the same:56571. One named window per process.582. Pipe output through `tee /tmp/<name>.log` so history survives scrollback limits and `grep` works later.593. Wait for a *readiness signal* — a log line, an open port, a sentinel echo — not a fixed `sleep`.604. Read recent state from `capture-pane`, historical state from the log file.615. Leave the window alive so the user can attach and watch.6263## Deeper guides (load on demand)6465- `references/long-running.md` — dev servers (next/vite/rails/django), test watchers (jest/vitest/pytest-watch), log tailing (kubectl/docker/journalctl), long builds, tunnels (ngrok/ssh -L/port-forward), docker compose, supervised agents, ssh sessions. Read this whenever you're about to start any of those.66- `references/repls.md` — interactive REPLs (Python, Node, psql, ipython, sqlite3). Indentation handling, multi-line blocks, when to bail out and write a script.67- `references/troubleshooting.md` — capture returns nothing/stale, send-keys lands wrong, nested sessions, truncated output, hung prompts, ANSI noise.6869---70> Source: [Try3D/skills](https://github.com/Try3D/skills) — distributed by [TomeVault](https://tomevault.io).71<!-- tomevault:4.0:skill_md:2026-06-15 -->