Files
tmux/agent-cmd.sh
Kenneth Benzie (Benie) 688f263323 Auto-detach when all agents in window exit
Add agent-cmd.sh wrapper that detaches the client when all panes in the
current window have exited. This allows multiple agent windows (one per
directory) while automatically returning to the shell when done with a
particular window's agents.

- remain-on-exit keeps panes alive after agent exits to check status
- Wrapper counts running panes and detaches when it's the last one
2026-02-02 11:49:26 +00:00

16 lines
537 B
Bash
Executable File

#!/usr/bin/env bash
# Wrapper that runs an agent command, then detaches if all panes in window are dead
# Run the agent command (don't use set -e, agent may exit non-zero)
"$@" || true
# Brief delay to let tmux update pane status
sleep 0.1
# Count panes still running (pane_dead=0)
# Note: our own pane counts as running since this script is executing
running=$(tmux list-panes -F '#{pane_dead}' | grep -c '^0$' || true)
# If we're the only pane still running, all others are dead - detach
[ "$running" -le 1 ] && tmux detach-client