Our review
Manages Git worktrees for a monorepo: create, list, and cleanup with automatic dependency installation and GitHub issue validation.
Strengths
- Automates worktree creation from GitHub issues with issue state validation
- Automatically installs dependencies with pnpm after creation
- Provides a formatted table of active worktrees with ahead/behind status
- Cleans up worktrees whose branches have been merged into main
Limitations
- Specific to the USOPC monorepo directory structure
- Requires the GitHub CLI (`gh`) to be installed and configured
- Does not handle merge conflicts during cleanup
Use this skill to quickly create an isolated work environment for a GitHub issue, or to clean up stale worktrees after merging.
Do not use it if you are working outside the USOPC monorepo or if you prefer to manage worktrees manually with Git.
Security analysis
SafeThe skill only executes standard git worktree operations, pnpm install, and gh issue view, all applied locally within the repository. There is no command to fetch or execute external scripts, delete files outside controlled worktree paths, or exfiltrate data. The allowed tools are restricted to safe, legitimate development commands.
No concerns found
Examples
/worktree create 42/worktree list/worktree cleanupname: worktree description: Smart worktree management — create, list, and clean up git worktrees with automatic gotcha handling (pnpm install, hook script copy, issue validation). argument-hint: <create|list|cleanup> [issue-number] disable-model-invocation: true allowed-tools: Bash(git *), Bash(cd *), Bash(pnpm *), Bash(gh issue view *), Bash(gh repo view *), Bash(ls *), Glob, Read
Smart Worktree Management
You are managing git worktrees for the USOPC Athlete Support Agent monorepo. The argument is: $ARGUMENTS.
Parse the argument to determine the subcommand:
create <issue-number>— Create a new worktree for an issuelist— List active worktrees with statuscleanup— Remove worktrees whose branches have been merged
If no subcommand is provided or the argument is empty, print the usage:
Usage: /worktree <command> [args]
create <issue-number> — Create worktree for a GitHub issue
list — List active worktrees with branch status
cleanup — Remove merged worktrees and prune refs
Subcommand: create <issue-number>
Step 1: Validate the issue exists
Run gh issue view <issue-number> --json number,title,state to confirm the issue exists and is open. If the issue doesn't exist or is closed, warn the user and stop.
Step 2: Determine paths
- Get the main repo root:
git rev-parse --show-toplevel(if in a worktree, usegit worktree listto find the main repo) - Worktree path:
../usopc-issue-<number>relative to the main repo (i.e., a sibling directory) - Derive a short branch name from the issue title:
feat/<kebab-case-summary>(max 50 chars, lowercase, hyphens only)
Step 3: Fetch latest main
Run git fetch origin main to ensure we branch from the latest main.
Step 4: Create the worktree
git worktree add <worktree-path> -b <branch-name> origin/main
If the worktree path already exists, warn and stop.
Step 5: Install dependencies
cd <worktree-path> && pnpm install
Step 6: Print summary
Worktree created:
Path: <worktree-path>
Branch: <branch-name>
Issue: #<number> — <title>
Dependencies installed.
Navigate with: cd <worktree-path>
Subcommand: list
Step 1: List worktrees
Run git worktree list and parse the output.
Step 2: For each worktree (excluding bare/main)
- Show the path, branch name
- Run
git -C <path> log --oneline -1for latest commit - Run
git -C <path> rev-list --left-right --count origin/main...<branch>for ahead/behind status
Step 3: Print formatted table
Active worktrees:
../usopc-issue-42 feat/add-auth +3 / -0 (latest: abc1234 Add auth middleware)
../usopc-issue-55 fix/query-perf +1 / -2 (latest: def5678 Fix slow query)
Subcommand: cleanup
Step 1: List worktrees
Run git worktree list and identify non-main worktrees.
Step 2: Check each branch
For each worktree branch, check if it has been merged into origin/main:
git branch --merged origin/main | grep <branch-name>
Step 3: Remove merged worktrees
For each merged worktree, remove it:
git worktree remove <path>
Print which worktrees were removed.
Step 4: Prune and clean up
git worktree prune
git fetch --prune origin
Step 5: Print summary
Cleaned up:
Removed: ../usopc-issue-42 (feat/add-auth — merged)
Removed: ../usopc-issue-55 (fix/query-perf — merged)
Pruned stale worktree references.
If no worktrees were eligible for cleanup, say so.
Important notes
- Always use absolute paths when running git commands to avoid confusion between worktree and main repo.
- The main repo root can be found via
git worktree list— it's the first entry (the one without[branch]or with[main]). scripts/update-hours.mjsandscripts/stamp-readme-hours.mjsare tracked in git, so they'll be available in worktrees automatically — no copying needed.
Next.js App Router Expert
Development
A skill that turns Claude into a Next.js App Router expert.
README Generator
Development
Creates professional and comprehensive README.md files for your projects.
API Documentation Writer
Development
Generates comprehensive API documentation in OpenAPI/Swagger format.