sandgardenhq/sgai/run-long-running-processes-in-tmux

Claude Code and agent skill by sandgardenhq/sgai

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Guide for using tmux to manage detached sessions for long-running processes, including lifecycle management, cleanup, startup, verification, and output capture; When you need to run servers or long-running commands in the background, send commands to them, capture output, handle TTY requirements, or manage session lifecycle with error handling

Install

npx vskill@latest install sandgardenhq/sgai/run-long-running-processes-in-tmux

SKILL.md

Run Long Running Processes in Tmux

Overview

Tmux allows running processes in detached sessions, providing pseudo-terminals for processes requiring TTY, and tools to interact with them without attaching. Enhanced with complete session lifecycle management including cleanup, startup verification, and output capture.

When to Use

Use when:

  • Running servers or daemons in background
  • Processes need TTY but you want detached execution
  • Need to send commands or signals to running processes
  • Capturing output from detached sessions
  • Managing long-running tasks in automation scripts
  • Testing server processes or managing background services
  • Need session cleanup and conflict resolution

Core Pattern

  1. Cleanup existing sessions: tmux kill-session -t name 2>/dev/null || true
  2. Start detached session: tmux new-session -d -s name "command"
  3. Verify startup: tmux capture-pane -t name -S - -p | grep -q "expected_output"
  4. Interact: tmux send-keys -t name "command" C-m
  5. Capture: tmux capture-pane -t name -S - -p > file
  6. Monitor: tmux attach -t name (when needed)

Quick Reference

CommandPurposeExample
kill-session -t name 2>/dev/nulltrueCleanup existingtmux kill-session -t server 2>/dev/nulltrue
new-session -d -s name "cmd"Start detachedtmux new-session -d -s server "python -m http.server"
capture-pane -t name -S - -pVerify startuptmux capture-pane -t server -S - -pgrep -q "Serving"
send-keys -t name "cmd" C-mSend commandtmux send-keys -t server "echo test" C-m
capture-pane -t name -S - -p > fileCapture outputtmux capture-pane -t server -S - -p > log.txt
attach -t nameReattachtmux attach -t server
kill-session -t nameStop sessiontmux kill-session -t server

Implementation

Session Lifecycle Management
bash
# Complete lifecycle with error handling
SESSION_NAME="myserver"
COMMAND="python -m http.server 8000"
# 1. Cleanup existing session
tmux kill-session -t "$SESSION_NAME" 2>/dev/null || true
# 2. Start new session
tmux new-session -d -s "$SESSION_NAME" "$COMMAND"
# 3. Wait for startup and verify
sleep 2
if ! tmux capture-pane -t "$SESSION_NAME" -S - -p | grep -q "Serving HTTP"; then
echo "Server failed to start properly"
tmux kill-session -t "$SESSION_NAME"
exit 1
fi
# 4. Capture initial output
tmux capture-pane -t "$SESSION_NAME" -S - -p > startup.log
# 5. Session is ready for interaction
Starting Detached Sessions
bash
# Basic detached session
tmux new-session -d -s mysession "my_long_running_command"
# With working directory and logging
tmux new-session -d -s appsession -c /path/to/dir "./run_app.sh >app.log 2>&1"
# With session conflict handling
if tmux has-session -t appsession 2>/dev/null; then
echo "Session already exists, cleaning up..."
tmux kill-session -t appsession
fi
tmux new-session -d -s appsession "./run_app.sh"

For processes requiring TTY, tmux provides PTYs automatically.

Session Verification
bash
# Check if session exists
if tmux has-session -t mysession 2>/dev/null; then
echo "Session is running"
else
echo "Session not found"
fi
# Verify process output
tmux capture-pane -t mysession -S - -p | grep -q "expected_pattern"
echo $?
# Check session status
tmux display-message -t mysession -p "#{session_name}: #{window_status}"
Sending Commands
bash
# Send command with enter
tmux send-keys -t mysess:0.0 "cd /path/to/dir" C-m
tmux send-keys -t mysess:0.0 "./run_my_task.sh --option" C-m
# Send with delay for process readiness
tmux send-keys -t server "status" C-m
sleep 1
tmux capture-pane -t server -S - -p | tail -5

Note: Process must accept stdin as commands. May need delays for shell readiness.

Capturing Output
bash
# Capture full history
tmux capture-pane -t mysess:0.0 -S - -p > output.txt
# Capture with verification
OUTPUT=$(tmux capture-pane -t mysess:0.0 -S - -p)
if echo "$OUTPUT" | grep -q "ERROR"; then
echo "Error detected in output"
fi
# Alternative with buffer
tmux capture-pane -t mysess:0.0 -S -
tmux save-buffer -b 0 output.txt
# Real-time monitoring
watch -n 5 'tmux capture-pane -t server -S - -p | tail -10'

Text only, may lose colors unless -e flag used.

Common Mistakes

  • Forgetting -d flag (attaches instead of detaching)
  • Wrong pane syntax (session:window.pane)
  • Assuming processes can receive commands if not shell-based
  • Not handling TTY requirements (tmux usually covers)
  • Losing sessions on reboot (use supervisors)
  • Not cleaning up existing sessions before starting new ones
  • Forgetting to verify session startup before proceeding
  • Not handling session conflicts in automation scripts

Real-World Impact

Enables background execution of servers, automated testing, and remote process management without keeping terminals open. Enhanced lifecycle management reduces repetitive session management tasks and provides reliable server testing workflows with proper error handling and cleanup.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
113
Repository forks
6
7-day trend score
24

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 27 Mar 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/sandgardenhq/sgai/run-long-running-processes-in-tmux/badge)](https://verified-skill.com/skills/sandgardenhq/sgai/run-long-running-processes-in-tmux)

Something wrong with this skill or its page? Tell us.