Claude代码实例生成工具

一个允许在iTerm2窗口中生成新的Claude代码实例的MCP服务器工具,适用于开发者在macOS环境下快速启动交互式编码会话。

  • by pm990320
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 pm990320/claude-coder-mac-mcp

使用说明

克劳德编码器mac-mcp

一个MCP服务器,允许Claude Desktop在iTerm2窗口中生成新的Claude Code实例。

特性

  • spawn_claude_coder:使用给定的提示符生成一个新的Claude Code实例

    • 打开一个新的iTerm2窗口
    • 可选择与一起运行 --dangerously-skip-permissions (必须在服务器上启用)
    • 将提示直接传递给Claude
    • 终端变得完全互动
  • list_iterm_windows:列出所有iTerm2窗口和会话

需求

安装

通过npm(推荐)

npm install -g claude-coder-mac-mcp

来源

git clone https://github.com/pm990320/claude-coder-mac-mcp.git
cd claude-coder-mac-mcp
npm install
npm run build

验证安装

claude-coder-mac-mcp check

这将运行环境检查,以验证macOS、iTerm2、Claude Code CLI和自动化权限是否都配置正确。

CLI使用情况

CLI有多个命令:

# Show help
claude-coder-mac-mcp --help

# Start the MCP server (used by Claude Desktop)
# By default, spawned Claude instances run in normal mode (user must approve actions)
claude-coder-mac-mcp mcp

# Start the MCP server with --dangerously-skip-permissions enabled
# WARNING: This allows spawned Claude instances to run without user approval
claude-coder-mac-mcp mcp --dangerously-skip-permissions

# Test spawning a Claude Code instance directly (normal mode)
claude-coder-mac-mcp spawn "Help me write a REST API"
claude-coder-mac-mcp spawn "Fix the tests" -d ~/myproject -t "Test Fixer"

# Test spawning with --dangerously-skip-permissions
claude-coder-mac-mcp spawn "Fix the tests" --dangerously-skip-permissions

# List current iTerm2 windows
claude-coder-mac-mcp list

# Check environment is configured correctly
claude-coder-mac-mcp check

Claude桌面配置

添加到您的Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json):

正常模式 (用户必须批准Claude Code操作):

{
  "mcpServers": {
    "claude-coder-mac": {
      "command": "node",
      "args": ["/path/to/claude-coder-mac-mcp/dist/index.js", "mcp"]
    }
  }
}

带有--危险地跳过权限 (Claude Code自主运行):

{
  "mcpServers": {
    "claude-coder-mac": {
      "command": "node",
      "args": ["/path/to/claude-coder-mac-mcp/dist/index.js", "mcp", "--dangerously-skip-permissions"]
    }
  }
}

使用Claude Desktop

配置后,您可以要求Claude Desktop生成新的Claude Code实例:

“启动一个新的Claude编码器,在~/myproject上处理我的项目,任务是:实现用户身份验证”

克劳德将使用 spawn_claude_coder 使用新的Claude Code会话打开iTerm2的工具。

权限

首次使用时,macOS会要求您授予自动化权限。首选

系统设置>隐私和安全>自动化

并确保运行MCP服务器的应用程序(例如Claude Desktop)有权控制iTerm2。

MCP工具参数

spawn_claude_coder

参数 必填 说明
prompt 是 给Claude Code的任务/提示
workingDirectory 无 运行Claude代码的目录(默认为~)
windowTitle 否 iTerm2窗口的自定义标题

注:是否 --dangerously-skip-permissions 传递给生成的Claude实例的参数由服务器启动标志控制,而不是由工具参数控制。

list_iterm_windows

没有参数。列出所有打开的iTerm2窗口及其会话。

发展

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Lint
npm run lint

# Fix lint issues
npm run fix

# Type check
npm run typecheck

项目结构

src/
├── index.ts    # CLI entrypoint (uses commander)
├── server.ts   # MCP server setup and tool registration
├── spawn.ts    # Core spawn functionality
├── iterm.ts    # iTerm2 AppleScript utilities
└── check.ts    # Environment verification checks

tests/
├── spawn.test.ts   # Unit tests for spawn functions
└── iterm.test.ts   # Unit tests for iTerm utilities

为了可测试性,这些模块是分开的- spawn.ts 和 iterm.ts 包含可以独立进行单元测试的纯函数。

许可证

麻省理工学院