cmux-mcp

MCP server for controlling cmux (Ghostty-based terminal) via native CLI. Send commands, read output, send control characters — all in background via Unix socket.

cmux-mcp

한국어

MCP server that gives AI agents full control of your cmux terminal.

Let Claude run commands, read output, manage tabs/panes/workspaces/windows, and send control characters in your cmux terminal -- all through the Model Context Protocol. Works in the background. No focus stealing.

Quick Start

Option A: Claude Code Plugin (Recommended)

/plugin marketplace add daegweon/cmux-mcp
/plugin install cmux-mcp@cmux-tools

That's it. The MCP server is configured automatically.

Option B: npx (No build required)

Edit ~/.claude/settings.json:

{
  "mcpServers": {
    "cmux-mcp": {
      "command": "npx",
      "args": ["-y", "cmux-mcp"]
    }
  }
}

Restart Claude Code.

Option C: Clone and build

git clone https://github.com/daegweon/cmux-mcp.git
cd cmux-mcp
npm install && npm run build

Edit ~/.claude/settings.json:

{
  "mcpServers": {
    "cmux-mcp": {
      "command": "node",
      "args": ["/absolute/path/to/cmux-mcp/build/index.js"]
    }
  }
}

Restart Claude Code.

Claude Desktop setup

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "cmux-mcp": {
      "command": "node",
      "args": ["/absolute/path/to/cmux-mcp/build/index.js"]
    }
  }
}

Restart Claude Desktop after saving.

Any MCP client

cmux-mcp communicates over stdio. Point your MCP client to node /path/to/cmux-mcp/build/index.js.

Requirements

  • macOS
  • cmux.app installed and running
  • Node.js 18+
  • cmux socket control mode set to Automation or Open Access (Settings > Automation > Socket Control Mode)

Tools

cmux-mcp exposes the full cmux CLI as MCP tools. All terminal I/O tools support an optional surface parameter for targeting specific tabs.

Terminal I/O

ToolDescription
write_to_terminalSend commands to the terminal. Enter is appended automatically. Returns new output line count.
read_terminal_outputRead the last N lines from the terminal buffer.
send_control_characterSend Ctrl+C, Ctrl+Z, Escape, or any control character.

Surface (Tab) Management

ToolDescription
list_surfacesList all tabs in a workspace with IDs and titles.
new_surfaceCreate a new terminal tab.
close_surfaceClose a specific tab.
focus_surfaceFocus (activate) a specific tab.
move_surfaceMove a tab to a different pane, window, or position.
reorder_surfaceReorder a tab within its pane.
rename_tabRename a tab.
new_splitSplit the current surface into a new pane.
drag_surface_to_splitDrag a surface to create a split.
refresh_surfacesRefresh all surfaces.
surface_healthCheck health of surfaces.

Pane Management

ToolDescription
list_panesList all panes in a workspace.
new_paneCreate a new pane (split) with direction.
focus_paneFocus a specific pane.
resize_paneResize a pane in a given direction.
swap_paneSwap two panes.
break_paneBreak a pane out into a new workspace.
join_paneJoin a pane into another pane.
last_paneSwitch to the last active pane.
list_panelsList all panels in a workspace.
focus_panelFocus a specific panel.

Window Management

ToolDescription
list_windowsList all windows.
new_windowCreate a new window.
close_windowClose a specific window.
focus_windowFocus a specific window.
current_windowShow current window info.
rename_windowRename the current window.
next_window / previous_window / last_windowNavigate between windows.
move_workspace_to_windowMove a workspace to a different window.

Workspace Management

ToolDescription
list_workspacesList all workspaces.
new_workspaceCreate a new workspace with optional cwd/command.
close_workspaceClose a specific workspace.
select_workspaceSwitch to a specific workspace.
rename_workspaceRename a workspace.
current_workspaceShow current workspace info.
reorder_workspaceReorder a workspace in the sidebar.

Search & Structure

ToolDescription
find_windowSearch for a window by content or title.
treeShow the full tree structure (windows/workspaces/panes/surfaces).
identifyShow identity info for the current surface/workspace.

Notifications

ToolDescription
notifySend a notification with title, subtitle, and body.
list_notificationsList all notifications.
clear_notificationsClear all notifications.

Sidebar Metadata

ToolDescription
set_status / clear_status / list_statusManage status entries in the sidebar.
set_progress / clear_progressManage a progress bar in the sidebar.
sidebar_stateShow the current sidebar state.

Log

ToolDescription
logWrite a log entry to the workspace sidebar.
clear_logClear log entries.
list_logList log entries.

Buffer

ToolDescription
set_bufferSet a named buffer with text content.
list_buffersList all buffers.
paste_bufferPaste a buffer into the terminal.

Terminal Control

