本文最后更新于:2026-04-07T20:31:27+08:00
tmux 美化配置 & Claude Code 搭配指南
第一部分:tmux 美化配置 1. 安装前置依赖 1 2 3 4 5 6 7 8 9 10 brew install tmuxsudo apt install tmux
2. 安装 TPM(tmux 插件管理器) 1 git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
3. 完整配置文件 ~/.tmux.conf 以下是一份兼顾美观 和 Claude Code 开发体验 的配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 set -g default-terminal "tmux-256color" set -as terminal-overrides ",*:RGB" set -sg escape-time 0 set -g history-limit 50000 set -g mouse on set -g base-index 1 setw -g pane-base-index 1 set -g renumber-windows on set -g focus-events on set -g status-interval 5 setw -g aggressive-resize on unbind C-bset -g prefix C-abind C-a send-prefixbind | split-window -h -c "#{pane_current_path}" bind - split-window -v -c "#{pane_current_path}" unbind '"' unbind %bind h select-pane -Lbind j select-pane -Dbind k select-pane -Ubind l select-pane -Rbind -r H resize-pane -L 5bind -r J resize-pane -D 5bind -r K resize-pane -U 5bind -r L resize-pane -R 5bind c new-window -c "#{pane_current_path}" bind r source-file ~/.tmux.conf \; display "配置已重载 ✓" set -g @catppuccin_flavor "mocha" set -g @catppuccin_window_status_style "rounded" set -g status-right-length 100set -g status-left-length 100set -g status-left "" set -g status-right "#{E:@catppuccin_status_application}" set -agF status-right "#{E:@catppuccin_status_cpu}" set -ag status-right "#{E:@catppuccin_status_session}" set -ag status-right "#{E:@catppuccin_status_uptime}" set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'catppuccin/tmux#v2.1.3' set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' set -g @plugin 'tmux-plugins/tmux-cpu' set -g @plugin 'tmux-plugins/tmux-yank' set -g @continuum-restore 'on' set -g @resurrect-capture-pane-contents 'on' run '~/.tmux/plugins/tpm/tpm'
4. 安装插件 保存配置后,在 tmux 中按 Ctrl+A(或你的前缀键)再按 I(大写),TPM 会自动下载并安装所有插件。
5. 其他热门主题可选
主题
风格
安装
Catppuccin
柔和粉彩
catppuccin/tmux
Dracula
暗色紫调
dracula/tmux
Nord
冷色极简
nordtheme/tmux
Tokyo Night
赛博朋克暗色
janoamaral/tokyo-night-tmux
Gruvbox
暖色复古
egel/tmux-gruvbox
第二部分:tmux × Claude Code 搭配用法 1. 基础工作流:创建专属开发会话 1 2 3 4 5 tmux new -s myproject claude
从此以后,即使关闭终端、SSH 断开,你的 Claude Code 对话和所有运行中的进程都不会丢失。
1 2 3 4 5 Ctrl+A, d tmux attach -t myproject
2. 推荐分屏布局 一个典型的 vibe coding 布局:
1 2 3 4 5 6 7 8 9 10 ┌─────────────────────────┬──────────────────┐ │ │ │ │ Claude Code │ Dev Server │ │ (主面板) │ (日志输出) │ │ │ │ │ │ │ ├─────────────────────────┼──────────────────┤ │ Git / 文件浏览 │ 测试输出 │ │ │ │ └─────────────────────────┴──────────────────┘
快速搭建方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 tmux new -s dev Ctrl+A, | npm run dev Ctrl+A, h Ctrl+A, - git log --oneline --graph Ctrl+A, l Ctrl+A, - npm test --watch
3. Claude Code 能感知 tmux Claude Code 理解 tmux 的概念。你可以直接告诉它:
“看看 tmux 第 2 个窗口第 0 个面板里的服务器报错日志,帮我修复”
Claude Code 可以用 tmux 子命令读取其他面板的内容、翻阅滚动缓冲区,甚至向其他面板发送命令。
在 CLAUDE.md 中注明你的 tmux 布局会很有帮助:
1 2 3 4 5 ## 开发环境 - 使用单个 tmux 会话,前缀键为 Ctrl+A- 窗口 1: Claude Code(面板 0)+ 开发服务器日志(面板 1)- 窗口 2: 测试运行器- 开发服务器运行在 localhost:3000
4. tmux 弹出窗口运行 Claude Code(进阶) 这个技巧来自开发者 Takuya(devaslife),把 Claude Code 放在 tmux 弹出窗口中,按快捷键呼出/隐藏,不会打断主要工作流:
1 2 3 4 5 6 7 bind -r y run-shell '\ SESSION="claude-$(echo #{pane_current_path} | md5sum | cut -c1-8)"; \ tmux has-session -t "$SESSION" 2>/dev/null || \ tmux new-session -d -s "$SESSION" -c "#{pane_current_path}" "claude"; \ tmux display-popup -w80% -h80% \ -E "tmux attach-session -t $SESSION"'
效果:按 Ctrl+A, y 弹出 Claude Code,关掉弹窗后会话继续在后台运行,再次按快捷键恢复。
5. Agent Teams(多 Agent 协作) Claude Code 的 Agent Teams 功能原生支持 tmux 分屏,每个 teammate agent 会在独立的 tmux 面板中运行:
1 2 3 4 5 6 7 { "env" : { "CLAUDE_CODE_SPAWN_BACKEND" : "tmux" } , "teammateMode" : "tmux" }
启用后,当你让 Claude Code 分配任务给队友时,每个 agent 都会出现在自己的面板中,你可以实时看到它们各自在干什么。
6. Git Worktrees + tmux:并行多任务 这是高级玩家的终极工作流——一个项目同时推进多个功能分支:
1 2 3 4 5 6 7 8 9 10 git worktree add ../myproject--feat-auth feat/auth git worktree add ../myproject--fix-bug fix/bug-123 tmux new-window -n "feat-auth" -c "../myproject--feat-auth" tmux new-window -n "fix-bug" -c "../myproject--fix-bug"
三个 Claude Code 实例分别在三个分支上工作,互不干扰,用 Ctrl+A, 1/2/3 切换查看进度。
7. 远程 / 移动端 Vibe Coding tmux 让你可以从任何设备继续开发:
1 2 3 4 5 6 7 8 9 10 11 笔记本 / 手机 / iPad │ ▼ SSH / Mosh │ ▼ 远程服务器 (tmux 会话始终运行) │ ├── Claude Code (继续对话) ├── Dev Server (一直在跑) └── Tests (随时查看)
推荐工具:iPad 用 Blink Shell (支持 Mosh),iPhone 用 Termius 。Mosh 比 SSH 更耐断连,配合 tmux 体验极佳。
8. tmux 内浏览 Claude Code 长输出 Claude Code 的输出经常很长。在 tmux 里你不需要额外的翻页功能:
操作
快捷键
进入复制/翻页模式
Ctrl+A, [
向上翻页
Ctrl+U
向下翻页
Ctrl+D
逐行滚动
j / k
搜索
/(向前)或 ?(向后)
下一个/上一个匹配
n / N
退出翻页模式
q 或 Ctrl+C
导出面板全部内容
tmux capture-pane -p -S -10000
速查:一个完整的日常 Vibe Coding 流程 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 早上开工 └─ tmux attach - t myproject ← 恢复昨天的一切 规划任务 └─ Claude Code: /init 或 /todo ← 让 AI 帮你规划今天的工作 开发 └─ 主面板: Claude Code ← 用自然语言描述需求 └─ 右侧面板: npm run dev ← 实时看效果 └─ 下方面板: 测试 / git ← 随时验证 Code Review └─ Claude Code: /review ← AI 审查代码 └─ 另一面板: git diff ← 对照查看 部署 / 长任务 └─ Claude Code 启动部署 └─ Ctrl+ A, d ← 断开去开会 └─ 回来后 tmux attach ← 部署结果等着你 下班 └─ 直接关终端,tmux 会话留着明天继续
提示 :以上所有配置和技巧可以根据个人习惯调整。最重要的是让 tmux 成为你和 AI agent 之间的”粘合剂”——持久化、可视化、多任务并行,这正是 vibe coding 最需要的基础设施。