it2

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 0 Imported by: 0

README

it2

Go Reference Go Report Card

Programmatic control of iTerm2 — sessions, splits, text I/O, buffer reading, state detection, and real-time events over the Unix socket API.

it2 turns iTerm2 into an orchestration layer for terminal workflows. Split panes, send commands, read output, detect state — from shell scripts, CI pipelines, or AI agents like Claude Code and Gemini CLI.

Install

Requires Go 1.21+ and iTerm2 3.3.0+.

go install github.com/tmc/it2/cmd/it2@latest
it2 auth check   # iTerm2 will prompt to allow API access

Quick Start

it2 session list                          # list all sessions
it2 session split -q                      # split pane, print new session ID
it2 session send-text $SID "make test"    # send text to a session
it2 session get-screen $SID               # read visible screen content
it2 session get-buffer $SID --lines 100   # read scrollback buffer

Agent Integration

it2 detects and interacts with AI agents running in terminal sessions. Built-in support for Claude Code; extensible to any agent via plugins.

State Detection

Check what a session is doing without reading the full buffer:

it2 session is-active $SID                # exit 0 if agent is working
it2 session has-modal $SID                # exit 0 if modal dialog detected
it2 session suggest-action $SID           # recommend: continue, approve, wait
it2 session claude-status $SID            # human-readable Claude Code status
it2 session get-state $SID --agent=auto   # full state as structured output
Auto-Respond

Watch a session and automatically respond to prompts:

it2 session autorespond $SID                     # default patterns
it2 session autorespond $SID --pattern "Continue?"  # custom pattern

The embedded claude-auto-approve plugin checks safety heuristics before approving any modal. See Claude Plugins Reference for hook setup and event logging.

Multi-Agent Workflows

it2 supports multi-agent patterns where sessions split, communicate, and read each other's output.

Split and Delegate
# Create a worker session and send it a task
WORKER=$(it2 session split -q --vertical)
it2 session set-badge "$WORKER" "$(echo $WORKER | cut -c1-8)\nWorker"
it2 session send-text "$WORKER" "cd /project && make lint"
Cross-Session Communication
# Read a session's output
it2 session get-buffer "$WORKER" --lines 50

# Wait for prompt, then send next command
it2 session send-text --require is-at-prompt "$WORKER" "make test"

# Skip delivery confirmation for speed
it2 session send-text --skip-confirm "$WORKER" "echo done"
Prime Protocol

Output inter-session communication guidelines for an agent:

it2 prime | it2 session send-text $SID -f -

This sends a protocol document that teaches agents how to respond via it2 session send-text, include session IDs, and format messages.

Broadcast

Send the same input to multiple sessions simultaneously:

it2 broadcast set $SID1 $SID2 $SID3   # create broadcast domain
it2 broadcast send "git pull"           # send to all sessions in domain
it2 broadcast clear                     # tear down broadcast domain

Plugin System

Plugins are executables on your PATH matching it2-session-*, it2-tab-*, or it2-window-*. They receive session context as JSON on stdin and return enrichment data on stdout.

it2 plugin list           # show discovered plugins with source and hash
it2 plugin run <name>     # run a plugin directly

Embedded plugins:

Plugin Type Purpose
is-at-prompt session Detect shell prompt (exit 0 = at prompt)
claude-has-modal session Detect Claude Code modal dialogs
claude-suggest-action session Recommend intervention for stuck sessions
claude-auto-approve session Auto-approve safe operations
claude-is-safe-operation session Check if an operation is safe to auto-approve
has-no-queued-claude-messages session Check for pending message queue
is-claude.sh session-process Detect if session runs Claude Code
tree.sh session-process Show process hierarchy for a session

PATH plugins shadow embedded plugins of the same name. See docs/TAXONOMY.md for the full plugin model.

Configuration

