---
name: terminal-control
description: Handle GUI terminal launches, control, and tmux safely from non-interactive exec sessions.
always: true
---

# Terminal Control Skill

Use these rules whenever the user asks you to open, close, or control a terminal app, create a `tmux` session, or run terminal commands through a GUI terminal.

- The `exec` tool does not allocate an interactive TTY.
- If a command fails with `not a terminal`, retry with a detached or otherwise non-interactive form instead of saying the task is impossible.
- Do not claim that GUI terminal control is impossible on macOS when the user explicitly asked for it. It is valid to use `osascript` to control apps like `iTerm` or `Terminal`.
- For `tmux` session creation via `exec`, prefer:
  - `tmux new-session -d -s <name>`
  - `tmux new-session -A -d -s <name>` when reusing an existing session name is acceptable
- When sending text into an existing tmux pane, `tmux send-keys -l -- "text"` only types text. Press Return in a second tmux call such as `tmux send-keys -t target C-m`, or use `bash {baseDir}/skills/tmux/scripts/send-text.sh -t target --enter -- "text"`.
- Do not claim that you "pressed Enter" unless the pane capture changed after the send.
- If the user explicitly asks to use a GUI terminal app on macOS, it is valid to launch that app through `exec` using `open` or `osascript`.
- Destructive GUI actions such as closing windows or quitting terminal apps are allowed only when the user explicitly asked for them.

Examples:

```bash
open -a "iTerm"
```

```bash
osascript <<'APPLESCRIPT'
tell application "iTerm"
  activate
  create window with default profile
  tell current session of current window
    write text "tmux new-session -A -s Claude"
  end tell
end tell
APPLESCRIPT
```

```bash
osascript <<'APPLESCRIPT'
tell application "iTerm"
  if it is running then
    close every window
  end if
end tell
APPLESCRIPT
```

```bash
osascript -e 'tell application "Terminal" to quit'
```

- If GUI automation is flaky, create the `tmux` session directly with detached mode and tell the user how to attach to it.
