Windows 下 Claude Code使用 Agent Teams 配置教程

在linux和macos系统下安装tmux,使用agent teams非常简单,但是在windows系统下无法直接安装tmux,只能另辟蹊径,于是我从github上找到了tmux_for_windows项目。

前提条件

1. 安装 Git for Windows

下载地址:https://git-scm.com/download/win

安装后确认:

where.exe git
# 输出示例:C:\Program Files\Git\cmd\git.exe

2. 安装 tmux for Windows

tmux 必须运行在 Git Bash(MinGW64)环境下,CMD 和 PowerShell 不支持,原因:

依赖 CMD/PowerShell Git Bash
PTY 伪终端
Unix 系统调用
MSYS2 运行库

安装步骤:

  1. 克隆仓库(或下载 zip):

    git clone https://github.com/hongwenjun/tmux_for_windows.git
    
  2. 管理员权限将 zip 解压到 Git 的 usr 目录:

    # PowerShell(管理员)
    Start-Process powershell -Verb RunAs -ArgumentList `
      "-Command Expand-Archive -Path 'tmux_for_windows\tmux_for_git-bash.zip' -DestinationPath 'C:\Program Files\Git\usr' -Force" -Wait
    
  3. 验证安装:

    # Git Bash 中
    tmux -V
    # 输出:tmux 2.7 或更高版本
    
  4. 复制 .tmux.conf(启用鼠标支持):

    Copy-Item "tmux_for_windows\.tmux.conf" -Destination "$env:USERPROFILE\.tmux.conf"
    

配置 Claude Code

settings.json 路径

范围 路径
全局(推荐) C:\Users\<用户名>\.claude\settings.json
项目级 <项目路径>\.claude\settings.json

完整配置

编辑 ~/.claude/settings.json,添加以下字段:

{
  "env": {
    "PATH": "<原有PATH>;C:\\Program Files\\Git\\usr\\bin",
    "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
  },
  "teammateMode": "tmux"
}

关键字段说明:

字段 说明
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS "1" 启用实验性 agent 团队功能
teammateMode "tmux" 使用 tmux 管理多个 agent 进程
PATH 追加 C:\Program Files\Git\usr\bin 让 Claude Code 能找到 tmux.exe

teammateMode 合法值:

  • "auto" — 自动选择
  • "tmux" — 使用 tmux 分 pane 运行(Windows 需配合 Git Bash)
  • "in-process" — 在同一进程内运行(不需要 tmux)

注意: teammateSessions 不是合法字段,settings.json 的 schema 会报错,不要添加。


工作原理

Git Bash(tmux 会话)
└── claude CLI 主进程
        └── 触发多 agent 并行任务
                ├── tmux pane 1 → claude 进程(Agent 1)
                ├── tmux pane 2 → claude 进程(Agent 2)
                └── tmux pane 3 → claude 进程(Agent 3)
  • 每个 teammate 是一个独立的 claude 进程,运行在单独的 tmux pane 中
  • 各 agent 有独立的上下文、环境变量和工作目录
  • 可通过 Ctrl+B + 方向键在 pane 之间切换,实时观察各 agent 输出

使用方式

启动方式

必须在 Git Bash 中启动 Claude Code:

# 方式一:在任意目录右键 → "Git Bash Here",然后
claude

# 方式二:在已有 tmux 会话中启动
tmux new-session -s work
claude

查看 tmux 会话

tmux list-sessions          # 查看所有会话
tmux list-panes -a          # 查看所有 pane
tmux attach-session -t work # 连接到指定会话

tmux 常用快捷键

快捷键 功能
Ctrl+B + 方向键 切换 pane
Ctrl+B + d 脱离会话(后台运行)
Ctrl+B + [ 进入复制/滚动模式
q 退出复制模式

验证配置

重启 Claude Code 后,执行以下检查:

# 1. 确认 tmux 可访问
tmux -V

# 2. 确认配置已加载(在 Claude Code 会话内执行)
# 触发一个多 agent 并行任务,观察是否在 tmux 中创建新 pane

常见问题

问题 原因 解决方案
tmux: command not found PATH 未包含 tmux 路径 在 settings.json 的 PATH 中追加 C:\Program Files\Git\usr\bin
解压时 Access Denied 写入 Program Files 需要管理员权限 Start-Process -Verb RunAs 以管理员运行
agent 不在新 pane 中出现 未在 Git Bash/tmux 环境下运行 claude 必须从 Git Bash 启动 Claude Code
teammateSessions 报 schema 错误 该字段不在官方 schema 中 删除该字段,只保留 teammateMode

参考

  • tmux for Windows 仓库:https://github.com/hongwenjun/tmux_for_windows
  • Git for Windows:https://git-scm.com/download/win
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