tab-close-race-mitigation

Capture tab titles before directory changes to reliably close iTerm tabs in scripts.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This skill addresses race conditions that occur when a script attempts to close its own iTerm tab after changing directories or removing the working directory.

Core Features & Use Cases

  • Capture Tab Pattern: Store the tab pattern (title) before directory changes or worktree removals.
  • Pattern Matching: Use the captured pattern to ensure the script can close its own tab even after the directory changes.
  • Non-Fatal Tab Close: Handle cases where the tab cannot be closed successfully, allowing the script to continue executing.

Quick Start

Add the skill and run it with the required arguments.

Frequently Asked Questions about tab-close-race-mitigation

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

FAQPage Schema
Why does my iTerm tab fail to close after a shell script changes the directory?

An iTerm tab may fail to close after a directory change because the shell script loses its reference to the original working directory, creating a race condition. Capturing the tab title before changing directories ensures the script can still target and close its own tab.

How do I prevent race conditions when closing iTerm tabs from a shell script?

To prevent race conditions when closing iTerm tabs, capture the tab title pattern before executing directory changes or worktree removals. The script then uses this stored pattern to match and close the correct tab even after the working directory is gone.

What happens if a shell script cannot match and close its own iTerm tab?

If a shell script cannot successfully match and close its own iTerm tab, the close operation is handled non-fatally. This allows the script to continue executing its remaining commands instead of crashing or hanging on the tab closure failure.

When do I need to capture the iTerm tab title before removing a worktree?

You need to capture the iTerm tab title before removing a worktree because the directory path the tab relies on will be deleted. Storing the title pattern beforehand lets the script identify the tab and close it after the worktree removal.

Can I use shell scripting to manage terminal tabs in iTerm without causing script failures?

Yes, you can use shell scripting to manage terminal tabs in iTerm without failures by implementing non-fatal tab closing logic. By capturing tab titles before directory changes, the script gracefully handles closure failures and continues executing.