Skip to content

Instantly share code, notes, and snippets.

@kentaro
Created June 5, 2025 14:02
Show Gist options
  • Save kentaro/27c4f450de042d7f83a76aeba4e5cd26 to your computer and use it in GitHub Desktop.
Save kentaro/27c4f450de042d7f83a76aeba4e5cd26 to your computer and use it in GitHub Desktop.
claude-tilex
# claude-tilex: <count> 個のペインを開き、
# ブランチ名を入力 → worktree 作成 → claude を実行
#
# 使い方例:
# claude-tilex 4 # オプションなし
# claude-tilex 2 -- --model opus # 2 ペインで Opus を実行
claude-tilex() {
local count session="claude-parallel"
# ---------- 引数パース ----------
while (($#)); do
case $1 in
--) shift; break ;; # 以降はそのまま claude へ
[0-9]*) count=$1; shift ;;
*) echo "Usage: claude-tilex <count> [-- <claude options>]"; return 1 ;;
esac
done
[[ -z $count ]] && { echo "Usage: claude-tilex <count> [-- <claude options>]"; return 1; }
local claude_opts="$*" # 残りをそのまま渡す(空でも可)
local root=$(git rev-parse --show-toplevel 2>/dev/null) || { echo "Not in git repo"; return 1; }
cd "$root"
# ---------- セッション準備 ----------
local target created=0 cmd
cmd="claude ${claude_opts:+$claude_opts}"
if [[ -z $TMUX ]]; then
tmux new-session -d -s "$session" \
"bash -c 'read -p \"branch name: \" br; git worktree add -B \"\$br\" .worktrees/\$br HEAD && cd .worktrees/\$br && $cmd'"
target=$session
created=1
else
target="."
fi
# ---------- 残りペイン ----------
for ((i = created; i < count; i++)); do
tmux split-window -t "$target" \
"bash -c 'read -p \"branch name: \" br; git worktree add -B \"\$br\" .worktrees/\$br HEAD && cd .worktrees/\$br && $cmd'"
done
tmux select-layout -t "$target" tiled
[[ -z $TMUX ]] && tmux attach -t "$session"
echo "✅ claude-tilex: started $count pane(s) with \"${cmd}\""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment