claude+tmux 团队模式使用

362 阅读5分钟

使用 cc switch 管理AI工具,安装cc-switch

安装 Claude code ,参考文档

推荐好用的 skills superpowers 介绍文档

直接指定使用,例如 使用 brainstorming 技能

Superpowers 技能说明

核心工作流技能

技能用途触发时机
brainstorming头脑风暴、探索方案任何创造性工作之前
writing-plans编写实现计划有需求规格,开始编码前
executing-plans执行实现计划有书面计划要执行时
test-driven-development测试驱动开发实现功能或修复 bug 前

质量保障技能

技能用途触发时机
systematic-debugging系统化调试遇到 bug 或测试失败
verification-before-completion完成前验证声称"完成了"之前
requesting-code-review请求代码审查完成任务后
receiving-code-review处理代码审查反馈收到审查意见后

高级协作技能

技能用途触发时机
dispatching-parallel-agents分发并行任务2+ 独立任务可并行执行
subagent-driven-development子代理驱动开发在当前会话中执行计划
using-git-worktreesGit 工作树隔离需要隔离开发环境
finishing-a-development-branch完成开发分支实现完成,决定如何集成

安装 Homebrew(如果还没有)
Homebrew 是 macOS 的包管理器。打开 Terminal 运行:

/bin/bash -c "$(curl -fsSL 
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

1.安装完后验证:

brew --version
# Homebrew 4.x.x

如果你的 Mac 是 Apple Silicon(M1/M2/M3/M4),Homebrew 安装在 /opt/homebrew。安装脚本会自动提示你添加 PATH,务必按照提示操作。

3.2 安装 tmux

brew install tmux

验证:

tmux -V
# tmux 3.5a (or similar)

3.3 安装 Claude Code(如果还没有)

# 确保有 Node.js 18+
node -v

# 如果没有 Node.js
brew install node

# 安装 Claude Code
npm install -g @anthropic-ai/claude-code

验证:

claude --version
一键获取完整项目代码

3.4 一键验证全部就绪

echo "=== Environment Check ===" && \
tmux -V && \
node -v && \
claude --version && \
echo "=== All Good! ==="

看到类似输出就说明一切就绪:

=== Environment Check ===
tmux 3.5a
v22.13.0
1.0.33 (Claude Code)
=== All Good! ===

用tmux运行Claude Code团队(解决你的痛点)

这里是完整流程:

第一步:创建tmux会话

bash

tmux new -s claude-dev

你会进入一个全新的终端环境,底部有绿色状态栏

第二步:在会话中启动Claude Code

bash

# 进入你的项目目录
cd /Users/making/testDome

# 启动Claude Code
claude

第三步:正常使用Claude Code

创建你的AI团队:

text

Create an agent team with 2 teammates to help me think about this project

第四步:断开但保持运行(关键!)

当Claude团队正在工作时(比如遇到429重试),你想离开:

  • 按 Ctrl+b,然后按 d
    终端会显示 [detached],你回到了普通命令行

此时,Claude Code和你的AI团队仍在后台运行,继续重试或执行任务

第五步:重新连接(随时随地)

想查看进度时:

bash

# 先查看有哪些会话
tmux ls

# 重新连接
tmux attach -t claude-dev

瞬间回到之前的界面,看到Claude团队的输出

第六步:任务完成后的清理

bash

# 在会话内退出Claude Code(按Ctrl+C)
# 然后退出tmux会话
exit

# 或在外部直接杀死会话
tmux kill-session -t claude-dev

⚙️ 贴心配置(可选)

创建~/.tmux.conf文件,加入这些配置让体验更好

bash

# 启用鼠标支持(可以用鼠标点击切换窗格)
set -g mouse on

# 增加历史缓冲区到10000行
set -g history-limit 10000

# 修改前缀键为Ctrl+a(很多人喜欢,避免与Vim冲突)
# unbind C-b
# set -g prefix C-a
# bind C-a send-prefix

保存后,在tmux中按Ctrl+b :,输入source-file ~/.tmux.conf重载配置

创建配置文件

touch ~/.tmux.conf

推荐配置

将以下内容写入 ~/.tmux.conf

# ============================================
# tmux config optimized for Claude Code Agent Teams
# ============================================

# --- 基础设置 ---
# 开启鼠标支持(可以用鼠标点击切换 pane、拖拽调整大小、滚轮翻页)
set -g mouse on

# 提高历史记录行数(Agent 输出可能很长)
set -g history-limit 50000

# 减少 Esc 键延迟(默认 500ms,太慢了)
set -sg escape-time 10

# 开启 256 色支持
set -g default-terminal "screen-256color"

# --- 状态栏美化 ---
# 状态栏位置
set -g status-position bottom

# 状态栏颜色
set -g status-style 'bg=#1a1a2e fg=#888888'

# 左侧:session 名称
set -g status-left '#[fg=#4ec9b0,bold] [#S] '
set -g status-left-length 20

# 右侧:时间
set -g status-right '#[fg=#666666] %H:%M '

# 当前 window 高亮
set -g window-status-current-style 'fg=#4ec9b0,bold'

# --- Pane 边框 ---
# 非活动 pane 边框颜色
set -g pane-border-style 'fg=#333333'
# 活动 pane 边框颜色(绿色高亮,方便识别当前 pane)
set -g pane-active-border-style 'fg=#4ec9b0'

# --- 便捷键绑定 ---
# Ctrl+B r 重新加载配置(修改配置后不用重启 tmux)
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"

# Ctrl+B | 垂直分屏(比 % 更直觉)
bind | split-window -h
# Ctrl+B - 水平分屏(比 " 更直觉)
bind - split-window -v

# Alt+Arrow 不用 prefix 直接切换 pane(更快)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

最高频使用的快捷键(建议背下来):

快捷键 功能 使用场景
Ctrl+B d Detach(分离) 让 Agent 们在后台继续工作
Ctrl+B ↑↓←→ 切换 Pane 在 Lead 和 Teammates 之间切换
Ctrl+B z Zoom Pane 放大查看某个 Teammate 的输出
Ctrl+B [ 滚动模式 查看 Teammate 的历史输出
Ctrl+B " 水平分屏 手动创建新 Pane
Ctrl+B % 垂直分屏 手动创建新 Pane
Ctrl+B c 新建 Window 创建新标签页(如监控用)
Ctrl+B n/p 切换 Window 在标签页间切换
Ctrl+B x 关闭 Pane 清理不需要的 Pane
记忆技巧:d=detach, z=zoom, [=看(scroll), "=横线(水平分), %=竖线(垂直分)

image.png

相关命令

tmux new -s claude-dev

# 进入你的项目目录 
cd /Users/making/testDome 

# 启动Claude Code 
claude

Create an agent team with 2 teammates to help me think about this project

# 先查看有哪些会话 
tmux ls 

# 重新连接 
tmux attach -t claude-dev

# 在会话内退出Claude Code(按Ctrl+C) 
# 然后退出tmux会话 
exit 

# 或在外部直接杀死会话 
tmux kill-session -t claude-dev
回退
/rewind

Mac 更新 Claude Code 命令
sudo npm update -g @anthropic-ai/claude-code