npx claudepluginhub caphtech/claude-marketplace --plugin zellij-pluginWant just this skill?
Then install: npx claudepluginhub u/[userId]/[slug]
git worktreeを作成してzellij tabで開く。worktree削除とクリーンアップも行う。「worktreeを作って」「ブランチをworktreeで開いて」「worktreeを削除して」「worktreeを一覧して」と言われた時に使用する。
This skill is limited to using the following tools:
zellij-worktree
git worktreeをzellij tabとして管理する。
概要
create <branch> → git worktree add → zellij action new-tab
delete <branch> → zellij action close-tab → git worktree remove
list → git worktree list
前提チェック
スキル実行前に以下を確認:
- gitリポジトリ内か
zellijセッション内か($ZELLIJ変数の存在)— 非zellij時はworktree操作のみ行いパスを出力- 現在の作業ディレクトリがworktreeの場合、メインリポジトリのパスを特定する
# メインリポジトリの特定
COMMON_DIR=$(cd "$(git rev-parse --git-common-dir)" && pwd)
ABS_GIT_DIR=$(cd "$(git rev-parse --absolute-git-dir)" && pwd)
if [ "$COMMON_DIR" != "$ABS_GIT_DIR" ]; then
REPO_ROOT=$(dirname "$COMMON_DIR")
else
REPO_ROOT=$(git rev-parse --show-toplevel)
fi
REPO_NAME=$(basename "$REPO_ROOT")
復元失敗時のフォールバック: git worktree list --porcelain の最初のworktreeエントリがメインrepo。
パス規則
WORKTREE_BASE="${CLAUDE_WORKTREE_DIR:-$(dirname "$REPO_ROOT")/${REPO_NAME}.worktrees}"
- デフォルト配置:
../<repo-name>.worktrees/<branch-slug>/ - 環境変数
CLAUDE_WORKTREE_DIRで上書き可能
slug生成(create時のみ使用)
# ブランチ名のハッシュ(決定論的、create/delete間で安定)
BRANCH_HASH=$(printf '%s' "$BRANCH" | shasum | cut -c1-6)
# 読みやすいslug + 常にハッシュを付加して一意性を保証
BRANCH_SLUG=$(printf '%s' "$BRANCH" | sed 's/[^A-Za-z0-9._-]/-/g; s/--*/-/g; s/^-//; s/-$//' | cut -c1-60)
# パストラバーサル防止 + 空slug対策
case "$BRANCH_SLUG" in
""|"."|"..") BRANCH_SLUG="branch" ;;
esac
BRANCH_SLUG="${BRANCH_SLUG}-${BRANCH_HASH}"
WORKTREE_PATH="${WORKTREE_BASE}/${BRANCH_SLUG}"
<readable-slug>-<branch-hash>形式で常に一意- ブランチ名のsha1先頭6文字をsuffixとして付加(
feature/aとfeature-aの衝突を回避) - deleteはslugを再計算しない(後述)
worktreeパスの逆引き
deleteやcreateの既存チェックでは、slugの再計算ではなく git worktree list --porcelain からブランチ名でパスを逆引きする。これによりslug計算の不一致によるバグを防ぐ。
# ブランチ名からworktreeパスを逆引き
find_worktree_by_branch() {
git worktree list --porcelain | awk -v branch="$1" '
/^worktree / { path = substr($0, 10) }
/^branch refs\/heads\// {
b = substr($0, 19)
if (b == branch) { print path; exit }
}
'
}
コマンド
create
引数: ブランチ名(必須)。未指定なら質問する。
# 1. 既存チェック(ブランチ名で逆引き)
EXISTING_PATH=$(find_worktree_by_branch "$BRANCH")
if [ -n "$EXISTING_PATH" ]; then
echo "Worktree already exists: ${EXISTING_PATH}"
if [ -n "$ZELLIJ" ]; then
TAB_NAME=$(basename "$EXISTING_PATH")
zellij action go-to-tab-name "${TAB_NAME}" 2>/dev/null || true
fi
exit 0
fi
# 2. slug化とパス決定(上記slug生成を使用)
# 3. 書き込み権限チェック + フォールバック
if ! mkdir -p "${WORKTREE_BASE}" 2>/dev/null; then
WORKTREE_BASE="${TMPDIR:-/tmp}/${REPO_NAME}.worktrees"
BRANCH_SLUG="${BRANCH_SLUG}" # slug自体は変わらない
WORKTREE_PATH="${WORKTREE_BASE}/${BRANCH_SLUG}"
mkdir -p "${WORKTREE_BASE}"
fi
# 4. worktree作成
if git show-ref --verify --quiet "refs/heads/${BRANCH}"; then
git worktree add "${WORKTREE_PATH}" "${BRANCH}"
elif REMOTE_REF=$(git branch -r --list "*/${BRANCH}" | head -1 | xargs); [ -n "$REMOTE_REF" ]; then
git worktree add --track -b "${BRANCH}" "${WORKTREE_PATH}" "$REMOTE_REF"
else
git worktree add -b "${BRANCH}" "${WORKTREE_PATH}"
fi
# 5. zellij tabを作成(zellij環境の場合のみ)
if [ -n "$ZELLIJ" ]; then
zellij action new-tab --name "${BRANCH_SLUG}" --cwd "${WORKTREE_PATH}"
else
echo "Worktree created: ${WORKTREE_PATH}"
echo "cd ${WORKTREE_PATH}"
fi
delete
引数: ブランチ名(必須)。未指定なら list の結果から選択を促す。
slugを再計算せず、ブランチ名からworktreeパスを逆引きして削除する。
# 1. ブランチ名からworktreeパスを逆引き
WORKTREE_PATH=$(find_worktree_by_branch "$BRANCH")
if [ -z "$WORKTREE_PATH" ]; then
echo "Error: No worktree found for branch '${BRANCH}'"
git worktree list
exit 1
fi
# メイン作業ツリーの削除を防止
MAIN_TOPLEVEL=$(cd "$REPO_ROOT" && pwd)
WORKTREE_RESOLVED=$(cd "$WORKTREE_PATH" && pwd)
if [ "$WORKTREE_RESOLVED" = "$MAIN_TOPLEVEL" ]; then
echo "Error: Cannot delete main working tree"
exit 1
fi
TAB_NAME=$(basename "$WORKTREE_PATH")
# 2. Guard: 削除前の安全チェック
WARNINGS=""
# 未commitの変更チェック
DIRTY=$(git -C "$WORKTREE_PATH" status --porcelain 2>/dev/null)
if [ -n "$DIRTY" ]; then
WARNINGS="${WARNINGS}\n⚠ 未commitの変更があります:\n${DIRTY}\n"
fi
# 未pushのコミットチェック
UNPUSHED=$(git -C "$WORKTREE_PATH" log @{u}.. --oneline 2>/dev/null)
if [ -n "$UNPUSHED" ]; then
WARNINGS="${WARNINGS}\n⚠ 未pushのコミットがあります:\n${UNPUSHED}\n"
fi
# 注: zellijではpane内の実行中プロセスを外部から検出するAPIがないため、
# tmux版のような実行中プロセスチェックは行えない。
# zellij自体がタブ/pane閉じ時に確認プロンプトを表示する。
# 警告がある場合はユーザーに確認を求める
if [ -n "$WARNINGS" ]; then
printf '%s\n' "$WARNINGS"
echo "---"
echo "このworktreeを削除しますか?ユーザーに確認してください。"
echo "確認が取れるまで以降の削除処理を実行しないこと。"
exit 0
fi
# 3. zellij tabを閉じる(worktree削除前に実行 — cwdが消える前にタブを閉じる)
if [ -n "$ZELLIJ" ]; then
zellij action go-to-tab-name "${TAB_NAME}" 2>/dev/null && \
zellij action close-tab 2>/dev/null || true
fi
# 4. worktreeを削除
git worktree remove "${WORKTREE_PATH}"
# 5. 空ディレクトリの掃除
WORKTREE_BASE=$(dirname "$WORKTREE_PATH")
rmdir "${WORKTREE_BASE}" 2>/dev/null || true
list
引数なし。現在のworktreeを表示。
echo "=== Git Worktrees ==="
git worktree list
注: zellijにはtab一覧を取得するCLIコマンドが限定的なため、git worktree list のみ表示する。
エラーハンドリング
- worktree作成失敗時:
git worktree prune --expire nowを実行してリトライ - zellij非実行時: worktree操作のみ行い、パスを出力(
$ZELLIJで判定) - 削除時のzellij tab不在: 警告を出すがworktree削除は続行
--git-common-dir復元失敗時:git worktree list --porcelainの最初のエントリからメインrepoパスを取得
Similar Skills
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.