Environment Variables
Variable Description
ITERM_SESSION_ID Current session ID (set by iTerm2)
ITERM2_COOKIE Auth cookie (auto-requested if not set)
ITERM2_KEY Auth key (auto-requested if not set)
IT2_PLUGIN_PATHS Additional plugin search directories
IT2_PLUGIN_DEADLINE Plugin execution timeout (default 5s)
ITERM2_DEBUG Enable debug logging (1)
Global Flags
--format string      Output format: table, text, json, yaml (default "table")
--timeout duration   Connection timeout (default 5s)
Session IDs

Sessions accept UUIDs, short prefixes, or full w0t1p12:UUID format. When omitted, most commands use $ITERM_SESSION_ID (the current session).

Run it2 help [command] for detailed usage on any command.

Documentation

Overview

Package it2 provides a Go client library and CLI for the iTerm2 API.

it2 enables programmatic control of iTerm2 sessions, tabs, and windows over the Unix socket and WebSocket APIs. It handles authentication automatically and supports plugins for extensible session enrichment.

CLI Installation

go install github.com/tmc/it2/cmd/it2@latest

Library Usage

The internal/client package provides the Go API (internal; use the CLI for external automation):

c := client.New("ws://localhost:1912")
if err := c.Connect(ctx); err != nil {
	log.Fatal(err)
}
defer c.Close()

sessions, err := c.ListSessions(ctx)
if err != nil {
	log.Fatal(err)
}
for _, s := range sessions {
	fmt.Printf("%s %s\n", s.SessionID, s.WindowID)
}

err = c.SendText(ctx, sessions[0].SessionID, "echo hello\n")

Connection

The client prefers the Unix socket at ~/Library/Application Support/iTerm2/private/socket and falls back to ws://localhost:1912.

See Also

Directories

