v0.1.0 — Now on GitHub

Go client for iTerm2

A developer-friendly Go library that mirrors the official iTerm2 Python API. Control sessions, split panes, capture screenshots, subscribe to events — all via WebSocket.

Everything you can do from iTerm2

Full coverage of the iTerm2 Python API — sessions, panes, variables, events, and more.

Session Control

SendText, GetBuffer, Inject, Activate, Close, Restart — complete session lifecycle.

Pane & Tab Management

SplitPane (vertical/horizontal), CreateTab, traverse nested splitter trees.

Variables & Properties

GetVariable, SetVariable, GetProperty, SetProperty, SetProfileProperty.

Screenshot

Capture Window, Tab, or Session as PNG via native macOS screencapture.

Event Subscription

Subscribe to new sessions, keystrokes, focus changes, variable changes.

RPC & Notifications

Register custom RPCs, handle server-originated requests, extend iTerm2.

Dead simple to use

Connect, traverse the window hierarchy, and send text — all in a few lines.

main.go connection.go
package main
import "github.com/phpgao/term2go"
func main() {
  // Connect to iTerm2 — auto-detects cookie/key
  term2go.Run(ctx, "my-app", func(caller term2go.Caller) error {
    app, _ := term2go.GetApp(caller)
    // Traverse window → tab → session hierarchy
    for _, w := range app.Windows {
      for _, t := range w.Tabs {
        // Send a command to each session
        sess := t.Root.FindSessionByID("session-id")
        sess.SendText(ctx, "echo Hello term2go!\n", false)
      }
    }
    return nil
  })
}
30+
RPC Functions
10+
Event Subscriptions
Go 1.23+
Language Version
MIT
License

Ready to build?

Control your terminal from Go. Star the repo, browse the examples, and start hacking.