home / skills / terrylica / cc-skills / iterm2-layout

This skill configures iTerm2 workspace layouts via TOML, enabling tab management, auto-launch scripts, and git worktree discovery.

npx playbooks add skill terrylica/cc-skills --skill iterm2-layout

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.5 KB
---
name: iterm2-layout
description: Configure iTerm2 workspace layouts with TOML. TRIGGERS - iTerm2 layout, workspace tabs, layout.toml, AutoLaunch.
---

# iTerm2 Layout Configuration

<!-- ADR: /docs/adr/2025-12-15-iterm2-layout-config.md -->

Configure iTerm2 workspace layouts with proper separation of concerns: private paths in TOML config, publishable code in Python script.

## When to Use This Skill

Use this skill when:

- Configuring iTerm2 workspace layouts
- Adding, removing, or modifying workspace tabs
- Setting up AutoLaunch scripts for iTerm2
- Configuring git worktree tab auto-discovery

## Configuration Overview

### File Locations

| File             | Location                               | Purpose                |
| ---------------- | -------------------------------------- | ---------------------- |
| Config (private) | `~/.config/iterm2/layout.toml`         | User's workspace paths |
| Script (public)  | `~/scripts/iterm2/default-layout.py`   | Layout logic           |
| Template         | `~/scripts/iterm2/layout.example.toml` | Example config         |

### Config File Format

```toml
# ~/.config/iterm2/layout.toml

[layout]
left_pane_ratio = 0.20    # 0.0 to 1.0
settle_time = 0.3         # seconds

[commands]
left = "br --sort-by-type-dirs-first"
right = "zsh"

[worktrees]
# Optional: Enable git worktree discovery
# main_repo_root = "~/projects/my-project"
# worktree_pattern = "my-project.worktree-*"

[[tabs]]
name = "home"
dir = "~"

[[tabs]]
name = "projects"
dir = "~/projects"

[[tabs]]
dir = "~/Documents"  # name defaults to "Documents"
```

## Setup Instructions

### First-Time Setup

```bash
/usr/bin/env bash << 'CONFIG_EOF'
# 1. Ensure config directory exists
mkdir -p ~/.config/iterm2

# 2. Copy template
cp ~/scripts/iterm2/layout.example.toml ~/.config/iterm2/layout.toml

# 3. Edit with your workspace paths
# Add [[tabs]] entries for each workspace

# 4. Restart iTerm2 to test
CONFIG_EOF
```

### Adding a New Tab

Add a `[[tabs]]` entry to `~/.config/iterm2/layout.toml`:

```toml
[[tabs]]
name = "MyProject"  # Tab display name (optional)
dir = "~/path/to/project"
```

**Name field**:

- If omitted, uses directory basename
- Custom names useful for abbreviations (e.g., "AF" instead of "alpha-forge")

### Removing a Tab

Delete or comment out the `[[tabs]]` entry:

```toml
# [[tabs]]
# name = "OldProject"
# dir = "~/old/project"
```

## Configuration Schema

| Section       | Key                | Type   | Default        | Description               |
| ------------- | ------------------ | ------ | -------------- | ------------------------- |
| `[layout]`    | `left_pane_ratio`  | float  | 0.20           | Left pane width (0.0-1.0) |
| `[layout]`    | `settle_time`      | float  | 0.3            | Wait after cd (seconds)   |
| `[commands]`  | `left`             | string | br...          | Left pane command         |
| `[commands]`  | `right`            | string | zsh            | Right pane command        |
| `[worktrees]` | `alpha_forge_root` | string | null           | Worktree root (optional)  |
| `[worktrees]` | `worktree_pattern` | string | `*.worktree-*` | Glob pattern              |
| `[[tabs]]`    | `dir`              | string | **required**   | Directory path            |
| `[[tabs]]`    | `name`             | string | basename       | Tab display name          |

## Troubleshooting

### Error: "Layout configuration not found"

**Symptom**: Script Console shows error about missing config

**Solution**:

```bash
# Create config from template
cp ~/scripts/iterm2/layout.example.toml ~/.config/iterm2/layout.toml
```

### Error: "Invalid TOML syntax"

**Symptom**: Script Console shows TOML parse error

**Solution**:

