home / skills / trentshaines / dotfiles / cleanup-panes

cleanup-panes skill

/dot_claude/skills/cleanup-panes

This skill closes all tmux panes in the current window except the one you are in, streamlining your workspace.

npx playbooks add skill trentshaines/dotfiles --skill cleanup-panes

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.1 KB
---
name: 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

Overview

This skill closes all tmux panes in the current window except the active one, letting you quickly reduce clutter or reset a window layout. It is a simple, safe command for keeping only the pane you are working in while leaving the window and session intact. Use it when you want a clean workspace without manually closing each pane.

How this skill works

The skill reads the current pane ID, lists all panes in the active tmux window, filters out the current pane, and kills each remaining pane. It counts successful kills and reports how many panes were closed. If there are no other panes, it reports that nothing needed closing.

When to use it

  • You want to close every other pane in the current tmux window quickly.
  • You need to reset a messy pane layout back to a single pane.
  • You finished parallel work in other panes and want to focus on the current pane.
  • You want a fast way to clean the window before creating a new layout or split.

Best practices

  • Run the command from the pane you want to keep to avoid unintentionally closing the wrong pane.
  • Verify unsaved work in other panes before running, since killed panes terminate their processes.
  • Use within the intended tmux window—this does not affect other windows or sessions.
  • Combine with a quick status or list-panes check if you want to inspect panes before cleanup.

Example use cases

  • After running multiple build or test panes, keep only the editor pane to continue work.
  • Clean up a temporary debugging window that spawned several short-lived panes.
  • Reset a collaboration window after a pair-programming session to start a new layout.
  • Remove leftover panes created by scripts or tools without closing the tmux window or session.

FAQ

Will this close panes in other tmux windows or sessions?

No. It only targets panes listed in the current tmux window.

What happens to processes running in killed panes?

Killing a pane terminates its running processes. Save work or stop important tasks before running the cleanup.