Overview
The iTerm2 terminal plugin provides:- Automatic tab creation in iTerm2
- tmux session attachment
- Session name-based tab identification
- Existing tab detection and reuse
- Window creation if no window exists
- Bulk tab opening for multiple sessions
- macOS-only operation
macOS only: This plugin requires macOS and iTerm2. On other platforms, it logs a warning and performs no operations.
Prerequisites
- macOS: Required for AppleScript support
- iTerm2: Download from https://iterm2.com
- tmux: Used by the default runtime plugin
Configuration
Add the iTerm2 terminal plugin to youragent-orchestrator.yaml:
Configuration Options
The iTerm2 plugin has no configuration options. It operates using iTerm2’s default profile and settings.The plugin uses your iTerm2 default profile settings. Customize your default profile in iTerm2 Preferences → Profiles to affect plugin behavior.
How It Works
Opening a Session
When you runao open <session-id>, the plugin:
- Checks for existing tab: Searches all iTerm2 windows and tabs for a session with matching name
- Selects if found: If tab exists, brings it to focus
- Creates new tab if needed: Opens new tab with tmux attach command
- Sets tab name: Names the tab/session for easy identification
Session Name Resolution
The plugin uses the runtime handle ID (tmux session name) if available, otherwise falls back to the orchestrator session ID:Tab Creation Process
- Activates iTerm2
- Creates window if none exists
- Creates new tab with default profile
- Sets session name
- Executes tmux attach command:
The
printf command sets the terminal title before attaching, ensuring the tab name persists even if tmux is disconnected.AppleScript Security
The plugin uses multiple layers of escaping to prevent injection:- AppleScript escaping: Escapes special characters for AppleScript strings
- Shell escaping: Escapes single quotes for shell commands
- Double escaping: Shell-escape first, then AppleScript-escape for write commands
Usage Examples
Open Single Session
- Create/select iTerm2 tab for the session
- Attach to the tmux session
- Focus the tab
Open All Sessions
- Open tabs for all active sessions
- 300ms delay between each tab (avoid AppleScript race conditions)
- Reuse existing tabs where possible
Check if Session is Open
Advanced Features
Existing Tab Detection
The plugin searches all iTerm2 windows and tabs for matching session names:Tab detection is not case-sensitive and matches exact session names. Partial matches are not supported.
Query-Only Session Check
TheisSessionOpen() method checks for tab existence without selecting it:
Bulk Opening with Delays
When opening multiple sessions, the plugin adds 300ms delays between operations:The delay prevents AppleScript race conditions where rapid tab creation can cause tabs to be created in the wrong window or order.
Troubleshooting
Nothing happens when running ao open
Nothing happens when running ao open
Check iTerm2 is installed:Check plugin is configured:Check logs:
Error: osascript execution failed
Error: osascript execution failed
Grant iTerm2 automation permissions:
- System Preferences → Security & Privacy → Privacy
- Select “Automation” in left sidebar
- Find your terminal app (Terminal.app, iTerm2, etc.)
- Enable checkbox for “iTerm.app”
Tabs created in wrong window
Tabs created in wrong window
This can happen with rapid tab creation. Solutions:
- Close extra iTerm2 windows
- Use
ao openfor individual sessions (not--all) - Wait a moment between manual
ao opencommands
openAll() helps, but can’t prevent all race conditions.Tab name doesn't match session
Tab name doesn't match session
The plugin sets both:
- iTerm2 session name (persists)
- Terminal title (via printf escape sequence)
- Check session.runtimeHandle.id in metadata
- Verify tmux session name matches
- Check for shell profile overrides (PS1, etc.)
tmux attach fails
tmux attach fails
- Verify tmux session exists:
- Check runtime plugin created session:
- Recreate session:
Plugin warns 'not supported on darwin'
Plugin warns 'not supported on darwin'
Your OS is not macOS. The iTerm2 plugin only works on macOS.Solution: Use a different terminal plugin:
Integration with tmux Runtime
The iTerm2 plugin is designed to work with the tmux runtime plugin: Runtime creates session:- Runtime creates tmux session
- Runtime stores session ID in
runtimeHandle.id - Terminal reads
runtimeHandle.idfor session name - Terminal runs
tmux attachwith that name
If using a different runtime plugin, ensure it sets
runtimeHandle.id to a value the terminal can use for attachment.macOS Catalina+ Permissions
On macOS Catalina (10.15) and later, you may need to grant additional permissions:- System Events access: Required for AppleScript
- Automation access: Required to control iTerm2
- Accessibility access: May be required for window focus
Comparison with Web Terminal
| Feature | iTerm2 | Web |
|---|---|---|
| Platform | macOS only | Any |
| Setup | iTerm2 required | Browser required |
| Tab management | Native OS tabs | Browser tabs |
| Keyboard shortcuts | iTerm2 shortcuts | xterm.js shortcuts |
| Copy/paste | Native | Browser-dependent |
| Customization | iTerm2 profiles | CSS/config |
| Remote access | Local only | Can be remote |
| Performance | Native | JavaScript |
Source Code
View the plugin source:- Package:
@composio/ao-plugin-terminal-iterm2 - Location:
packages/plugins/terminal-iterm2/src/index.ts - Functions:
runAppleScript()- Execute AppleScript snippetsshellEscape()- Escape strings for shellescapeAppleScript()- Escape strings for AppleScript (from core)findAndSelectExistingTab()- Search and focus existing tabopenNewTab()- Create new tab with tmux attach
Related
- Web Terminal - Browser-based terminal alternative
- tmux Runtime - Default runtime plugin
- Terminal Plugin Interface - Technical interface
- iTerm2 Documentation - Official iTerm2 docs
