tmux 美化配置 & Claude Code 搭配指南

tmux 美化配置 & Claude Code 搭配指南


第一部分:tmux 美化配置

1. 安装前置依赖

1
2
3
4
5
6
7
8
9
10
# macOS
brew install tmux

# Ubuntu / Debian
sudo apt install tmux

# 安装 Nerd Font(图标显示必备)
# 推荐:JetBrainsMono Nerd Font / FiraCode Nerd Font
# 下载地址:https://www.nerdfonts.com/font-downloads
# 安装后在终端 App 设置中选中该字体

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
# ============================================================================
# tmux 配置 — 美化 + AI 开发优化
# ============================================================================

# ─── 基础设置 ──────────────────────────────────────────────────
set -g default-terminal "tmux-256color" # 256 色支持
set -as terminal-overrides ",*:RGB" # 真彩色
set -sg escape-time 0 # 无 Escape 延迟
set -g history-limit 50000 # 大滚动缓冲区(AI 输出很长)
set -g mouse on # 鼠标支持
set -g base-index 1 # 窗口从 1 开始编号
setw -g pane-base-index 1 # 面板从 1 开始编号
set -g renumber-windows on # 关闭窗口后自动重排序号
set -g focus-events on # 传递焦点事件
set -g status-interval 5 # 状态栏刷新间隔
setw -g aggressive-resize on # 自适应面板大小

# ─── 更改前缀键(可选,推荐 Ctrl+A) ──────────────────────────
# 默认是 Ctrl+B,很多人觉得不顺手
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# ─── 更直观的分屏快捷键 ────────────────────────────────────────
bind | split-window -h -c "#{pane_current_path}" # 竖向分屏
bind - split-window -v -c "#{pane_current_path}" # 横向分屏
unbind '"'
unbind %

# ─── Vim 风格面板导航 ──────────────────────────────────────────
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# ─── 面板大小调整(Shift + 方向) ──────────────────────────────
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# ─── 新窗口保留当前路径 ───────────────────────────────────────
bind c new-window -c "#{pane_current_path}"

# ─── 快速重载配置 ─────────────────────────────────────────────
bind r source-file ~/.tmux.conf \; display "配置已重载 ✓"

# ─── Catppuccin 主题配置 ──────────────────────────────────────
set -g @catppuccin_flavor "mocha" # 可选: latte, frappe, macchiato, mocha
set -g @catppuccin_window_status_style "rounded" # 可选: basic, rounded, slanted, none

# ─── 状态栏模块 ──────────────────────────────────────────────
set -g status-right-length 100
set -g status-left-length 100
set -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' # Catppuccin 主题
set -g @plugin 'tmux-plugins/tmux-resurrect' # 会话持久化
set -g @plugin 'tmux-plugins/tmux-continuum' # 自动保存/恢复
set -g @plugin 'tmux-plugins/tmux-cpu' # CPU 信息模块
set -g @plugin 'tmux-plugins/tmux-yank' # 系统剪贴板复制

# ─── 会话持久化配置 ───────────────────────────────────────────
set -g @continuum-restore 'on' # 启动时自动恢复
set -g @resurrect-capture-pane-contents 'on' # 保存面板内容

# ─── 初始化 TPM(必须放在最后一行) ──────────────────────────
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 会话
tmux new -s myproject

# 在会话中启动 Claude Code
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
# 创建会话并启动 Claude Code
tmux new -s dev

# 右侧分屏 → 运行开发服务器
Ctrl+A, |
npm run dev

# 回到左侧
Ctrl+A, h

# 下方分屏 → 查看 git 状态
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
# 在 ~/.tmux.conf 中添加
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
// ~/.claude.json
{
"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
# 创建 worktree
git worktree add ../myproject--feat-auth feat/auth
git worktree add ../myproject--fix-bug fix/bug-123

# 每个 worktree 一个 tmux 窗口 + 一个 Claude Code 实例
tmux new-window -n "feat-auth" -c "../myproject--feat-auth"
# 在新窗口里启动 claude

tmux new-window -n "fix-bug" -c "../myproject--fix-bug"
# 在新窗口里启动 claude

三个 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
退出翻页模式 qCtrl+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 最需要的基础设施。


tmux 美化配置 & Claude Code 搭配指南
https://blog.wenxin.site/2026/04/01/tmux_and_claude_code/
作者
HarryMa
发布于
2026年4月1日
许可协议