iterm-two-phase-close-pattern

Close iTerm2 sessions, panes, tabs, and windows with two-phase enumeration and deletion.

Updated Nov 9, 2025
One-click install
npx skills add https://github.com/manifoldlogic/claude-code-plugins --skill iterm-two-phase-close-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: iterm-two-phase-close-pattern
Source: https://github.com/manifoldlogic/claude-code-plugins/tree/main/plugins/iterm/skills/iterm-two-phase-close-pattern
Command: npx skills add https://github.com/manifoldlogic/claude-code-plugins --skill iterm-two-phase-close-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires AppleScript, bash, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the challenge of safely closing iTerm2 sessions, panes, tabs, and windows by implementing a two-phase architecture that minimizes the risk of data loss and ensures atomic operations.

Core Features & Use Cases

  • Two-Phase Architecture: Separates enumeration and deletion phases to enable dry-run previews and confirmation prompts.
  • Reverse Iteration: Ensures correct index handling during deletion to prevent index shifting bugs.
  • User Confirmation: Provides user confirmation for multiple matches to prevent accidental deletions.
  • Dry-Run Mode: Allows users to preview the operations without executing them.
  • Use Case: Ideal for developers and system administrators who need to manage multiple iTerm2 sessions and want to ensure that their operations are safe and reversible.

Quick Start

Use the iterm-two-phase-close-pattern skill to safely close all panes matching the pattern 'agent: tests' in iTerm2.

Frequently Asked Questions about iterm-two-phase-close-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely close multiple iTerm2 sessions without causing index shifting bugs?

To safely close iTerm2 sessions, use a two-phase architecture that separates enumeration and deletion phases. This approach employs reverse iteration during deletion to prevent index shifting bugs and ensures safe session management.

Can I preview which iTerm2 tabs and panes will be closed before executing the command?

Yes, you can preview operations using a dry-run mode. This mode allows you to enumerate and identify matching iTerm2 sessions, panes, and tabs for deletion without actually executing the closure, preventing accidental data loss.

What is the best way to automate closing iTerm2 windows with AppleScript and bash?

The best way to automate closing iTerm2 windows is using a shell scripting approach that leverages AppleScript. This method provides user confirmation prompts for multiple matches and uses reverse iteration to guarantee atomic operations.

Why does deleting iTerm2 panes by index shift remaining sessions and how to avoid it?

Deleting iTerm2 panes by index shifts remaining sessions because the list contracts after each deletion. Avoid this by using reverse iteration in the deletion phase, which processes items from bottom to top so prior indexes remain unaffected.

Do I need AppleScript to manage iTerm2 session closures from a bash script?

Yes, you need AppleScript alongside bash to manage iTerm2 session closures. AppleScript provides the necessary interface to interact with iTerm2's application state, while bash handles the shell scripting logic for the two-phase enumeration and deletion.