内容
# zellij-mcp
**适用于Claude Code的终端编排。 57种工具。 基于标签的工作区。**
[](LICENSE)
[](https://zellij.dev)
[](https://docs.anthropic.com/en/docs/claude-code)
[](https://genomewalker.github.io/zellij-mcp/)
[](https://github.com/genomewalker/zellij-mcp/releases)
---
## 为什么选择zellij-mcp?
**无焦点窗格控制。** 原生Zellij插件写入窗格而不会夺取焦点。您的光标保持在原位,而Claude在后台工作。
**Claude窗格保护。** 自动检测代理的窗格并防止意外关闭。不会在任务中途自我终止。
**基于标签的工作区。** 代理工作被组织到专用标签中(例如“代理”,“分析”,“HPC”)。切换标签以观察代理进度,或停留在自己的标签中。
**命名窗格定位。** 按名称而非仅按焦点定位窗格。 `create_named_pane("worker")`、`read_pane("worker")`、`run_in_pane("worker", "make test")`。
**完整的终端控制。** 57种MCP工具用于窗格、标签、输出监控、REPL交互、SSH连接和HPC作业管理。
---
## 安装
### 通过Claude Code插件系统(推荐)
```
/plugin genomewalker/zellij-mcp
```
然后 **重启Claude Code**。
### 手动安装
```bash
curl -fsSL https://raw.githubusercontent.com/genomewalker/zellij-mcp/main/scripts/install.sh | bash
```
要更新:`cd ~/.local/share/zellij-mcp && git pull && ./scripts/install.sh`
---
## 快速入门
```
"创建一个名为worker的窗格"
"在worker中运行npm test"
"等待测试完成"
"显示结果"
```
---
## 主要功能
### 基于标签的工作区
代理操作在会话中组织到专用标签中:
```python
create_named_pane(name="analysis", command="ipython3", tab="work")
# → 在“work”标签中创建,切换标签以观察进度
```
### 命名窗格操作
按名称跨标签和会话定位窗格:
```python
create_named_pane(name="tests", command="bash", tab="dev")
run_in_pane(pane_name="tests", command="pytest -v")
wait_for_output(pane_name="tests", pattern="passed|failed")
read_pane(pane_name="tests")
```
### 输出监控
```python
wait_for_output(pane_name="worker", pattern=r"Done|Error", timeout=300)
wait_for_idle(pane_name="worker", stable_seconds=3)
tail_pane(pane_name="worker") # 获取自上次读取以来的新输出
```
### REPL交互
```python
create_named_pane(name="ipython", command="ipython3")
repl_execute(pane_name="ipython", code="import pandas as pd\ndf.describe()")
repl_interrupt(pane_name="ipython") # Ctrl+C
```
### SSH和HPC工作流
```python
ssh_connect(name="hpc", host="user@cluster.edu")
ssh_run(name="hpc", command="squeue -u $USER")
job_submit(ssh_name="hpc", script="analysis.sh", scheduler="slurm")
job_status(job_id="12345")
```
### 代理生成
```python
spawn_agents(agents=[
{"name": "researcher", "task": "Find API documentation"},
{"name": "implementer", "task": "Write the integration"}
])
list_spawned_agents()
agent_output(name="researcher")
```
---
## 工具参考
### 窗格管理(12种工具)
`new_pane` `close_pane` `focus_pane` `focus_next_pane` `focus_previous_pane` `move_pane` `move_pane_backwards` `resize_pane` `rename_pane` `toggle_floating` `toggle_fullscreen` `toggle_embed_or_floating`
### 命名窗格(7种工具)
`create_named_pane` `destroy_named_pane` `list_named_panes` `focus_pane_by_name` `read_pane` `write_to_pane` `run_in_pane`
### 监控(5种工具)
`wait_for_output` `wait_for_idle` `tail_pane` `search_pane` `send_keys`
### REPL(2种工具)
`repl_execute` `repl_interrupt`
### SSH和HPC(4种工具)
`ssh_connect` `ssh_run` `job_submit` `job_status`
### 标签管理(8种工具)
`new_tab` `close_tab` `focus_tab` `move_tab` `rename_tab` `query_tab_names` `go_to_next_tab` `go_to_previous_tab`
### 会话和布局(6种工具)
`list_sessions` `list_panes` `session_info` `dump_layout` `swap_layout` `session_map`
### 工作区和代理管理(5种工具)
`agent_session` `spawn_agents` `list_spawned_agents` `agent_output` `stop_agent`
### 其他(8种工具)
`write_chars` `clear_pane` `scroll` `edit_scrollback` `switch_mode` `stack_panes` `launch_plugin` `pipe`
---
## 跨会话控制
所有工具都支持`session`参数以定位其他Zellij会话:
```python
list_sessions()
read_pane(session="other-session", pane_name="worker")
run_in_pane(session="dev", pane_name="tests", command="make check")
```
---
## 与prism.nvim结合使用
完整开发工作流:
```
1. zellij-mcp: "在浮动窗格中打开nvim"
2. prism.nvim: "跳转到第42行,添加错误处理"
3. zellij-mcp: "在下面的窗格中运行测试"
4. zellij-mcp: "等待测试并显示结果"
```
---
## 窗格桥插件
安装程序包括一个原生Zellij插件(`zellij-pane-bridge.wasm`),该插件启用:
- **无焦点写入** - 发送文本到任意窗格而不会更改焦点
- **Claude窗格保护** - 自动检测并保护代理的窗格免于关闭
- **直接窗格控制** - 按ID关闭、隐藏、显示窗格
MCP服务器在可用时自动使用该插件,如果未安装,则回退到基于焦点的操作。
---
## 要求
- [Zellij](https://zellij.dev/documentation/installation) 0.40+
- Python 3.8+,带有`mcp`包
- Claude Code
---
MIT · [网站](https://genomewalker.github.io/zellij-mcp/) · [GitHub](https://github.com/genomewalker/zellij-mcp) · [问题](https://github.com/genomewalker/zellij-mcp/issues)