with one click
terminal-monitoring
// Use when monitoring iTerm2 session activity, watching for state changes, subscribing to notifications, or implementing automated responses to terminal events.
// Use when monitoring iTerm2 session activity, watching for state changes, subscribing to notifications, or implementing automated responses to terminal events.
Control iTerm2 terminals. Use when splitting panes, sending commands to sessions, checking session output, setting badges, creating layouts, or coordinating multiple terminals.
Use when working with Claude Code sessions in iTerm2 - detecting Claude sessions, checking their status, linking sessions, or coordinating multiple Claude instances.
Use when managing multiple iTerm2 sessions, creating split layouts, navigating session hierarchies, or orchestrating terminal workflows across panes.
| name | terminal-monitoring |
| description | Use when monitoring iTerm2 session activity, watching for state changes, subscribing to notifications, or implementing automated responses to terminal events. |
| allowed-tools | ["Bash","Read","Grep"] |
Guidance for monitoring iTerm2 sessions and responding to events.
# Tail session output (like tail -f)
it2 session tail -f "$SESSION_ID"
# Watch session for state transitions
it2 session watch "$SESSION_ID"
# Monitor all sessions
it2 session watch --all
# Subscribe to notifications
it2 notification monitor --type keystroke
# List available notification types
it2 notification list-types
Common types:
keystroke - Key presses in sessionsscreen_update - Screen content changesprompt - Shell prompt events (requires shell integration)session_ended - Session terminationvariable_changed - iTerm2 variable modifications# Monitor keystrokes
it2 notification monitor --type keystroke
# Subscribe with JSON output for parsing
it2 subscribe screen_update --format json
# Watch single session
it2 session watch "$SID"
# Watch with specific interval
it2 session watch "$SID" --interval 2s
The watch command detects:
Follow session output like tail -f:
# Follow session output
it2 session tail -f "$SID"
# With line limit
it2 session tail -f "$SID" --lines 50
# Monitor jobs in a session
it2 job list "$SID"
# Watch for job completion
it2 job wait "$SID"
If shell integration is enabled:
# Check shell integration status
it2 session has-shell-integration "$SID"
# Get prompt metadata
it2 session prompt "$SID"
# Search command history
it2 prompt search "git commit"
Set up automatic responses to patterns:
# Auto-respond to prompts
it2 session autorespond "$SID" --pattern "Continue?" --response "y"
# Get suggested action
ACTION=$(it2 session suggest-action "$SID" --format json)
# Act based on state
STATE=$(it2 session get-state "$SID" --format json | jq -r '.state')
case "$STATE" in
"idle") echo "Session ready for input" ;;
"working") echo "Session busy" ;;
"waiting") echo "Session needs attention" ;;
esac
# Get current screen hash
HASH1=$(it2 session get-screen "$SID" | md5)
sleep 1
HASH2=$(it2 session get-screen "$SID" | md5)
if [ "$HASH1" != "$HASH2" ]; then
echo "Screen changed"
fi
# Wait for specific content
while ! it2 session get-screen "$SID" | grep -q "Complete"; do
sleep 1
done
echo "Task completed"
# Subscribe to events and process
it2 subscribe screen_update --session "$SID" --format json | while read event; do
# Process each event
echo "$event" | jq .
done
See references/notifications.md for all notification types. See references/shell-integration.md for prompt/command tracking. See workflows/automated-testing.md for CI/CD integration.