iTerm2 MCP Server
This MCP server lets Claude inspect iTerm2 sessions, stage commands for user approval, execute them, and read terminal output safely.
List iTerm2 sessions with IDs, TTY, window/tab, and name; Claude's own session is marked and untargetable.
Stage single-line commands in a target session without pressing Enter, optionally replacing an existing staged command.
Execute a staged command only after user approval, waiting by default for output to settle or a prompt, then returning only new output.
Read session output using
new(unseen lines) ortailmodes, with optional regex grep and output-size caps.Clear a staged, unexecuted command line.
Create a new iTerm2 tab and return its session ID.
Target sessions by ID or default to the last used session; works with local and SSH sessions and refuses multiline commands.
Provides tools for interacting with iTerm2 terminal sessions, including listing sessions, proposing and executing commands with approval, reading command output, clearing staged commands, and creating new tabs. It can also control remote SSH sessions running inside iTerm2.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@iTerm2 MCP Server check disk space on my system"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
iTerm2 MCP Server
An MCP (Model Context Protocol) server that lets Claude interact with your iTerm2 terminal sessions with an approval workflow. You see proposed commands before they execute!
Docs: Quick start ยท Architecture ยท Changelog
Features
๐ List all iTerm2 sessions - See all your terminal windows, tabs, and sessions
๐ Propose commands - Claude types commands but waits for your approval
โ Execute on approval - You explicitly approve each command before it runs
๐ Read output - Claude can see command results to help debug or continue
โก Run and wait - Executing returns just the new output once the command finishes (no polling)
๐ชถ Token-lean - Reads return only output Claude hasn't seen yet, capped, optionally grep-filtered
๐ฏ Targets sessions by ID - Work in any pane; refuses the pane Claude itself runs in
๐ Create new tabs - Spin up fresh terminal sessions as needed
๐ Works with SSH - Control remote sessions just like local ones
Related MCP server: mcp-terminal-server
How It Works
You chat with Claude in Claude Code or the Claude desktop app
Claude proposes a command - It gets typed in your terminal but doesn't execute
You review it - See the actual command in your terminal window
You approve or reject - Tell Claude to proceed or cancel
Claude executes - Only then does it press Enter
Installation
Prerequisites
macOS (tested on macOS 10.15+)
iTerm2 installed
Node.js 18+ (required for MCP SDK)
Claude Code and/or Claude Desktop
Quick Install
cd iterm2-mcp-server
./install.shThe installer will:
Detect your Node.js installation (handles nvm automatically)
Install npm dependencies
Show you the exact config to add
Guide you through iTerm2 automation setup
Manual Setup
If you prefer to set up manually:
1. Install Dependencies
npm install
chmod +x index.js2. Find Your Node.js Path
CRITICAL: You must use the full path to Node.js, not just "node".
# If using nvm (most common issue)
which node
# Example output: /Users/yourname/.nvm/versions/node/v20.20.0/bin/node
# If using Homebrew
which node
# Example output: /opt/homebrew/bin/nodeWhy? Claude Desktop doesn't inherit your shell's nvm setup, so it defaults to an old Node version if you just use "node". Using the full path ensures it always uses the right version.
3. Configure Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"iterm2": {
"command": "/Users/yourname/.nvm/versions/node/v20.20.0/bin/node",
"args": ["/absolute/path/to/iterm2-mcp-server/index.js"]
}
}
}Replace:
The node path with YOUR actual path from step 2
The index.js path with the absolute path to where you installed this
3b. Or add to Claude Code
claude mcp add --scope user iterm2 -- "$(which node)" /absolute/path/to/iterm2-mcp-server/index.js3c. Optional: install the agent skill
skills/iterm2-terminal/SKILL.md tells the agent when to use these tools and how: pick the session, stage the command, ask, then execute, and never stack commands. For Claude Code:
mkdir -p ~/.claude/skills && cp -r skills/iterm2-terminal ~/.claude/skills/The skill is also listed free on Agensi.
4. Set Up iTerm2 Automation (One-Time)
IMPORTANT: To grant initial permissions, you need to temporarily allow automation:
Open iTerm2 Preferences (โ,)
Go to General โ Magic
Change "Require 'Automation' permission" to: "Allow all apps to connect"
Restart iTerm2
Restart Claude Desktop (โQ then reopen)
Use Claude to interact with iTerm2 once (e.g., "list my sessions")
Change back to "Require 'Automation' permission" for security
Why? macOS needs to see an actual automation attempt before it registers Claude's access. This one-time setup makes it work.
5. Restart Claude Desktop
Quit completely (โQ) and reopen.
Usage
Basic Workflow
Open Claude Desktop and start a conversation
Make sure iTerm2 is running
Ask Claude to help with terminal tasks
Example Conversations
List Sessions:
You: "List my iTerm sessions"
Claude: [shows your sessions]Run Commands:
You: "Check disk space on my system"
Claude: "I've typed 'df -h' in your terminal. Should I execute it?"
You: "Yes"
Claude: [executes and shows results]SSH Sessions:
You: "SSH to my server and check if nginx is running"
Claude: [proposes: ssh user@server]
You: "Go ahead"
Claude: [connects, then proposes: systemctl status nginx]Tools
Tool | What it does |
| One line per session: |
| Types a single-line command into a session without pressing Enter. Refuses if a command is already staged there (unless |
| Presses Enter on the staged command, then (by default) waits until a prompt returns or output settles and returns only the new output: |
|
|
| Clears the staged line (Ctrl-U). |
| Opens a tab and returns its session ID. |
session_id is optional after the first call; it defaults to the last session used.
Limitations
Multi-line commands are refused by design. Join with
;/&&, or write a script file and run that.Prompt detection is heuristic (ends in
$ # % > โฏ -->,--More--,Password:,?; right-aligned prompt segments are ignored). If it doesn't match your prompt, output is returned once it stops changing (settle_ms), or passprompt_regex.Staged-command tracking lives in the server process; if you run or clear a staged command by hand, the next propose notices the line changed and carries on.
Security
What's Protected
โ
Explicit approval required - Commands are typed but not run automatically
โ
Visible actions - Every command appears in your terminal
โ
Local only - No network communication, MCP over stdio
โ
No credentials stored - Uses your existing SSH sessions
โ
SSH safe - Works with remote sessions without installing anything remotely
Best Practices
Review every command before approving
Use iTerm2's "Require 'Automation' permission" setting after initial setup
Don't approve commands you don't understand
Claude can see terminal output after commands run
Troubleshooting
"Node.js version too old" or MCP server crashes
Problem: You're using Node.js < 18
Solution: The installer handles this automatically, or manually:
# Check version
node --version
# If using nvm
nvm use 20 # or higher
# Update your config with the new path
which node # Use this full path in claude_desktop_config.json"Can't get session" or AppleScript errors
Problem: iTerm2 automation not set up
Solution:
Temporarily set iTerm2 to "Allow all apps to connect"
Restart iTerm2 and Claude Desktop
Use Claude once ("list my sessions")
Lock down automation again
Commands don't appear in terminal
Problem: Wrong session ID or permissions
Solution:
Ask Claude to run
list_iterm_sessionsagain (IDs change when panes are closed/reopened)"Session not found" means the ID is stale; "Not permitted" means Automation permission
"Server disconnected" in logs
Problem: Usually Node version mismatch
Solution:
Check
~/Library/Logs/Claude/mcp-server-iterm2.logVerify you're using the full path to Node 18+
Run
./install.shagain to get the right path
Permission dialog never appears
Problem: macOS doesn't show the automation dialog
Solution:
Use the temporary "Allow all apps" method described above
Make sure iTerm2 is running when you restart Claude
Check System Settings โ Privacy & Security โ Automation
Architecture
โโโโโโโโโโโโโโโโโโโ
โ Claude Code / โ
โ Claude Desktop โ
โโโโโโโโโโฌโโโโโโโโโ
โ MCP Protocol
โ (JSON-RPC over stdio)
โผ
โโโโโโโโโโโโโโโโโโโ
โ MCP Server โ
โ (Node.js) โ
โโโโโโโโโโฌโโโโโโโโโ
โ AppleScript
โ (session by ID)
โผ
โโโโโโโโโโโโโโโโโโโ
โ iTerm2 โ
โ (your shells) โ
โโโโโโโโโโโโโโโโโโโDevelopment
Running Tests
# Check if iTerm2 can be controlled
osascript -e 'tell application "iTerm2" to get version'
# End-to-end test: opens a scratch tab, runs echo/seq through the server, closes it
npm testLogs
# Watch MCP server logs
tail -f ~/Library/Logs/Claude/mcp-server-iterm2.logFuture Improvements
Multi-session support (target sessions by ID) โ v0.2.0
Quote/special character handling โ v0.2.0
Multi-line commands (needs a staging approach that doesn't press Enter per line)
Command history tracking
Integration with tmux/screen
Python API integration for better reliability
Contributing
Improvements welcome! Key areas:
Safe multi-line staging
Prompt detection for more shells/devices
Tests and documentation
License
MIT
Credits
Built with:
MCP SDK - Model Context Protocol from Anthropic
AppleScript - macOS automation
iTerm2 - Best terminal for macOS
Node.js - Runtime environment
Acknowledgments
Special thanks to the community for testing and feedback during development!
Available Tools
6 toolsclear_proposed_commandA
Clear the staged (unexecuted) command line in a session (Ctrl-U).
Inputs: session_id.
create_new_tabA
Create a new iTerm2 tab (default profile) and return its session ID.
Inputs: no named parameters.
execute_commandA
Press Enter on the staged command (only after the user approved it). By default waits until the output settles or a prompt returns, then returns just the new output โ no separate read needed.
Inputs: grep, wait, max_chars, settle_ms, +3 more.
list_iterm_sessionsA
List iTerm2 sessions: id, tty, window/tab, name. The session Claude itself runs in is marked and can't be targeted.
Inputs: no named parameters.
propose_commandA
Type a single-line command into an iTerm2 session WITHOUT pressing Enter, for the user to review. Then ask the user; call execute_command only after they approve, or clear_proposed_command if they decline. Refuses if a command is already staged there (unless replace: true) and refuses multi-line commands.
Inputs: command (required), replace, session_id, description.
read_session_outputA
Read an iTerm2 session's screen. mode 'new' (default) returns only lines not already returned for this session; 'tail' returns the last N lines (scrollback included).
Inputs: grep, mode, lines, max_chars, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
TDQS
Scored across 6 tools
Each tool has a clearly distinct role: listing sessions, staging a command, executing a staged command, clearing a staged command, creating a tab, and reading screen output. The propose/execute/clear trio is tightly coupled but the descriptions make the boundaries explicit.
All names follow a consistent snake_case verb_noun pattern: list_iterm_sessions, propose_command, execute_command, create_new_tab, read_session_output, clear_proposed_command. Minor resource-name variation (iterm_sessions vs new_tab) does not break the pattern.
Six tools is well-scoped for controlling iTerm2 sessions without bloat. Each tool corresponds to a necessary step in the session/command workflow.
Core workflows are covered: discover sessions, create tabs, stage/execute/clear commands, and read output. Minor gaps exist, such as closing tabs/sessions, splitting panes, or focusing/naming sessions, but agents can work around them.
Related MCP Connectors
Lets Claude, ChatGPT and other AI chats work on your Linux computers: terminal, files and browser.
1Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Let ChatGPT and Claude read and edit files, search and run commands on your own computer.
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Claude to execute commands and manage directory-aware panes within tmux sessions for a shared terminal experience. It features smart output capture, interactive prompt detection, and background task management.2MIT
- FlicenseNot gradedqualityCmaintenanceEnables running interactive terminals inside Claude Code and Claude Desktop, supporting multiple sessions for different tasks.-
- FlicenseNot gradedqualityDmaintenanceEnables interactive terminal sessions within Claude Code and Desktop, allowing users and AI to execute commands and manage multiple tabs.2-
- AlicenseNot gradedqualityDmaintenanceEnables Claude Desktop to spawn new Claude Code instances in iTerm2 windows for interactive coding sessions.16 npmMIT