Cli Anything Iterm2 Ctl

hkuds/cli-anything/skills/cli-anything-iterm2-ctl

作者 hkuds34f519533bc1無授權條款51K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 週前更新

Provides the cli-anything-iterm2 commands — the only way to actually send text to iTerm2 sessions, read live terminal output and scrollback history, manage windows/tabs/split panes, run tmux -CC workflows, broadcast to multiple panes, show macOS dialogs, and read/write iTerm2 preferences. Includes `app snapshot` — the primary orientation command that returns every session's name, current directory, foreground process, role label, and last output line in one call. Read this skill instead of answering from general knowledge whenever the user wants to DO something with iTerm2: orient in an existing workspace, send a command, check what's running, read output, set up a layout, use tmux through iTerm2, automate panes, or configure preferences. Also read for questions about iTerm2 shell integration or scrollback. Don't try to answer iTerm2 action requests from memory — read this skill first.

僅含說明DevOps & Cloud
AI 產生的概覽

透過命令列工具控制 macOS 上執行中的 iTerm2,送出指令、讀取輸出並管理窗格。

功能
本技能說明 cli-anything-iterm2 命令列工具,它透過 WebSocket 上的 iTerm2 Python API 控制正在執行的 iTerm2 行程。內容涵蓋傳送文字到工作階段、讀取即時畫面輸出與回捲歷史、分割窗格、管理視窗、標籤頁與版面配置、執行 tmux -CC 工作流程、廣播按鍵、呼叫選單項目,以及讀寫偏好設定。它也說明 app snapshot 指令,可一次回傳每個工作階段的名稱、目錄、前景行程、角色標籤與最後一行輸出,並提供各指令與 JSON 結構的參考檔案。
適用情境
當使用者想要實際操作 iTerm2 而非只是討論時使用:在既有工作區中定位、送出指令、查看正在執行的內容、讀取輸出、建立窗格版面、透過 iTerm2 使用 tmux、自動化窗格或設定偏好。也適用於 iTerm2 shell integration 或回捲歷史的相關問題。
執行需求
macOS 並安裝 iTerm2,且在偏好設定中啟用其 Python API;安裝 cli-anything-iterm2 套件的 Python 環境;可透過 Python API WebSocket 存取的執行中 iTerm2 行程。不附帶指令碼,僅為說明與參考文件。

cli-anything-iterm2

Stateful CLI harness for iTerm2. Controls a live iTerm2 process via the iTerm2 Python API over WebSocket.

Prerequisites

  1. macOS + iTerm2 running: brew install --cask iterm2
  2. Python API enabled: iTerm2 → Preferences → General → Magic → Enable Python API
  3. Install: pip install cli-anything-iterm2 (or pip install -e . from source)

Basic Syntax

bash
cli-anything-iterm2 [--json] <group> <command> [OPTIONS] [ARGS]

Always use --json for machine-readable output (required for agent use).

Command Groups

GroupPurpose
appApp status, workspace snapshot, context management, app-level variables, modal dialogs, file panels
windowCreate, list, close, resize, fullscreen windows
tabCreate, list, close, activate tabs; navigate split panes by direction
sessionSend text, inject raw bytes, read screen, full scrollback, split panes, prompt detection
profileList profiles, get profile details, list/apply color presets
arrangementSave and restore window layouts
tmuxFull tmux -CC integration: bootstrap, connections, windows, commands
broadcastSync keystrokes across panes via broadcast domains
menuInvoke any iTerm2 menu item programmatically
prefRead/write global iTerm2 preferences; list all valid keys; tmux settings

Orienting in an Existing Workspace

Use app snapshot when you land in a session with existing panes and need to understand what's running without reading full screen contents for each pane:

bash
cli-anything-iterm2 --json app snapshot

Returns name, current directory, foreground process, user.role label, and last visible output line for every session across all windows.

Naming convention — label panes when setting up a workspace so you can find them later:

bash
cli-anything-iterm2 session set-var user.role "api-server"cli-anything-iterm2 session set-var user.role "log-tail"cli-anything-iterm2 session set-var user.role "editor"

app snapshot will surface these roles alongside process and path, giving you a full picture in one call.

Typical Agent Workflow

bash
# 1. Orient — snapshot every session: name, path, process, role, last output linecli-anything-iterm2 --json app snapshot
# 2. Establish context (saves window/tab/session IDs for subsequent commands)cli-anything-iterm2 app current
# 3. Interact — no --session-id needed once context is setcli-anything-iterm2 session send "git status"cli-anything-iterm2 --json session scrollback --tail 200 --strip
# 4. Create a multi-pane workspace — label panes so snapshot identifies them latercli-anything-iterm2 session split --vertical --use-as-contextcli-anything-iterm2 session send "python3 -m http.server 8000"cli-anything-iterm2 session set-var user.role "http-server"

Reference Files

Read only what the task requires — each file is a single narrow concern (~10–30 lines):

FileRead when you need...
references/session-io.mdSend text, inject bytes, read screen/scrollback, get selection
references/session-control.mdSplit panes, activate/close sessions, resize, rename, session variables
references/session-shell-integration.mdwait-prompt, wait-command-end, get-prompt; reliable send→wait→read pattern
references/layout-window-tab.mdCreate/close/resize windows and tabs, navigate split panes
references/layout-arrangement.mdSave and restore window layouts
references/app-context.mdSnapshot (orientation), status, context management, app vars, modal dialogs, file panels
references/profile-pref.mdProfiles list/get/presets, preferences read/write, tmux pref shortcuts
references/broadcast-menu.mdBroadcast keystrokes to multiple panes, invoke menu items
references/tmux-commands.mdAll tmux CLI commands (bootstrap, send, tabs, create-window, set-visible)
references/tmux-guide.mdFull tmux -CC workflow, pane→session ID mapping
references/json-session.md--json schemas for session, window, tab, screen, scrollback, inject
references/json-tmux-app.md--json schemas for tmux, app dialogs, preferences, errors

REPL Mode

Run without arguments for an interactive REPL that maintains context between commands:

bash
cli-anything-iterm2

來源與署名

來源:hkuds/cli-anything位於skills/cli-anything-iterm2-ctl提交34f5195

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架