跳到正文
Skillpedia
部署与云(DevOps)58k · #3212

cli-anything-iterm2

它能做什么

这个技能让你的智能体在 Mac 的终端应用 iTerm2 中工作,通过读取和发送文本与其会话交互。适合使用 iTerm2 并希望自动化终端工作的开发者。

适用场景

  • ✓当你想让智能体向正在运行的 iTerm2 会话发送命令的时候。
  • ✓当你想读取终端会话的当前输出或历史记录的时候。
  • ✓当你想自动排列窗口、标签页或分屏窗格的时候。

技能链接

https://github.com/HKUDS/CLI-Anything/blob/main/iterm2/agent-harness/cli_anything/iterm2_ctl/skills/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/CLI-Anything/blob/main/iterm2/agent-harness/cli_anything/iterm2_ctl/skills/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我在 iTerm2 中打开一个新标签页,在那里运行测试套件,并显示最后 50 行输出。”

每周 5 个新技能,1 分钟读完。

工作原理

这个技能通过 iTerm2 的 Python API 连接到 iTerm2,然后读取或发送文本到你选择的会话。输出可以以 JSON 格式显示,方便智能体读取。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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

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

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

Command Groups

Group Purpose
app App status, workspace snapshot, context management, app-level variables, modal dialogs, file panels
window Create, list, close, resize, fullscreen windows
tab Create, list, close, activate tabs; navigate split panes by direction
session Send text, inject raw bytes, read screen, full scrollback, split panes, prompt detection
profile List profiles, get profile details, list/apply color presets
arrangement Save and restore window layouts
tmux Full tmux -CC integration: bootstrap, connections, windows, commands
broadcast Sync keystrokes across panes via broadcast domains
menu Invoke any iTerm2 menu item programmatically
pref Read/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:

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:

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

# 1. Orient — snapshot every session: name, path, process, role, last output line
cli-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 set
cli-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 later
cli-anything-iterm2 session split --vertical --use-as-context
cli-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):

File Read when you need...
references/session-io.md Send text, inject bytes, read screen/scrollback, get selection
references/session-control.md Split panes, activate/close sessions, resize, rename, session variables
references/session-shell-integration.md wait-prompt, wait-command-end, get-prompt; reliable send→wait→read pattern
references/layout-window-tab.md Create/close/resize windows and tabs, navigate split panes
references/layout-arrangement.md Save and restore window layouts
references/app-context.md Snapshot (orientation), status, context management, app vars, modal dialogs, file panels
references/profile-pref.md Profiles list/get/presets, preferences read/write, tmux pref shortcuts
references/broadcast-menu.md Broadcast keystrokes to multiple panes, invoke menu items
references/tmux-commands.md All tmux CLI commands (bootstrap, send, tabs, create-window, set-visible)
references/tmux-guide.md Full 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:

cli-anything-iterm2
常见问题

我需要做什么设置?

你需要在 macOS 上安装 iTerm2,并在其偏好设置中开启 Python API。

它能在 Windows 上使用吗?

不能,它只适用于 macOS,因为 iTerm2 是一款 Mac 应用。

它可以读取屏幕吗?

可以,它可以读取屏幕以及会话的完整回滚历史。

详情

作者的原始描述

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 existi

repo: HKUDS/CLI-Anything

热度

GitHub 星标
58k
排名
#3212
许可证
Apache-2.0
更新时间
2026/9/21

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能