[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-9f3170ac-21fe-4250-a745-1308754e2db0":3,"$f6JHyCPFMjih1R_QwY7qgylAvoaLL4pld_FpRm0S1wo4":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"9f3170ac-21fe-4250-a745-1308754e2db0","tmux","专家级别的tmux会话、窗口和面板管理，用于终端多路复用、持久远程工作流和shell脚本自动化。","cat_design_ui","mod_design","sickn33,design","---\nname: tmux\ndescription: \"Expert tmux session, window, and pane management for terminal multiplexing, persistent remote workflows, and shell scripting automation.\"\ncategory: development\nrisk: safe\nsource: community\ndate_added: \"2026-03-28\"\nauthor: kostakost2\ntags: [tmux, terminal, multiplexer, sessions, shell, remote, automation]\ntools: [claude, cursor, gemini]\n---\n\n# tmux — Terminal Multiplexer\n\n## Overview\n\n`tmux` keeps terminal sessions alive across SSH disconnects, splits work across multiple panes, and enables fully scriptable terminal automation. This skill covers session management, window\u002Fpane layout, keybinding patterns, and using `tmux` non-interactively from shell scripts — essential for remote servers, long-running jobs, and automated workflows.\n\n## When to Use This Skill\n\n- Use when setting up or managing persistent terminal sessions on remote servers\n- Use when the user needs to run long-running processes that survive SSH disconnects\n- Use when scripting multi-pane terminal layouts (e.g., logs + shell + editor)\n- Use when automating `tmux` commands from bash scripts without user interaction\n\n## How It Works\n\n`tmux` has three hierarchy levels: **sessions** (top level, survives disconnects), **windows** (tabs within a session), and **panes** (splits within a window). Everything is controllable from outside via `tmux \u003Ccommand>` or from inside via the prefix key (`Ctrl-b` by default).\n\n### Session Management\n\n```bash\n# Create a new named session\ntmux new-session -s work\n\n# Create detached (background) session\ntmux new-session -d -s work\n\n# Create detached session and start a command\ntmux new-session -d -s build -x 220 -y 50 \"make all\"\n\n# Attach to a session\ntmux attach -t work\ntmux attach          # attaches to most recent session\n\n# List all sessions\ntmux list-sessions\ntmux ls\n\n# Detach from inside tmux\n# Prefix + d   (Ctrl-b d)\n\n# Kill a session\ntmux kill-session -t work\n\n# Kill all sessions except the current one\ntmux kill-session -a\n\n# Rename a session from outside\ntmux rename-session -t old-name new-name\n\n# Switch to another session from outside\ntmux switch-client -t other-session\n\n# Check if a session exists (useful in scripts)\ntmux has-session -t work 2>\u002Fdev\u002Fnull && echo \"exists\"\n```\n\n### Window Management\n\n```bash\n# Create a new window in the current session\ntmux new-window -t work -n \"logs\"\n\n# Create a window running a specific command\ntmux new-window -t work:3 -n \"server\" \"python -m http.server 8080\"\n\n# List windows\ntmux list-windows -t work\n\n# Select (switch to) a window\ntmux select-window -t work:logs\ntmux select-window -t work:2       # by index\n\n# Rename a window\ntmux rename-window -t work:2 \"editor\"\n\n# Kill a window\ntmux kill-window -t work:logs\n\n# Move window to a new index\ntmux move-window -s work:3 -t work:1\n\n# From inside tmux:\n# Prefix + c     — new window\n# Prefix + ,     — rename window\n# Prefix + &     — kill window\n# Prefix + n\u002Fp   — next\u002Fprevious window\n# Prefix + 0-9   — switch to window by number\n```\n\n### Pane Management\n\n```bash\n# Split pane vertically (left\u002Fright)\ntmux split-window -h -t work:1\n\n# Split pane horizontally (top\u002Fbottom)\ntmux split-window -v -t work:1\n\n# Split and run a command\ntmux split-window -h -t work:1 \"tail -f \u002Fvar\u002Flog\u002Fsyslog\"\n\n# Select a pane by index\ntmux select-pane -t work:1.0\n\n# Resize panes\ntmux resize-pane -t work:1.0 -R 20   # expand right by 20 cols\ntmux resize-pane -t work:1.0 -D 10   # shrink down by 10 rows\ntmux resize-pane -Z                   # toggle zoom (fullscreen)\n\n# Swap panes\ntmux swap-pane -s work:1.0 -t work:1.1\n\n# Kill a pane\ntmux kill-pane -t work:1.1\n\n# From inside tmux:\n# Prefix + %     — split vertical\n# Prefix + \"     — split horizontal\n# Prefix + arrow — navigate panes\n# Prefix + z     — zoom\u002Funzoom current pane\n# Prefix + x     — kill pane\n# Prefix + {\u002F}   — swap pane with previous\u002Fnext\n```\n\n### Sending Commands to Panes Without Being Attached\n\n```bash\n# Send a command to a specific pane and press Enter\ntmux send-keys -t work:1.0 \"ls -la\" Enter\n\n# Run a command in a background pane without attaching\ntmux send-keys -t work:editor \"vim src\u002Fmain.py\" Enter\n\n# Send Ctrl+C to stop a running process\ntmux send-keys -t work:1.0 C-c\n\n# Send text without pressing Enter (useful for pre-filling prompts)\ntmux send-keys -t work:1.0 \"git commit -m '\"\n\n# Clear a pane\ntmux send-keys -t work:1.0 \"clear\" Enter\n\n# Check what's in a pane (capture its output)\ntmux capture-pane -t work:1.0 -p\ntmux capture-pane -t work:1.0 -p | grep \"ERROR\"\n```\n\n### Scripting a Full Workspace Layout\n\nThis is the most powerful pattern: create a fully configured multi-pane workspace from a single script.\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\n\nSESSION=\"dev\"\n\n# Bail if session already exists\ntmux has-session -t \"$SESSION\" 2>\u002Fdev\u002Fnull && {\n  echo \"Session $SESSION already exists. Attaching...\"\n  tmux attach -t \"$SESSION\"\n  exit 0\n}\n\n# Create session with first window\ntmux new-session -d -s \"$SESSION\" -n \"editor\" -x 220 -y 50\n\n# Window 1: editor + test runner side by side\ntmux send-keys -t \"$SESSION:editor\" \"vim .\" Enter\ntmux split-window -h -t \"$SESSION:editor\"\ntmux send-keys -t \"$SESSION:editor.1\" \"npm test -- --watch\" Enter\ntmux select-pane -t \"$SESSION:editor.0\"\n\n# Window 2: server logs\ntmux new-window -t \"$SESSION\" -n \"server\"\ntmux send-keys -t \"$SESSION:server\" \"docker compose up\" Enter\ntmux split-window -v -t \"$SESSION:server\"\ntmux send-keys -t \"$SESSION:server.1\" \"tail -f logs\u002Fapp.log\" Enter\n\n# Window 3: general shell\ntmux new-window -t \"$SESSION\" -n \"shell\"\n\n# Focus first window\ntmux select-window -t \"$SESSION:editor\"\n\n# Attach\ntmux attach -t \"$SESSION\"\n```\n\n### Configuration (`~\u002F.tmux.conf`)\n\n```bash\n# Change prefix to Ctrl-a (screen-style)\nunbind C-b\nset -g prefix C-a\nbind C-a send-prefix\n\n# Enable mouse support\nset -g mouse on\n\n# Start window\u002Fpane numbering at 1\nset -g base-index 1\nsetw -g pane-base-index 1\n\n# Renumber windows when one is closed\nset -g renumber-windows on\n\n# Increase scrollback buffer\nset -g history-limit 50000\n\n# Use vi keys in copy mode\nsetw -g mode-keys vi\n\n# Faster key repetition\nset -s escape-time 0\n\n# Reload config without restarting\nbind r source-file ~\u002F.tmux.conf \\; display \"Config reloaded\"\n\n# Intuitive splits: | and -\nbind | split-window -h -c \"#{pane_current_path}\"\nbind - split-window -v -c \"#{pane_current_path}\"\n\n# New windows open in current directory\nbind c new-window -c \"#{pane_current_path}\"\n\n# Status bar\nset -g status-right \"#{session_name} | %H:%M %d-%b\"\nset -g status-interval 5\n```\n\n### Copy Mode and Scrollback\n\n```bash\n# Enter copy mode (scroll up through output)\n# Prefix + [\n\n# In vi mode:\n# \u002F to search forward, ? to search backward\n# Space to start selection, Enter to copy\n# q to exit copy mode\n\n# Paste the most recent buffer\n# Prefix + ]\n\n# List paste buffers\ntmux list-buffers\n\n# Show the most recent buffer\ntmux show-buffer\n\n# Save buffer to a file\ntmux save-buffer \u002Ftmp\u002Ftmux-output.txt\n\n# Load a file into a buffer\ntmux load-buffer \u002Ftmp\u002Fdata.txt\n\n# Pipe pane output to a command\ntmux pipe-pane -t work:1.0 \"cat >> ~\u002Fsession.log\"\n```\n\n### Practical Automation Patterns\n\n```bash\n# Idempotent session: create or attach\nensure_session() {\n  local name=\"$1\"\n  tmux has-session -t \"$name\" 2>\u002Fdev\u002Fnull \\\n    || tmux new-session -d -s \"$name\"\n  tmux attach -t \"$name\"\n}\n\n# Run a command in a new background window and tail its output\nrun_bg() {\n  local session=\"${1:-main}\" cmd=\"${*:2}\"\n  tmux new-window -t \"$session\" -n \"bg-$$\"\n  tmux send-keys -t \"$session:bg-$$\" \"$cmd\" Enter\n}\n\n# Wait for a pane to produce specific output (polling)\nwait_for_output() {\n  local target=\"$1\" pattern=\"$2\" timeout=\"${3:-30}\"\n  local elapsed=0\n  while (( elapsed \u003C timeout )); do\n    tmux capture-pane -t \"$target\" -p | grep -q \"$pattern\" && return 0\n    sleep 1\n    (( elapsed++ ))\n  done\n  return 1\n}\n\n# Kill all background windows matching a name prefix\nkill_bg_windows() {\n  local session=\"$1\" prefix=\"${2:-bg-}\"\n  tmux list-windows -t \"$session\" -F \"#W\" \\\n    | grep \"^${prefix}\" \\\n    | while read -r win; do\n        tmux kill-window -t \"${session}:${win}\"\n      done\n}\n```\n\n### Remote and SSH Workflows\n\n```bash\n# SSH and immediately attach to an existing session\nssh user@host -t \"tmux attach -t work || tmux new-session -s work\"\n\n# Run a command on remote host inside a tmux session (fire and forget)\nssh user@host \"tmux new-session -d -s deploy 'bash \u002Fopt\u002Fdeploy.sh'\"\n\n# Watch the remote session output from another terminal\nssh user@host -t \"tmux attach -t deploy -r\"  # read-only attach\n\n# Pair programming: share a session (both users attach to the same session)\n# User 1:\ntmux new-session -s shared\n# User 2 (same server):\ntmux attach -t shared\n```\n\n## Best Practices\n\n- Always name sessions (`-s name`) in scripts — unnamed sessions are hard to target reliably\n- Use `tmux has-session -t name 2>\u002Fdev\u002Fnull` before creating to make scripts idempotent\n- Set `-x` and `-y` when creating detached sessions to give panes a proper size for commands that check terminal dimensions\n- Use `send-keys ... Enter` for automation rather than piping stdin — it works even when the target pane is running an interactive program\n- Keep `~\u002F.tmux.conf` in version control for reproducibility across machines\n- Prefer `bind -n` for bindings that don't need the prefix, but only for keys that don't conflict with application shortcuts\n\n## Security & Safety Notes\n\n- `send-keys` executes commands in a pane without confirmation — verify the target (`-t session:window.pane`) before use in scripts to avoid sending keystrokes to the wrong pane\n- Read-only attach (`-r`) is appropriate when sharing sessions with others to prevent accidental input\n- Avoid storing secrets in tmux window\u002Fpane titles or environment variables exported into sessions on shared machines\n\n## Common Pitfalls\n\n- **Problem:** `tmux` commands from a script fail with \"no server running\"\n  **Solution:** Start the server first with `tmux start-server`, or create a detached session before running other commands.\n\n- **Problem:** Pane size is 0x0 when creating a detached session\n  **Solution:** Pass explicit dimensions: `tmux new-session -d -s name -x 200 -y 50`.\n\n- **Problem:** `send-keys` types the text but doesn't run the command\n  **Solution:** Ensure you pass `Enter` (capital E) as a second argument: `tmux send-keys -t target \"cmd\" Enter`.\n\n- **Problem:** Script creates a duplicate session each run\n  **Solution:** Guard with `tmux has-session -t name 2>\u002Fdev\u002Fnull || tmux new-session -d -s name`.\n\n- **Problem:** Copy-mode selection doesn't work as expected\n  **Solution:** Confirm `mode-keys vi` or `mode-keys emacs` is set to match your preference in `~\u002F.tmux.conf`.\n\n## Related Skills\n\n- `@bash-pro` — Writing the shell scripts that orchestrate tmux sessions\n- `@bash-linux` — General Linux terminal patterns used inside tmux panes\n- `@ssh` — Combining tmux with SSH for persistent remote workflows\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,87,1538,"2026-05-16 13:44:30",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"设计创意","design","mdi-palette-outline","UI 设计、生成艺术、品牌视觉等创意 Skill",3,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"UI 设计","ui-design","mdi-monitor-cellphone","界面设计、交互规范、设计系统",1,36,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"5041c1d0-5601-46a1-b4d7-99d0f63777de","1.0.0","tmux.zip",4415,"uploads\u002Fskills\u002F9f3170ac-21fe-4250-a745-1308754e2db0\u002Ftmux.zip","2db5186178d524e484b1f56ea9cae60672f9494dccf67400219053a075e30288","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":11246}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]