agentleFS
lyhcodelyhcode/agent-skills/skills/iterm2-shell-setup/SKILL.md

iterm2-shell-setup

Skill2 starsChanged 8 months agoMITView on GitHub

iTerm2 shell integration setup and terminal environment configuration. Use this skill when the user wants to install or troubleshoot shell integration, set up command tracking, configure directory history, enable SSH shell integration on remote hosts, set up tmux integration with iTerm2, or fix issues with prompt detection, marks, or automatic features not working. Also trigger when the user mentions 'shell integration', command completion notifications, or wants features like right-click file download, automatic alerts for long-running commands, or recent directory navigation.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 6 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After installation, check that it's working:

    line 60
  2. Very specific:

    Run echo $ITERM_SESSION_ID — should output a value

    line 63
  3. Very specific:

    Check: type iterm2_print_user_vars should find the function

    line 64
  4. Very specific:

    If you disconnect, just tmux -CC attach to reconnect

    line 118
  5. Very specific:

    Add to ~/.zshrc (after the shell integration source line):

    line 132
  6. Very specific:

    Read references/troubleshooting.md for common issues and solutions.

    line 145
  7. Distinctive:

    When the user wants to set up shell integration:

    line 149
  8. Distinctive:

    Check if the integration script is sourced in the shell config

    line 157
  9. Distinctive:

    Check if the script file exists and is not corrupted

    line 158
  10. Distinctive:

    Check for conflicts with other prompt customization tools (Starship, Powerlevel10k, oh-my-zsh themes)

    line 159
  11. Distinctive:

    Verify the correct shell is being used

    line 160

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

iTerm2 Shell Integration & Environment Setup

Help the user install, configure, and troubleshoot iTerm2's shell integration features, plus tmux integration and remote SSH setup.

User's Environment

  • iTerm2 3.6.8 on macOS, using zsh
  • Shell integration: not currently installed

What Shell Integration Enables

Shell integration is the foundation for many of iTerm2's best features. Without it, these features don't work:

  • Command marks — Navigate between prompts with Cmd+Shift+Up/Down
  • Command status — Red/blue marks showing success/failure of each command
  • Automatic profile switching — Switch profiles based on hostname/user/path
  • Recent directories — Frecency-sorted directory list in the toolbelt
  • Command history — Searchable history across all sessions
  • File download — Right-click to download remote files via SCP
  • Long command alerts — Notification when a command finishes after N seconds
  • Captured output — Filter and interact with command output
  • Auto Composer — Native text editing for command input

Installation

Method 1: Automatic (Recommended)

iTerm2 can load shell integration automatically without modifying shell config files:

Settings > Profiles > General > Command > enable "Load shell integration automatically"

This injects the integration at session start without touching ~/.zshrc.

Method 2: Menu Install

iTerm2 > Install Shell Integration

This downloads the scripts and adds a source line to ~/.zshrc.

Method 3: Manual Install for zsh

Add to ~/.zshrc:

test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

Then download the script:

curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh

Verification

After installation, check that it's working:

  1. Open a new iTerm2 tab
  2. You should see a blue triangle mark at the left of each prompt
  3. Run echo $ITERM_SESSION_ID — should output a value
  4. Check: type iterm2_print_user_vars should find the function

Remote SSH Setup

To get shell integration features on remote hosts:

Option A: Automatic SSH Integration (iTerm2 3.5+)

iTerm2 has built-in SSH integration that doesn't require installing anything on the remote host. Enable it via the it2ssh command or configure in Settings.

Option B: Install on Remote Host

SSH into the remote host and run the appropriate install for its shell:

# For bash on remote:
curl -L https://iterm2.com/shell_integration/bash -o ~/.iterm2_shell_integration.bash
echo 'test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"' >> ~/.bashrc

# For zsh on remote:
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
echo 'test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"' >> ~/.zshrc

Supported Shells

ShellScript URL
zshhttps://iterm2.com/shell_integration/zsh
bashhttps://iterm2.com/shell_integration/bash
fishhttps://iterm2.com/shell_integration/fish
tcshhttps://iterm2.com/shell_integration/tcsh

tmux Integration

iTerm2 can natively control tmux, showing each tmux window as a native iTerm2 tab/window. This gives you iTerm2's UI (scrollback, search, profiles) with tmux's persistence.

How to Use

# Start new tmux session with iTerm2 integration
tmux -CC

# Attach to existing session with integration
tmux -CC attach

The -CC flag is the key — it enables iTerm2's native integration mode.

Key Points

  • Each tmux window becomes an iTerm2 tab
  • Each tmux pane becomes an iTerm2 split pane
  • Scrollback works natively (no tmux copy-mode needed)
  • If you disconnect, just tmux -CC attach to reconnect
  • The tmux dashboard (Shell > tmux > Dashboard) lets you manage sessions

Configuration

Settings > General > tmux:

  • "Open tmux windows as" — native tabs, native windows, or tabs in existing window
  • "Automatically hide the tmux client session" — hides the raw tmux control session
  • "Use tmux profile rather than profile of the connecting session" — use a separate profile for tmux sessions

User-Defined Variables

Shell integration enables user-defined variables that can be displayed in badges, status bar, and used by scripts.

Add to ~/.zshrc (after the shell integration source line):

iterm2_print_user_vars() {
  iterm2_set_user_var gitBranch $((git branch 2> /dev/null) | grep \* | cut -c3-)
  iterm2_set_user_var kubeContext $(kubectl config current-context 2>/dev/null)
}

These variables become available as \(user.gitBranch) in badges and interpolated strings.

Troubleshooting

Read references/troubleshooting.md for common issues and solutions.

Workflow

When the user wants to set up shell integration:

  1. Check current state — Look for iterm2_shell_integration in ~/.zshrc and check if ~/.iterm2_shell_integration.zsh exists
  2. Install — Use the appropriate method based on user preference
  3. Verify — Open a new tab and check for marks, $ITERM_SESSION_ID, and iterm2_print_user_vars
  4. Configure extras — Set up user variables, enable long command alerts, configure recent directories toolbelt

When troubleshooting:

  1. Check if the integration script is sourced in the shell config
  2. Check if the script file exists and is not corrupted
  3. Check for conflicts with other prompt customization tools (Starship, Powerlevel10k, oh-my-zsh themes)
  4. Verify the correct shell is being used

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.