terminal-session
tmux 持久化终端会话控制。通过向 tmux 发送按键、读取输出,管理 Claude Code、Codex、SSH 等长时间运行的交互式进程。跨多轮对话保持进程状态。需预装 tmux(Linux/macOS 默认提供;Windows 用户需 WSL2)。
Best use case
terminal-session is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
tmux 持久化终端会话控制。通过向 tmux 发送按键、读取输出,管理 Claude Code、Codex、SSH 等长时间运行的交互式进程。跨多轮对话保持进程状态。需预装 tmux(Linux/macOS 默认提供;Windows 用户需 WSL2)。
Teams using terminal-session should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/terminal-session/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How terminal-session Compares
| Feature / Agent | terminal-session | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
tmux 持久化终端会话控制。通过向 tmux 发送按键、读取输出,管理 Claude Code、Codex、SSH 等长时间运行的交互式进程。跨多轮对话保持进程状态。需预装 tmux(Linux/macOS 默认提供;Windows 用户需 WSL2)。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 终端会话控制(tmux) > 本技能完全通过已有的 `exec` 工具调用系统级 `tmux` CLI,无需任何新工具或依赖。 --- ## 使用时机 ### ✅ 应当使用本技能的场景 - 监控 Claude Code / Codex 在 tmux 中的运行状态 - 向交互式终端程序发送输入(回答提示、选择选项) - 读取 tmux 中长时间运行进程的输出 - 跨多轮对话操作同一个后台进程 - 检查已有 tmux 会话中的后台任务进度 ### ❌ 不应使用本技能的场景 - **一次性 shell 命令**(ls、grep、python script.py 等)→ 直接用 `exec` - **启动新后台进程**(无需交互)→ 用 `exec` 执行命令(末尾加 `&`) - **非交互式脚本** → 直接用 `exec` - **进程不在 tmux 中** → 无法操作 - **创建新 tmux 会话** → 用 `exec` 执行 `tmux new-session`(本技能专注于操控已有会话) - **Windows 原生(无 WSL)** → tmux 不可用,告知用户需要 WSL2 --- ## 常用会话名称约定 | 会话名 | 用途 | |--------|------| | `shared` | 主交互会话 | | `worker-2` ~ `worker-8` | 并行工作会话 | | `ssh_prod` | 生产环境 SSH | | `claude_task` | Claude Code 任务会话 | --- ## 常用命令 ### 列出会话 ```bash tmux list-sessions tmux ls ``` ### 读取输出 ```bash # 读取当前屏幕最后 20 行 tmux capture-pane -t shared -p | tail -20 # 读取完整滚动历史 tmux capture-pane -t shared -p -S - # 读取指定窗口/面板(格式: 会话:窗口.面板) tmux capture-pane -t shared:0.0 -p ``` ### 发送输入 ```bash # 发送文本(不回车) tmux send-keys -t shared "hello" # 发送文本并回车 tmux send-keys -t shared "ls -la" Enter # 特殊按键 tmux send-keys -t shared Enter # 回车 tmux send-keys -t shared Escape # Esc tmux send-keys -t shared C-c # Ctrl+C(中断) tmux send-keys -t shared C-d # Ctrl+D(EOF / 退出 REPL) tmux send-keys -t shared C-z # Ctrl+Z(挂起) ``` ### 窗口 / 面板导航 ```bash # 切换窗口 tmux select-window -t shared:0 # 切换面板 tmux select-pane -t shared:0.1 # 列出会话所有窗口 tmux list-windows -t shared ``` ### 会话管理 ```bash # 创建新会话(后台运行) tmux new-session -d -s newsession # 创建并直接启动程序 tmux new-session -d -s claude_task 'claude-code /workspace/project' # 关闭会话 tmux kill-session -t sessionname # 重命名会话 tmux rename-session -t old new # 检查会话是否存在 tmux has-session -t my_session 2>/dev/null && echo "存在" || echo "不存在" ``` --- ## 安全发送输入(重要) 对于交互式 TUI 程序(Claude Code、Codex 等),**必须将文本和 Enter 拆开发送**,避免多行粘贴导致的异常: ```bash # ✅ 正确:先发文本,短暂等待,再发 Enter tmux send-keys -t shared -l -- "Please apply the patch in src/foo.ts" sleep 0.1 tmux send-keys -t shared Enter # ❌ 错误:一次性发送可能引发多行粘贴问题 tmux send-keys -t shared "Please apply the patch in src/foo.ts" Enter ``` --- ## Claude Code 会话操作模式 ### 检查会话是否在等待输入 ```bash # 查找常见提示符(❯、Yes/No、proceed、permission 等) tmux capture-pane -t worker-3 -p | tail -10 | grep -E "❯|Yes.*No|proceed|permission|approve" ``` ### 确认 Claude Code 提示 ```bash # 发送 y 确认 tmux send-keys -t worker-3 'y' Enter # 选择编号选项 tmux send-keys -t worker-3 '2' Enter ``` ### 向会话发送任务 ```bash tmux send-keys -t worker-4 -l -- "Fix the authentication bug in auth.js" sleep 0.1 tmux send-keys -t worker-4 Enter ``` ### 批量检查所有工作会话状态 ```bash for s in shared worker-2 worker-3 worker-4 worker-5 worker-6 worker-7 worker-8; do echo "=== $s ===" tmux capture-pane -t $s -p 2>/dev/null | tail -5 done ``` --- ## 完整工作流示例 ### 启动 Claude Code 并交互 ```bash # 1. 创建会话并启动 tmux new-session -d -s coder 'claude-code /workspace' # 2. 等待启动(约 3 秒),读取初始状态 sleep 3 && tmux capture-pane -t coder -p | tail -20 # 3. 安全发送任务指令 tmux send-keys -t coder -l -- "Refactor the auth module to use JWT tokens" sleep 0.1 tmux send-keys -t coder Enter # 4. 等待执行,周期读取输出 sleep 10 && tmux capture-pane -t coder -p -S -100 # 5. 如有确认提示,回答 y tmux capture-pane -t coder -p | tail -5 | grep -q "proceed" && \ tmux send-keys -t coder 'y' Enter # 6. 完成后关闭会话 tmux kill-session -t coder ``` ### SSH 远程操作 ```bash # 建立连接(禁用首次连接确认) tmux new-session -d -s ssh_prod 'ssh -o StrictHostKeyChecking=no user@10.0.0.1' # 等待登录完成 sleep 2 && tmux capture-pane -t ssh_prod -p | tail -5 # 执行远程命令 tmux send-keys -t ssh_prod 'df -h && free -m' Enter sleep 2 && tmux capture-pane -t ssh_prod -p | tail -20 ``` --- ## 注意事项 - `capture-pane` 必须加 `-p` 才会输出到 stdout(脚本中必须) - `-S -` 读取完整滚动历史;`-S -200` 读取最近 200 行 - 目标格式:`会话:窗口.面板`(如 `shared:0.0`) - tmux 会话在 SSH 断开后依然存活,无需重新连接 - 任务完成后务必 `kill-session`,防止僵尸进程堆积 - `exec` 工具的安全策略仍然有效,危险命令仍会被拦截 # https://skills.sh/steipete/clawdis/tmux
Related Skills
checking-session-security
This skill enables Claude to check session security implementations within a codebase. It analyzes session management practices to identify potential vulnerabilities. Use this skill when a user requests to "check session security", "audit session handling", "review session implementation", or asks about "session security best practices" in their code. It helps identify issues like insecure session IDs, lack of proper session expiration, or insufficient protection against session fixation attacks. This skill leverages the session-security-checker plugin. Activates when you request "checking session security" functionality.
session-logs
Search your complete conversation history stored in session JSONL files. Use this when a user references older/parent conversations or asks what was said before.
session-handoff
Creates comprehensive handoff documents for seamless AI agent session transfers. Triggered when: (1) user requests handoff/memory/context save, (2) context window approaches capacity, (3) major task milestone completed, (4) work session ending, (5) user says 'save state', 'create handoff', 'I need to pause', 'context is getting full', (6) resuming work with 'load handoff', 'resume from', 'continue where we left off'. Proactively suggests handoffs after substantial work (multiple file edits, complex debugging, architecture decisions). Solves long-running agent context exhaustion by enabling fresh agents to continue with zero ambiguity.
spawn-terminal
Spawn a new terminal window to run CLI commands (ffmpeg, curl, python, etc.). Use for non-AI command execution.
chronicle-session-documenter
Document AI-assisted development sessions to Obsidian vault using Chronicle data. Works with MCP (fastest) or CLI commands (portable). Use when completing a coding session, creating development logs, or maintaining a knowledge base of past work. Automatically creates structured notes with metadata, summaries, and wikilinks.
session-memory
Manages cross-session learning and memory persistence. Use when user mentions 前回何をした, 履歴, 過去の作業, セッション記録, continue from before, session history. Do NOT load for: 実装作業, レビュー, 一時的な情報.
session-init
Initializes session with environment check and task status overview. Use when user mentions セッション開始, 作業開始, 状況確認, what should I work on, start session. Do NOT load for: 実装作業, レビュー, セッション途中の作業.
session-template
Apply task-specific templates to AI session plans using ai-update-plan. Use when starting a new task to load appropriate plan structure (feature, bugfix, refactor, documentation, security).
session-intelligence-harvester
This skill should be used after productive sessions to extract learnings and route them to appropriate Reusable Intelligence Infrastructure (RII) components. Use when corrections were made, format drift was fixed, new patterns emerged, or the user explicitly asks to "harvest learnings" or "capture session intelligence". Transforms one-time fixes into permanent organizational knowledge by implementing updates across multiple files.
terminal-title
This skill should be used to update terminal window title with context. Triggers automatically at session start via hook. Also triggers on topic changes during conversation (debugging to docs, frontend to backend). Updates title with emoji + project + current topic.
Warp — Modern Terminal & Workflow Automation
## Overview
OpenAI Codex CLI — AI Coding Agent in Your Terminal
You are an expert in OpenAI's Codex CLI, the open-source terminal-based coding agent that reads your codebase, generates and edits code, runs shell commands, and applies changes — all within your terminal. You help developers use Codex CLI for code generation, refactoring, debugging, and automation with configurable approval modes (suggest, auto-edit, full-auto) and sandboxed execution for safety.