create-worktree
Create or reuse a git worktree for a pull request or branch so reviews and work happen in isolation
Best use case
create-worktree is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Create or reuse a git worktree for a pull request or branch so reviews and work happen in isolation
Teams using create-worktree should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/create-worktree/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How create-worktree Compares
| Feature / Agent | create-worktree | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Create or reuse a git worktree for a pull request or branch so reviews and work happen in isolation
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# Git Worktree
Set up an isolated git worktree.
Parse `$ARGUMENTS` to extract:
- The worktree name (required) — used as the directory name under `.worktrees/`
- `--pr <number>` (optional) — checkout a GitHub PR into the worktree using `gh pr checkout`
- `--branch <ref>` (optional) — create the worktree from a specific branch or ref
## Steps
### 1. Determine worktree path
The worktree path is: `<repo-root>/.worktrees/<name>`
For example, if the repo root is `/home/user/src/dlt` and the name is `review-pr-3584`, the worktree path is `/home/user/src/dlt/.worktrees/review-pr-3584`.
Create the `.worktrees` directory if it does not exist:
```
mkdir -p <repo-root>/.worktrees
```
### 2. Create or reuse the worktree
Check if a worktree already exists at that path:
```
git worktree list
```
- **If a worktree already exists** at the target path, reuse it.
- If `--pr` was given, run `cd <worktree-path> && gh pr checkout <number>` to make sure it is up to date.
- If `--branch` was given, run `git -C <worktree-path> checkout <ref>`.
- **If no worktree exists** at the target path, create one:
- If `--pr` was given, first resolve the PR's branch name: `gh pr view <number> --json headRefName -q .headRefName`
- If `--pr` or `--branch` was given, check `git worktree list` output for any **other** worktree that already has the same branch checked out. If found:
- Use `AskUserQuestion` to ask the user: "Branch `<branch>` is already checked out in worktree `<existing-path>`. Use that worktree instead?"
- If the user says yes, use the existing worktree path (skip creation, proceed to step 3 with the existing path).
- If the user says no, **STOP** — do not create a new worktree. Print a message explaining that the branch is already checked out elsewhere and exit.
- If no conflict, create the worktree:
- If `--branch` was given: `git worktree add .worktrees/<name> <ref>`
- Otherwise: `git worktree add .worktrees/<name> --detach`
- If `--pr` was given, then also: `cd <worktree-path> && gh pr checkout <number>`
- `gh pr checkout` handles fetching, fork tracking, and branch setup automatically.
### 3. Switch cwd
```
cd <worktree-path>
```
Then verify the switch took effect:
```
pwd
```
If `pwd` does not show the worktree path, stop with an error — the cwd did not persist.
### 4. Report
```
Worktree ready: <worktree-path>
```Related Skills
worktree-make-dev
Set up a dev environment in an existing worktree (make dev + copy secrets)
worktree-from-issue
Create a git worktree with a new branch for implementing a fix or feature for a GitHub issue
switch-worktree
Switch the current session to work in an existing git worktree
find-source
No description provided.
review-pr
Analyze a GitHub pull request including diff, comments, related issues, and local code context
release-notes
Generate release notes between two git tags with categorized PR summaries and author attribution
optimize-code
Analyze and optimize Python code performance in critical paths
implement-issue
Triage, plan, and implement a fix or feature for a GitHub issue end-to-end
dashboard
Use when reading, editing, or creating files in dlt/_workspace/helpers/dashboard/ or tests/workspace/helpers/dashboard/ or tests/e2e/
auto-write-test-rules
Use when adding or proposing a new test ONLY if the test rules are not present
auto-import-rules
Enforces dlt import conventions and ordering. Use when writing or modifying Python imports in dlt/ or tests/.
auto-docstring-rules
Enforces dlt docstring conventions. Use when writing or modifying docstrings, classes, or function signatures in Python files.