Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use when you need state across calls — building env vars, navigating with cd, driving REPLs (python -i, mysql, psql, node), or responding to interactive prompts (sudo password, ssh host-key confirmation, mysql connection). Teaches the prompt-sentinel exec pattern (default mode), raw I/O for REPLs (raw_send=True then read_only=True), the one-in-flight-per-session rule, and the close-or-leak-against-the-cap discipline. Bash on macOS — never zsh; explicit shell=/bin/zsh is rejected. Read before cal
.claude/skills/aden-hive-hive-terminal-tools-pty-sessions/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-12 | ✗→✓ | ▲ Improved | 11% | 0% |
| case-13 | ✗→✓ | ▲ Improved | -31% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 48% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 63% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 31% | 0% |
PTY sessions are how you talk to interactive programs — programs that detect a terminal (isatty()) and behave differently when they don't see one. Use a session when:
cd, env vars, sourced scripts)python -i, mysql, psql, node, irb)sudo, ssh, npm login, gh auth login)For everything else, terminal_exec is simpler. Sessions cost more (per-session bash process, ring buffer, idle-reaping bookkeeping) and have a hard cap (TERMINAL_TOOLS_MAX_PTY, default 8).
Subprocess pipes break on every interactive program. The moment a program calls isatty() and sees False, it disables prompts, color, line-editing, password masking, progress bars — sometimes refuses to start. PTY makes us look like a real terminal so these programs work the same as in your shell.
The cost: PTY output includes terminal escape codes (cursor moves, color codes). The session captures them as-is; if you need clean text, strip ANSI escapes in your processing layer.
terminal_pty_open always invokes /bin/bash, regardless of the user's $SHELL. macOS users: yes, even when zsh is your interactive default. This is the terminal-tools-foundations policy applied to PTYs.
Reasons:
zmodload, =cmd expansion, zpty, ztcp) that bypass bash-shaped security checksThe bash invocation uses --norc --noprofile so user dotfiles don't leak in. PS1 is set to a unique sentinel for prompt detection. PS2 is empty. PROMPT_COMMAND is empty.
terminal_pty_runterminal_pty_run(session_id, command="ls -la")
→ { output, prompt_after: True, ... }The session writes ls -la\n, waits for the sentinel that its custom PS1 emits, returns the slice between submission and prompt. One in-flight call per session — a concurrent call returns a "session busy" error.
terminal_pty_run(session_id, command="print('hi')\n", raw_send=True)
→ { bytes_sent: 12 }For REPLs, vim keystrokes, password prompts. The session writes the bytes and returns immediately — it doesn't wait for a prompt (REPLs don't print bash's prompt; they print their own).
After a raw_send, you typically follow with:
terminal_pty_run(session_id, read_only=True, timeout_sec=2)
→ { output: "hi\n", more: False, ... }Reads whatever the session has accumulated since the last drain, with a brief settle window. Use after raw_send to capture the REPL's response.
expect)When the command launches a program with its own prompt (Python REPL's >>> , mysql's mysql> , sudo's password prompt), the bash sentinel won't appear until the program exits. Override:
terminal_pty_run(session_id, command="python3", expect=r">>>\s*$", timeout_sec=10)
→ output up to and including ">>>", then control returnsFor sudo:
terminal_pty_run(session_id, command="sudo -k && sudo whoami", expect=r"[Pp]assword:")
terminal_pty_run(session_id, command="<password>", raw_send=True, command="<password>\n")
terminal_pty_run(session_id, read_only=True, timeout_sec=5)(Treat passwords carefully — they end up in the ring buffer.)
terminal_pty_close(session_id)Leaked sessions count against TERMINAL_TOOLS_MAX_PTY (default 8). Idle reaping happens lazily on every _open call (sessions inactive longer than idle_timeout_sec, default 1800s, are dropped) — but don't rely on it. Close when you're done.
For unresponsive sessions, force=True skips the graceful "exit" attempt and goes straight to SIGTERM/SIGKILL.
sid = terminal_pty_open(cwd="/")
terminal_pty_run(sid, command="cd /var/log")
terminal_pty_run(sid, command="ls -la *.log | head")
terminal_pty_close(sid)sid = terminal_pty_open()
terminal_pty_run(sid, command="python3", expect=r">>>\s*$")
terminal_pty_run(sid, command="x = 42", raw_send=True)
terminal_pty_run(sid, command="print(x*x)\n", raw_send=True)
result = terminal_pty_run(sid, read_only=True) # → "1764\n>>> "
terminal_pty_run(sid, command="exit()", raw_send=True)
terminal_pty_close(sid)sid = terminal_pty_open()
terminal_pty_run(sid, command="ssh user@new-host", expect=r"\(yes/no.*\)\?")
terminal_pty_run(sid, command="yes\n", raw_send=True)
terminal_pty_run(sid, read_only=True, timeout_sec=10) # password prompt or login| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-12 | fail→pass | 16,308 | 1,113 | -93% | 1 | 1 | 0% | 1,445 | 1,597 | +11% | 0 | 0 | — |
case-13 | fail→pass | 14,549 | 2,191 | -85% | 1 | 1 | 0% | 2,583 | 1,777 | -31% | 0 | 0 | — |
case-01 | fail→fail | 7,710 | 6,457 | -16% | 1 | 1 | 0% | 1,423 | 2,177 | +53% | 0 | 0 | — |
case-02 | fail→fail | 7,895 | 15,234 | +93% | 1 | 1 | 0% | 359 | 1,730 | +382% | 0 | 0 | — |
case-03 | fail→pass | 16,292 | 11,174 | -31% | 1 | 1 | 0% | 2,632 | 3,889 | +48% | 0 | 0 | — |
case-04 | fail→pass | 6,742 | 2,054 | -70% | 1 | 1 | 0% | 1,078 | 1,759 | +63% | 0 | 0 | — |
case-05 | fail→pass | 8,123 | 3,067 | -62% | 1 | 1 | 0% | 1,520 | 1,997 | +31% | 0 | 0 | — |
case-06 | fail→pass | 8,927 | 2,807 | -69% | 1 | 1 | 0% | 1,564 | 1,914 | +22% | 0 | 0 | — |
case-07 | fail→pass | 13,032 | 7,847 | -40% | 1 | 1 | 0% | 1,728 | 2,680 | +55% | 0 | 0 | — |
case-08 | fail→pass | 17,765 | 3,719 | -79% | 1 | 1 | 0% | 3,166 | 2,153 | -32% | 0 | 0 | — |
case-09 | fail→pass | 9,555 | 6,161 | -36% | 1 | 1 | 0% | 1,902 | 2,676 | +41% | 0 | 0 | — |
case-10 | pass→pass | 12,063 | 1,448 | -88% | 1 | 1 | 0% | 2,088 | 1,640 | -21% | 0 | 0 | — |
case-11 | pass→pass | 4,329 | 2,601 | -40% | 1 | 1 | 0% | 774 | 1,817 | +135% | 0 | 0 | — |
case-14 | fail→pass | 4,083 | 10,524 | +158% | 1 | 1 | 0% | 801 | 3,429 | +328% | 0 | 0 | — |
case-15 | fail→pass | 10,282 | 1,192 | -88% | 1 | 1 | 0% | 1,991 | 1,643 | -17% | 0 | 0 | — |
case-16 | fail→pass | 8,434 | 1,616 | -81% | 1 | 1 | 0% | 1,521 | 1,660 | +9% | 0 | 0 | — |
case-17 | pass→pass | 13,656 | 5,655 | -59% | 1 | 1 | 0% | 2,425 | 2,365 | -2% | 0 | 0 | — |
case-18 | fail→pass | 15,669 | 3,859 | -75% | 1 | 1 | 0% | 2,806 | 2,038 | -27% | 0 | 0 | — |
case-19 | fail→pass | 8,053 | 2,930 | -64% | 1 | 1 | 0% | 1,640 | 2,010 | +23% | 0 | 0 | — |
case-20 | fail→pass | 8,029 | 5,634 | -30% | 1 | 1 | 0% | 1,580 | 1,948 | +23% | 0 | 0 | — |
case-21 | fail→pass | 15,793 | 3,088 | -80% | 1 | 1 | 0% | 2,665 | 1,915 | -28% | 0 | 0 | — |
case-22 | fail→pass | 13,393 | 10,902 | -19% | 1 | 1 | 0% | 2,650 | 3,651 | +38% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 19 counted toward the lift figure. The other 3 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +77 percentage points is the difference between those two pass rates over the 19 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.