1. Check TOML syntax (quotes, brackets)
2. Validate with: `python3 -c "import tomllib; tomllib.load(open('~/.config/iterm2/layout.toml', 'rb'))"`

### Tabs Not Appearing

**Symptom**: iTerm2 opens but no custom tabs created

**Causes**:

1. No `[[tabs]]` entries in config
2. Config file in wrong location
3. Script not in AutoLaunch

**Solution**:

```bash
# Verify config location
ls -la ~/.config/iterm2/layout.toml

# Verify AutoLaunch symlink
ls -la ~/Library/Application\ Support/iTerm2/Scripts/AutoLaunch/

# Check Script Console for errors
# iTerm2 > Scripts > Manage > Console
```

### Directory Does Not Exist Warning

**Symptom**: Tab skipped with warning in Script Console

**Solution**: Verify directory path exists or create it:

```bash
mkdir -p ~/path/to/missing/directory
```

## Error Handling Behavior

The script uses "print + early return" pattern:

1. **Missing config**: Logs instructions to Script Console, exits cleanly
2. **Invalid TOML**: Logs parse error with details, exits cleanly
3. **Missing directory**: Logs warning, skips tab, continues with others

**Viewing errors**: Scripts > Manage > Console in iTerm2

## Git Worktree Detection (Optional)

Enable dynamic tab creation for git worktrees:

```toml
[worktrees]
main_repo_root = "~/projects/my-project"
worktree_pattern = "my-project.worktree-*"
```

**How it works**:

1. Script globs for `~/projects/my-project.worktree-*` directories
2. Validates each against `git worktree list`
3. Generates acronym-based tab names (e.g., `AF-ssv` for `sharpe-statistical-validation`)
4. Inserts worktree tabs after main project tab

## References

- [iTerm2 Python API](https://iterm2.com/python-api/)
- [TOML Specification](https://toml.io/)
- [XDG Base Directory Spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
- [ADR: iTerm2 Layout Config](/docs/adr/2025-12-15-iterm2-layout-config.md)

Overview

This skill configures iTerm2 workspace layouts using a TOML configuration and a lightweight Python script. It separates private user paths (kept in ~/.config/iterm2/layout.toml) from publishable layout logic (the script), enabling reproducible tab and pane setups and optional git worktree discovery. It includes AutoLaunch support so iTerm2 recreates your workspace on startup.

How this skill works

The Python script reads a TOML file that defines layout settings, pane commands, and a list of tabs with directories and optional names. It validates the config, creates tabs and split panes in iTerm2 via the Python API, and skips missing directories while logging warnings to the Script Console. Optionally the script can discover git worktrees by globs, validate them with git, and inject generated worktree tabs adjacent to their main project tab.

When to use it

  • You want consistent iTerm2 tabs and pane layouts across sessions or machines.
  • Setting up AutoLaunch so iTerm2 recreates a development workspace on startup.
  • Managing many project tabs and preferring config-driven workspace definitions.
  • Automatically discovering git worktrees and exposing each as its own tab.
  • Sharing layout logic while keeping personal paths private.

Best practices

  • Keep only machine-specific paths in ~/.config/iterm2/layout.toml and keep the script public-ready.
  • Use explicit [[tabs]] entries for important workspaces; omit name to use basename.
  • Set reasonable settle_time to allow shell directory changes to complete before running commands.
  • Validate TOML with tomllib or a quick Python load after edits to catch syntax errors.
  • Use AutoLaunch by placing the script symlink in iTerm2's Scripts/AutoLaunch folder for reliable startup behavior.

Example use cases

  • Create a home tab, a projects tab, and a Documents tab automatically when iTerm2 starts.
  • Auto-discover git worktrees under a mono-repo and open each as an abbreviated-named tab.
  • Define left/right pane commands (e.g., file browser in left, zsh in right) and a left_pane_ratio.
  • Provision a consistent terminal workspace across new machines by copying the TOML template and editing paths.
  • Quickly add or remove project tabs by editing the TOML and restarting iTerm2.

FAQ

What happens if a directory in the TOML does not exist?

The script logs a warning to the Script Console, skips that tab, and continues creating the remaining tabs.

How do I validate TOML syntax?

Use Python's tomllib: python3 -c "import tomllib; tomllib.load(open('~/.config/iterm2/layout.toml','rb'))" to check for parse errors.