# Terminal setup

1. **Detect** `TERM_PROGRAM`, `WT_SESSION`, editor variables, or `--terminal`
2. **Plan** reads only; lists each file and the entry
3. the person runs it again with `apply`
4. **Back up and write** `<file>.openprogram-backup-<time>` beside the file
5. **Undo line** the copy command that restores it

Code: `host/terminal_setup.py`; CLI `interfaces/cli/commands/maintenance/terminal_setup.py`; shared command `runtime/commands/terminal_setup.py`, registered in `runtime/commands/registry.py`; the TUI case in `apps/cli/src/commands/handler.ts`; the default binding in `apps/cli/src/keybindings/table.ts`. Tests: `tests/component/platform/test_terminal_setup.py`, each under a temporary HOME. User page: [TUI](https://openprogram.io/docs/interfaces/tui.html).

## Per terminal

| Terminal | What changes |
| --- | --- |
| iTerm2, Ghostty, WezTerm, Kitty | Nothing. The TUI turns on the kitty keyboard protocol there, and they report Shift+Enter as `ESC [ 13 ; 2 u` |
| VS Code, Insiders, Cursor, Windsurf | The user `keybindings.json` gets `shift+enter` → `workbench.action.terminal.sendSequence` with that sequence, `when: terminalFocus`. Inside a Remote-SSH terminal the file is on the other machine, so it says to run it locally |
| Windows Terminal | A `sendInput` action in `settings.json` (packaged, preview or unpackaged path); an `actions` array is added when there is none |
| Alacritty | A `[[keyboard.bindings]]` entry in `alacritty.toml`, checked with `tomllib`. A legacy YAML config is reported, not converted |
| Terminal.app | It cannot tell Shift+Enter from Enter. "Use Option as Meta key" in the default profile, through `defaults export` and `import` with a backup plist, makes Option+Enter the new-line key |
| Inside tmux | A note with the two `tmux.conf` lines that pass the key through. tmux's file is not written |

## Rules

| Part | Rule |
| --- | --- |
| Only on request | Nothing calls it on start or on a key. Without `apply` it only reads |
| Refusal | A file that does not parse, or already binds Shift+Enter in the terminal to something else, is left untouched with the reason. A binding scoped to the editor only does not count |
| Comments kept | JSONC files get the entry inserted as text after the array's opening bracket, then reparsed to check; the file is never re-serialized |
| Write | Atomic replace through a temporary file in the same folder; a symlinked file is written at its target |
| Already set | Reports it is configured and writes nothing |
| Where it runs | The TUI runs the CLI with its own environment (`OPENPROGRAM_CLI_PYTHON`), so detection sees the terminal the TUI is in. The shared command on the Worker uses the session's terminal environment when the CLI gives one, and otherwise says to run it in the terminal |

## Why this shape

| Peer | What it does, and what we take |
| --- | --- |
| Copilot CLI | `/terminal-setup` writes the VS Code `sendSequence` and Windows Terminal `sendInput` bindings, refuses on a conflict or invalid JSON, keeps a backup. Taken as is |
| Claude Code | Lists the changes first, sets Option as Meta in Terminal.app, names the tmux settings, leaves native terminals alone. Taken; the list is a separate step here, so writing always follows a list the person saw |
| Pi | docs/terminal-setup.md gives the same `\u001b[13;2u` sequence for manual setup. The same sequence keeps one key path in the TUI |

## Implementation status

Not configured: Warp, JetBrains terminals, GNOME Terminal and Konsole are not recognised; the command says Alt+Enter adds a new line in any terminal and lists the supported names for `--terminal`.
