toolkit/packages/skills/tmux-monitor/SKILL.md
Monitor and report status of all tmux sessions including dev environments, spawned agents, and running processes. Uses tmuxwatch for enhanced visibility.
npx skillsauth add stevengonsalvez/agents-in-a-box tmux-monitorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Provide comprehensive visibility into all active tmux sessions, running processes, and spawned agents. This skill enables checking what's running where without needing to manually inspect each session.
if ! command -v tmux &> /dev/null; then
echo "❌ tmux is not installed"
exit 1
fi
if ! tmux list-sessions 2>/dev/null; then
echo "✅ No tmux sessions currently running"
exit 0
fi
# Get all sessions with metadata
SESSIONS=$(tmux list-sessions -F '#{session_name}|#{session_windows}|#{session_created}|#{session_attached}')
# Count sessions
TOTAL_SESSIONS=$(echo "$SESSIONS" | wc -l | tr -d ' ')
Group by prefix pattern:
dev-* → Development environmentsagent-* → Spawned agentsclaude-* → Claude Code sessionsmonitor-* → Monitoring sessionsDEV_SESSIONS=$(echo "$SESSIONS" | grep "^dev-" || true)
AGENT_SESSIONS=$(echo "$SESSIONS" | grep "^agent-" || true)
CLAUDE_SESSIONS=$(echo "$SESSIONS" | grep "^claude-" || true)
For each session, gather:
Window Information:
tmux list-windows -t "$SESSION" -F '#{window_index}:#{window_name}:#{window_panes}'
Running Processes (from first pane of each window):
tmux capture-pane -t "$SESSION:0.0" -p -S -10 -E 0
Port Detection (check for listening ports):
# Extract ports from session metadata
if [ -f ".tmux-dev-session.json" ]; then
BACKEND_PORT=$(jq -r '.backend.port // empty' .tmux-dev-session.json)
FRONTEND_PORT=$(jq -r '.frontend.port // empty' .tmux-dev-session.json)
fi
# Or detect from process list
lsof -nP -iTCP -sTCP:LISTEN | grep -E "node|python|uv|npm"
Dev Environment Metadata (.tmux-dev-session.json):
if [ -f ".tmux-dev-session.json" ]; then
PROJECT=$(jq -r '.project' .tmux-dev-session.json)
TYPE=$(jq -r '.type' .tmux-dev-session.json)
BACKEND_PORT=$(jq -r '.backend.port // "N/A"' .tmux-dev-session.json)
FRONTEND_PORT=$(jq -r '.frontend.port // "N/A"' .tmux-dev-session.json)
CREATED=$(jq -r '.created' .tmux-dev-session.json)
fi
Agent Metadata ({{HOME_TOOL_DIR}}/agents/*.json):
if [ -f "/.claude/agents/${SESSION}.json" ]; then
AGENT_TYPE=$(jq -r '.agent_type' "/.claude/agents/${SESSION}.json")
TASK=$(jq -r '.task' "/.claude/agents/${SESSION}.json")
STATUS=$(jq -r '.status' "/.claude/agents/${SESSION}.json")
DIRECTORY=$(jq -r '.directory' "/.claude/agents/${SESSION}.json")
CREATED=$(jq -r '.created' "/.claude/agents/${SESSION}.json")
fi
If tmuxwatch is available, offer enhanced view:
if command -v tmuxwatch &> /dev/null; then
echo ""
echo "📊 Enhanced Monitoring Available:"
echo " Real-time TUI: tmuxwatch"
echo " JSON export: tmuxwatch --dump | jq"
echo ""
# Optional: Use tmuxwatch for structured data
TMUXWATCH_DATA=$(tmuxwatch --dump 2>/dev/null || echo "{}")
fi
# tmux Sessions Overview
**Total Active Sessions**: {count}
**Total Windows**: {window_count}
**Total Panes**: {pane_count}
---
## Development Environments ({dev_count})
### 1. dev-myapp-1705161234
- **Type**: fullstack
- **Project**: myapp
- **Status**: ⚡ Active (attached)
- **Windows**: 4 (servers, logs, claude-work, git)
- **Panes**: 8
- **Backend**: Port 8432 → http://localhost:8432
- **Frontend**: Port 3891 → http://localhost:3891
- **Created**: 2025-01-13 14:30:00 (2h ago)
- **Attach**: `tmux attach -t dev-myapp-1705161234`
---
## Spawned Agents ({agent_count})
### 2. agent-1705160000
- **Agent Type**: codex
- **Task**: Refactor authentication module
- **Status**: ⚙️ Running (15 minutes)
- **Working Directory**: /Users/stevie/projects/myapp
- **Git Worktree**: worktrees/agent-1705160000
- **Windows**: 1 (work)
- **Panes**: 2 (agent | monitoring)
- **Last Output**: "Analyzing auth.py dependencies..."
- **Attach**: `tmux attach -t agent-1705160000`
- **Metadata**: `{{HOME_TOOL_DIR}}/agents/agent-1705160000.json`
### 3. agent-1705161000
- **Agent Type**: aider
- **Task**: Generate API documentation
- **Status**: ✅ Completed (5 minutes ago)
- **Output**: Documentation written to docs/api/
- **Attach**: `tmux attach -t agent-1705161000` (review)
- **Cleanup**: `tmux kill-session -t agent-1705161000`
---
## Running Processes Summary
| Port | Service | Session | Status |
|------|--------------|--------------------------|---------|
| 8432 | Backend API | dev-myapp-1705161234 | Running |
| 3891 | Frontend Dev | dev-myapp-1705161234 | Running |
| 5160 | Supabase | dev-shotclubhouse-xxx | Running |
---
## Quick Actions
**Attach to session**:
```bash
tmux attach -t <session-name>
Kill session:
tmux kill-session -t <session-name>
List all sessions:
tmux ls
Kill all completed agents:
for session in $(tmux ls | grep "^agent-" | cut -d: -f1); do
STATUS=$(jq -r '.status' "{{HOME_TOOL_DIR}}/agents/${session}.json" 2>/dev/null)
if [ "$STATUS" = "completed" ]; then
tmux kill-session -t "$session"
fi
done
{generated based on findings}
### Step 8: Provide Contextual Recommendations
**If completed agents found**:
⚠️ Found 1 completed agent session:
Recommendation: Review results and clean up: tmux attach -t agent-1705161000 # Review tmux kill-session -t agent-1705161000 # Cleanup
**If long-running detached sessions**:
💡 Found detached session running for 2h 40m:
Recommendation: Check if still needed: tmux attach -t dev-api-service-1705159000
**If port conflicts detected**:
⚠️ Port conflict detected:
Recommendation: Clean up old session if no longer needed
## Output Formats
### Compact (Default)
5 active sessions:
3 running servers:
### Detailed (Verbose)
Full report with all metadata, sample output, recommendations.
### JSON (Programmatic)
```json
{
"sessions": [
{
"name": "dev-myapp-1705161234",
"type": "dev-environment",
"category": "fullstack",
"windows": 4,
"panes": 8,
"status": "attached",
"created": "2025-01-13T14:30:00Z",
"ports": {
"backend": 8432,
"frontend": 3891
},
"metadata_file": ".tmux-dev-session.json"
},
{
"name": "agent-1705160000",
"type": "spawned-agent",
"agent_type": "codex",
"task": "Refactor authentication module",
"status": "running",
"runtime": "15m",
"directory": "/Users/stevie/projects/myapp",
"worktree": "worktrees/agent-1705160000",
"metadata_file": "{{HOME_TOOL_DIR}}/agents/agent-1705160000.json"
}
],
"summary": {
"total_sessions": 5,
"total_windows": 12,
"total_panes": 28,
"running_servers": 3,
"active_agents": 1,
"completed_agents": 1
},
"ports": [
{"port": 8432, "service": "Backend API", "session": "dev-myapp-1705161234"},
{"port": 3891, "service": "Frontend Dev", "session": "dev-myapp-1705161234"},
{"port": 5160, "service": "Supabase", "session": "dev-shotclubhouse-xxx"}
]
}
This skill is used by:
/tmux-status command (user-facing command)tmux (required)jq (required for JSON parsing)lsof (optional, for port detection)tmuxwatch (optional, for enhanced monitoring){{HOME_TOOL_DIR}}/agents/
agent-{timestamp}.json # Agent metadata
.tmux-dev-session.json # Dev environment metadata (per project)
/tmp/tmux-monitor-cache.json # Optional cache for performance
/tmux-status - User-facing wrapper around this skill/spawn-agent - Creates sessions that this skill monitors/start-local, /start-ios, /start-android - Create dev environmentsBeyond monitoring, use these patterns to actively manage coding sessions.
Use consistent names so sessions are self-documenting and parseable:
{tool}-{scope}-{id}[-{desc}]
| Segment | Values | Example |
|---------|--------|---------|
| tool | cc (Claude Code), codex, pi | cc |
| scope | issue, fix, pr, feature, task | issue |
| id | Issue number, PR number, or short identifier | 174 |
| desc | Optional short slug | auth-refactor |
Examples: cc-issue-174-auth-refactor, codex-fix-1520, cc-pr-186
When monitoring a coding session, look for these signals:
| Signal | Action | |--------|--------| | Model is generating code | Let it work | | "I'll now..." planning text | Verify approach is correct | | Error/stack trace repeating | Intervene (steer) | | Idle / waiting for input | Check if stuck or done | | "I've completed..." summary | Move to verify phase | | Session has exited | Check output / PR status |
# Correct course
tmux send-keys -t "${SESSION}" \
"STOP. You're going the wrong direction. <specific correction>" Enter
# Unstick
tmux send-keys -t "${SESSION}" \
"You seem stuck. Try: <specific suggestion>" Enter
# Add context
tmux send-keys -t "${SESSION}" \
"Additional context: <file path, pattern, constraint>" Enter
# Abort
tmux send-keys -t "${SESSION}" "/exit" Enter
costTotal to v.optional(v.float64())" is good.Detect session state from capture-pane output:
OUTPUT=$(tmux capture-pane -t "$SESSION" -p | tail -30)
# Completion signals
echo "$OUTPUT" | grep -qE "I've completed|changes have been|PR.*created|committed.*pushed" && echo "DONE"
# Error signals
echo "$OUTPUT" | grep -qE "Error:|FATAL|panic|OOM|killed|context.*exhausted" && echo "ERROR"
# Stuck signals (same error repeating 3+ times)
echo "$OUTPUT" | grep -iE "error|fail|fatal|panic" | sort | uniq -c | sort -rn | head -1 | awk '$1 >= 3 {print "STUCK"}'
Periodically check for stale sessions:
tmux list-sessions -F '#{session_name}' 2>/dev/null | while IFS= read -r s; do
[ -z "$s" ] && continue
LAST_ACTIVITY=$(tmux display -t "$s" -p '#{session_activity}')
IDLE_SECS=$(( $(date +%s) - LAST_ACTIVITY ))
if [ $IDLE_SECS -gt 3600 ]; then
echo "⚠️ $s idle for ${IDLE_SECS}s — consider cleanup"
fi
done
documentation
Report reflect drain spend over a time window — tokens split by cached (cache_read), uncached writes (cache_creation), and io (input+output), with a $ estimate, grouped by day / outcome / model / transcript. Reads the drainer's cost log and surfaces outlier runs and cache-reuse health (the 41.5M-token failure mode = low cache reuse + high cache writes). Use to answer "what is reflection costing me" for the last day / week.
development
Show fleet status — every claude session running on the host, merged across ainb + claude-peers broker + background jobs. Use when you need to enumerate sessions before composing an action, see which sessions have a peer registered (broker-routable) vs tmux-only, check the `summary` of each session, or pipe the list into jq for filtering. Default output: text table. Pass --format json for LLM consumption.
testing
Ordered multi-step prompts to fleet targets, ack-gated between steps via JSONL assistant-turn-end detection. Use for cycles like disconnect→reconnect→verify, or any flow where step N+1 requires step N to have completed first. The skill BLOCKS until each target's transcript shows the next assistant turn finishing OR per-step timeout fires (default 300s).
development
Center control panel — enumerate every claude session that is blocked waiting on something: a user answer (AskUserQuestion fired), an API error retry, an idle assistant turn-end with no follow-up, or an explicit WAITING: marker. Returns rich JSON with signal kind + context per session. Use this when you've stepped away from the fleet and want one place to see everything that wants your attention and answer it.