Path Synopsis
cmd
gen-docs command
it2 command
Command it2 provides comprehensive control over iTerm2 through its WebSocket API.
Command it2 provides comprehensive control over iTerm2 through its WebSocket API.
internal
cmd
Package cmd provides command implementations for the it2 CLI.
Package cmd provides command implementations for the it2 CLI.
cmd/alert
Package alert provides iTerm2 alert and dialog commands.
Package alert provides iTerm2 alert and dialog commands.
cmd/app
Package app provides commands for controlling the iTerm2 application.
Package app provides commands for controlling the iTerm2 application.
cmd/auth
Package auth provides commands for iTerm2 API authentication.
Package auth provides commands for iTerm2 API authentication.
cmd/color
Package color provides commands for managing iTerm2 colors and appearance.
Package color provides commands for managing iTerm2 colors and appearance.
cmd/colorpreset
Package colorpreset provides commands for managing iTerm2 color presets.
Package colorpreset provides commands for managing iTerm2 color presets.
cmd/control
Package control provides iTerm2 custom control management commands.
Package control provides iTerm2 custom control management commands.
cmd/event
Package event provides commands for managing iTerm2 event subscriptions.
Package event provides commands for managing iTerm2 event subscriptions.
cmd/filepanel
Package filepanel provides iTerm2 file panel dialog commands.
Package filepanel provides iTerm2 file panel dialog commands.
cmd/focus
Package focus provides commands for managing focus in iTerm2.
Package focus provides commands for managing focus in iTerm2.
cmd/job
Package job provides commands for job monitoring in iTerm2.
Package job provides commands for job monitoring in iTerm2.
cmd/keyboard
Package keyboard provides commands for managing keyboard bindings in iTerm2.
Package keyboard provides commands for managing keyboard bindings in iTerm2.
cmd/lifecycle
Package lifecycle provides iTerm2 session lifecycle management commands.
Package lifecycle provides iTerm2 session lifecycle management commands.
cmd/notification
Package notification provides commands for iTerm2 notification system.
Package notification provides commands for iTerm2 notification system.
cmd/preference
Package preference provides iTerm2 preference management commands.
Package preference provides iTerm2 preference management commands.
cmd/profile
Package profile provides commands for iTerm2 profile management.
Package profile provides commands for iTerm2 profile management.
cmd/prompt
Package prompt provides commands for managing prompts and command history in iTerm2 sessions using Shell Integration features.
Package prompt provides commands for managing prompts and command history in iTerm2 sessions using Shell Integration features.
cmd/selection
Package selection provides commands for managing text selection in iTerm2.
Package selection provides commands for managing text selection in iTerm2.
cmd/session
Package session provides commands for iTerm2 session management.
Package session provides commands for iTerm2 session management.
cmd/shell
Package shell provides commands for shell state detection and prompt tracking in iTerm2 sessions using Shell Integration features.
Package shell provides commands for shell state detection and prompt tracking in iTerm2 sessions using Shell Integration features.
cmd/shortcuts
Package shortcuts provides top-level convenience commands that wrap commonly used session commands.
Package shortcuts provides top-level convenience commands that wrap commonly used session commands.
cmd/snippet
Package snippet provides text snippet storage and retrieval commands.
Package snippet provides text snippet storage and retrieval commands.
cmd/tab
Package tab provides commands for iTerm2 tab management.
Package tab provides commands for iTerm2 tab management.
cmd/text
Package text provides commands for text operations in iTerm2.
Package text provides commands for text operations in iTerm2.
cmd/tool
Package tool provides direct access to built-in session plugins.
Package tool provides direct access to built-in session plugins.
cmd/utility
Package utility provides iTerm2 utility and helper commands.
Package utility provides iTerm2 utility and helper commands.
cmd/variable
Package variable provides commands for iTerm2 variable management.
Package variable provides commands for iTerm2 variable management.
cmd/window
Package window provides commands for iTerm2 window management.
Package window provides commands for iTerm2 window management.
cmdcore
Package cmdcore provides core command infrastructure for iTerm2 CLI operations.
Package cmdcore provides core command infrastructure for iTerm2 CLI operations.
cmderr
Package cmderr provides standardized error handling for iTerm2 CLI commands.
Package cmderr provides standardized error handling for iTerm2 CLI commands.
cmdutil
Package cmdutil provides command utilities for iTerm2 CLI operations
Package cmdutil provides command utilities for iTerm2 CLI operations
hints
Package hints provides a system for showing helpful suggestions to users, particularly for multi-agent workflows where Claude sessions need to understand inter-session communication protocols.
Package hints provides a system for showing helpful suggestions to users, particularly for multi-agent workflows where Claude sessions need to understand inter-session communication protocols.
iterm2settings
Package iterm2settings provides utilities for checking iTerm2 application state and settings.
Package iterm2settings provides utilities for checking iTerm2 application state and settings.
jqutil
Package jqutil provides jq filtering utilities for JSON output.
Package jqutil provides jq filtering utilities for JSON output.
plugins
Package plugins provides the plugin manifest schema and verification system.
Package plugins provides the plugin manifest schema and verification system.
plugins/verify
Package verify implements reproducible build verification for it2 plugins.
Package verify implements reproducible build verification for it2 plugins.
prime
Package prime provides the inter-session communication guidelines for multi-agent workflows.
Package prime provides the inter-session communication guidelines for multi-agent workflows.
scope
Package scope provides session filtering based on scope settings.
Package scope provides session filtering based on scope settings.
sessionid
Package sessionid provides utilities for managing iTerm2 session identifiers.
Package sessionid provides utilities for managing iTerm2 session identifiers.
sessionstate
Package sessionstate provides agent-agnostic session state detection and analysis.
Package sessionstate provides agent-agnostic session state detection and analysis.
sessionstate/agents/claude
Package claude provides Claude Code agent detection patterns.
Package claude provides Claude Code agent detection patterns.
validate
Package validate provides validation functions for iTerm2 CLI command inputs.
Package validate provides validation functions for iTerm2 CLI command inputs.
waitstable
Package waitstable provides utilities for detecting when a stream or buffer has stabilized (no changes for a configured duration).
Package waitstable provides utilities for detecting when a stream or buffer has stabilized (no changes for a configured duration).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL