feat: add --tmux/-t option to run agents in attachable tmux sessions

Wraps the backend in 'tmux new-session -A' with a per-backend, per-directory
session name, so agent sessions survive SSH drops and re-running the same
command reattaches. Falls back to a direct run when already inside tmux,
and errors clearly when tmux is not installed.
This commit is contained in:
Zhengshou Lai
2026-07-15 20:03:28 +08:00
parent 20e22eafd4
commit 5c3f90e910
3 changed files with 148 additions and 5 deletions
+6
View File
@@ -101,8 +101,14 @@ mycodex -r <session-id>
mycodex resume <session-id>
myhermes
myhermes --resume <session-id>
# tmux 防断线(SSH 远程场景)
myclaude -t # 在 tmux 会话中启动,掉线/合盖不丢会话
myclaude -t -r <session-id> # 与透传参数任意组合
```
`--tmux` / `-t` 会把 agent 包进一个**按后端 + 目录命名**的 tmux 会话(如 `myclaude-myagents-a1b2c3`):重复执行同一命令即重新接入(`tmux new-session -A` 语义),`C-b d` 脱离。已在 tmux 内时自动退化为直接运行;未安装 tmux 会给出明确提示。
各后端原生参数会原样透传。例如 Kimi npm 版支持 `--session``-c`continue)、`-y`yolo)等,Codex 支持 `resume``continue``exec` 等子命令;`mycodex` 还会将 `-r` / `--resume` 映射为 `codex resume`,与 `myclaude` 体验保持一致。Hermes 默认带 `--yolo` 启动,支持 `--resume <id>` / `--continue` 透传;其 sessions 存在全局 SQLite`~/.hermes/state.db`),不区分工作目录,`-l` 列出最近 20 条。
## 配置