home / skills / trentshaines / dotfiles / trent-cleanup-panes
This skill closes all tmux panes in the current window, keeping your active pane intact and restoring a clean layout.
npx playbooks add skill trentshaines/dotfiles --skill trent-cleanup-panesReview the files below or copy the command above to add this skill to your agents.
---
name: trent-cleanup-panes
description: Clean up tmux panes. Use when user wants to close/kill all other panes, clean up tmux window, or reset pane layout.
---
# Cleanup Panes Skill
## Overview
Closes all tmux panes in the current window except the one you're in.
## Trigger
User invokes `/cleanup-panes` or asks to clean up/close other panes.
## Instructions
Execute this bash script:
```bash
#!/bin/bash
ORIGINAL_PANE=$(tmux display-message -p '#{pane_id}')
echo "Keeping pane: $ORIGINAL_PANE"
# Get all panes except original, then kill each
PANES_TO_KILL=$(tmux list-panes -F '#{pane_id}' | grep -v "^${ORIGINAL_PANE}$")
if [ -z "$PANES_TO_KILL" ]; then
echo "No other panes to close."
else
COUNT=0
while IFS= read -r PANE; do
if [ -n "$PANE" ]; then
tmux kill-pane -t "$PANE" 2>/dev/null && ((COUNT++))
fi
done <<< "$PANES_TO_KILL"
echo "Closed $COUNT panes. Only current pane remains."
fi
```
## Important Notes
- Only affects the current tmux window
- Preserves the pane you're currently in
- Safe to run even if there are no other panes
This skill cleans up tmux panes in the current window by closing every pane except the one you're actively using. It provides a quick way to reset a tmux window to a single pane without affecting other windows or sessions. The operation is safe to run when there are no other panes and reports how many panes were closed.
The skill identifies the current pane, lists all panes in the current window, filters out the active pane, and kills each remaining pane. It counts successful kills and prints a summary. Only panes in the same tmux window are affected; the active pane is preserved and the rest are closed quietly.
Will this close panes in other tmux windows or sessions?
No. The skill only targets panes within the current tmux window.
What happens if there are no other panes?
It reports that no other panes exist and leaves the current pane untouched.
Can I accidentally kill the active pane?
No. The active pane is detected and explicitly preserved by the operation.