ToolDescription
clear_historyClear terminal scrollback history.
capture_paneCapture pane content (tmux-compatible).
respawn_paneRespawn a pane (restart the shell).
pipe_panePipe pane output to a shell command.
display_messageDisplay a message overlay.
trigger_flashTrigger a visual flash on the terminal.

Hooks & Misc

ToolDescription
set_hookSet, list, or unset event hooks.
wait_forWait for or send a named signal.
set_app_focusSet the app focus state.
markdown_openOpen a markdown file in a formatted viewer with live reload.
versionShow cmux version.
pingPing the cmux socket.

Browser

ToolDescription
browserControl the cmux built-in browser with subcommands: open, navigate, snapshot, click, type, eval, screenshot, and many more.

Real-World Examples

Run tests and analyze failures:

"Run the test suite and tell me which tests are failing"

Claude sends npm test, reads the output, and summarizes the failures.

Multi-tab SSH sessions:

"Open two new tabs, SSH into server-a in one and server-b in the other, then compare their disk usage"

Claude creates tabs, sends SSH commands to each, reads output from both, and compares.

Interactive REPL session:

"Open a Python REPL and check if pandas is installed"

Claude starts python3, types import pandas, reads the result, and reports back.

Long-running process management:

"Start the dev server, wait for it to be ready, then run the health check"

Claude sends the start command, polls the output until "ready" appears, then runs the next command.

Why cmux-mcp?

Background operation

cmux-mcp uses cmux's native CLI (cmux send, cmux read-screen, cmux send-key) which communicates via Unix socket. This means:

  • Works while cmux is in the background
  • No window focus stealing
  • No AppleScript activation delays
  • Reliable even during app initialization

CLI vs AppleScript

This project was forked from ferrislucas/iterm-mcp and completely rewritten. Here's why:

AppleScript (iterm-mcp)cmux CLI (cmux-mcp)
FocusMay steal focus, activate appNo focus change, Unix socket
Buffer readingGhostty write_scrollback_file (debug-only)cmux read-screen (stable production API)
StartupFails if app not fully initializedSocket-based, more resilient
TargetingAlways "front window"--surface flag for precise pane targeting
Key supportASCII codes onlyNamed keys: ctrl+c, escape, enter, arrows
StabilityFragile to app state changesDecoupled via socket IPC

Smart completion detection

cmux-mcp doesn't just blindly wait after sending a command. It monitors the TTY's CPU activity to know when a command actually finishes -- even for commands that produce output over time. As of v1.3.1, the polling interval was reduced from 350ms to 150ms and the idle threshold from 1000ms to 500ms, making write_to_terminal roughly 2x faster.

Token efficient

Agents read only the lines they need. A npm test that produces 500 lines of output? The agent first gets told "500 lines were output", then reads just the last 20 lines to check for errors. No wasted context window.

Handling Known cmux Issues

cmux-mcp's architecture avoids several known cmux edge cases:

IssueProblemHow cmux-mcp handles it
#152read-screen was debug-onlyUses the now-stable production CLI
#2042Invalid surface ID silently falls back to focused paneArchitecture supports --surface for explicit targeting
#1715TabManager unavailable during startup breaks hooksSocket-based CLI avoids initialization timing issues
#2153send-key didn't support arrow keysUses the updated upstream API with full key support
#2210Sidebar toggle corrupts prompt via SIGWINCHReads buffer after settling delay to avoid corrupted output

Architecture

MCP Client (Claude Code, Claude Desktop, etc.)
    |  stdio
cmux-mcp server
    |  child_process
cmux CLI (send / read-screen / send-key / ...)
    |  Unix socket
cmux.app (Ghostty-based terminal)
    |
macOS PTY

Core modules:

ModuleRole
cmux-pathResolves cmux binary path: CMUX_PATH env > which cmux > macOS default paths > fallback
CommandExecutorSends commands via cmux send, waits for completion. Caches TTY path for 60s.
TtyOutputReaderReads terminal buffer via cmux read-screen
SendControlCharacterSends control keys via cmux send-key
ProcessTrackerMonitors TTY processes for completion detection

Development

npm run build          # Compile TypeScript
npm run watch          # Auto-rebuild on changes
npm test               # Run unit tests
npm run e2e            # Run E2E tests (requires running cmux)
npm run inspector      # Open MCP Inspector for interactive debugging

Safety

  • No built-in command restrictions. Commands run with your shell's permissions.
  • Monitor AI activity and interrupt if needed.
  • Start with focused tasks until you're familiar with the model's behavior.

Credits

Privacy

cmux-mcp does not collect or transmit any data. All processing is local. See PRIVACY.md for details.

License

MIT

相關伺服器

NotebookLM 網頁匯入器

一鍵將網頁和 YouTube 影片匯入 NotebookLM。超過 200,000 位使用者信賴。

安裝 Chrome 擴充功能