Skip to content
Back to skills

Setup Worktree

ASecurity

Prepare this project for the worktree skill: study how it installs, configures and runs, then write `.worktreeinclude`, a committed setup script that gets a new git worktree ready to run, and a Worktrees section in AGENTS.md listing every server's ports and how to move them. Run once per project, and again to refresh it.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 29, 2026
ai-agentsjavascriptpythonrustgojavarubyphpshellbashnode

Works with

  • claude code
  • api

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned November 29, 2026

npx -y skills add artberri/skills --skill setup-worktree --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Setup Worktree?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Setup Worktree
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/artberri-setup-worktree/badge)](https://www.skillsdirectory.com/skills/artberri-setup-worktree)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: setup-worktree
description: "Prepare this project for the worktree skill: study how it installs, configures and runs, then write `.worktreeinclude`, a committed setup script that gets a new git worktree ready to run, and a Worktrees section in AGENTS.md listing every server's ports and how to move them. Run once per project, and again to refresh it."
disable-model-invocation: true
---

# Set up worktrees

Writes the project files the `worktree` skill reads, so that any worktree of this project can install, configure and run beside the main checkout. It sets up:

- **`.worktreeinclude`**: the gitignored files a worktree needs to run (env files, local secrets), in `.gitignore` syntax. Claude Code copies them into the worktrees it creates.
- **A setup script**, committed and executable, that `worktree`, a person or a future hook runs inside a new worktree: it copies those files when they are missing, installs the toolchain and dependencies the way CI does, and runs the steps after the install.
- **A "Worktrees" section** in the project's instruction file: each server, its ports, how to move them, and any state two copies of the app would share.
- **`.claude/worktrees/` in `.gitignore`**, where the `worktree` skill and Claude Code put worktrees.

Look at the project first, every time: it may be JavaScript, Python, Ruby, Go, Rust, PHP, a monorepo of several, or a Docker Compose stack. Every command you write comes from the project's own files, never from what a typical project of its kind does. [references/ecosystems.md](./references/ecosystems.md) maps lockfiles to install commands and frameworks to their ports; read the rows for what you find.

## 1. Explore

Run every lookup from the main checkout's root (`git worktree list`, first entry). Read what exists:

- **Earlier setup.** `.worktreeinclude`, a script that says the setup-worktree skill wrote it, a "Worktrees" section. If any exists, this is a *refresh*: start from them and propose changes, never a rewrite.
- **Instructions.** `AGENTS.md`, `CLAUDE.md`, `README`, `CONTRIBUTING`: how the project says to install, run and test. Find the *real* instruction file: when one is a symlink to the other, or only imports it (`@AGENTS.md`), the target is the real one.
- **Install.** Every lockfile and manifest, workspace configs for monorepos, and the CI config. CI's install command is the one to copy (`--frozen-lockfile`, `--frozen`, `ci`, `--locked`): it is the project's tested way to install exactly the lockfile.
- **Toolchain.** Version pins (`.prototools`, `.tool-versions`, `mise.toml`, `.nvmrc`, `.node-version`, `.python-version`, `.ruby-version`, `rust-toolchain.toml`, `go.mod`'s `toolchain`, `packageManager` in `package.json`) and the version manager that reads them, from CI or the docs.
- **After the install.** Lifecycle scripts (`prepare`, `postinstall`), git hook setup (`core.hooksPath`, husky, lefthook, pre-commit), code and type generation. Note which ones the install already runs on its own.
- **Ignored files.** `.gitignore` (and nested ones), and `git status --ignored --short` in the main checkout: what is ignored, and what of it exists right now.
- **Servers.** Dev, preview, start and storybook scripts, `Procfile`s, `Makefile` targets, `docker-compose.yml` / `compose.yaml`, framework and tool configs (`next.config.*`, `vite.config.*`, `wrangler.*`, `config/puma.rb`, `settings.py`...), and env files or examples that set ports. For each server find the **ports**: the main one and the **secondary** ones that clash just as badly (debugger or inspector, HMR websocket, a database or cache in Compose). Then find how to move each one: a flag or an env var, and whether a wrapper script passes the flag through to the tool underneath.
- **Shared state.** Anything two copies of the app would both use: a local database or cache that env files point at, a Compose volume or a fixed `container_name` / project `name:`, a fixed path outside the repo, a queue.
- **Claude Code settings.** `worktree.symlinkDirectories` in `.claude/settings*.json`: a symlinked dependency folder (`node_modules`, `.venv`, `vendor`, `target`) is shared by every worktree, so a branch with a different lockfile breaks the others. Recommend removing that entry. Check also that `.claude` and `.claude/worktrees` are real folders, not symlinks: Claude Code refuses to create worktrees through a symlink.

**Verify what you can't read off a file**: run a tool's `--help` (`npx --no-install <tool> --help`, `uv run <tool> --help`) or read its installed source or docs, to confirm that a flag exists and that the project's script passes it through. Keep every claim you could not confirm, marked *unverified* in what you show the user.

## 2. Present and confirm

Show the user what you found and what you will write, leading each part with your recommendation:

- **Install:** the toolchain and install commands, and the steps after them, with where each came from (`.github/workflows/ci.yml`, line 24).
- **`.worktreeinclude`:** each pattern and the files it matches today.
- **The script's path.** Put it in the project's existing scripts folder (`scripts/`, `bin/`, `script/`, `tools/`), named `worktree-setup.sh`, or in `scripts/` when there is none. On a refresh, keep the path it has.
- **Servers and ports**, as the table the section will hold, and the shared state.
- **Changes on a refresh**, as a diff.

Ask only about what you could not settle from the project. Wait for the answer before writing.

## 3. Write

- **`.worktreeinclude`.** Only files a worktree needs to *run*: env files, local secrets and config the app reads. Leave out everything a worktree rebuilds or regenerates: dependencies, caches, build output, generated types, logs. Leave out `.claude/settings.local.json` too: Claude Code reads the main checkout's copy from every worktree. Anchor each pattern at the root (`/.env*`), or at the folders that hold the files (`/apps/*/.env*`): an unanchored pattern also matches inside ignored dependency folders. Include patterns for files that don't exist yet when `.gitignore` ignores them for this purpose (`.env*` ignored, none created yet). Then prove each pattern matches something git ignores: `git check-ignore -q <a path it matches>` for every pattern, with a real file or a name it is meant for (`.env.local`). Drop a pattern that fails: Claude Code copies only files that are both matched and ignored.
- **The setup script.** Copy [templates/worktree-setup.sh](./templates/worktree-setup.sh) and replace its "Project steps" block with the project's own: the install inputs (every lockfile and toolchain pin the install depends on), the check that dependencies are present, the toolchain install, the install command from CI, and the steps after it. Keep everything outside that block as it is: it copies the `.worktreeinclude` files, skips the install when nothing changed, and keeps stdout empty. It runs on macOS's `/bin/bash` 3.2 and on Linux; keep the project steps to commands that work on both. Only the toolchain and dependency installs may use the network; every other step works offline. Make it executable (`chmod +x`), then check it with `bash -n`, and with `shellcheck` and `shfmt -d` when they are installed.
- **The "Worktrees" section** in the real instruction file, or a new `AGENTS.md` when the project has none (say so). Keep it in this shape, because the `worktree` skill reads the table:

  ```markdown
  ## Worktrees

  Run `scripts/worktree-setup.sh` inside a new worktree, and again after a branch changes a lockfile. It copies the files `.worktreeinclude` lists from the main checkout and installs what CI installs.

  | Server | Start | Port | Move it with | Also listens on |
  | --- | --- | --- | --- | --- |
  | API | `make api` | 8080 | `PORT=<port>` | debugger 2345 (`DLV_PORT=<port>`) |

  Shared state: both copies use the Postgres in `compose.yaml` (port 5432, volume `pgdata`); give a worktree its own with `COMPOSE_PROJECT_NAME=<name>` and `DB_PORT=<port>`.
  ```

  One row per server. Put each secondary port in "Also listens on" with its own way to move it, and `-` when there is none. Mark a flag you couldn't verify *(unverified)*. Leave the shared-state line out when there is none.
- **`.gitignore`.** Add `.claude/worktrees/` unless `git check-ignore -q .claude/worktrees/x` already succeeds.

On a refresh, edit each file in place: keep what is still right, including the user's own edits, and change only what the project changed.

## 4. Verify

Try the script in a throwaway worktree, from the main checkout:

1. `git worktree add .claude/worktrees/setup-check -b setup-check-tmp HEAD`.
2. Run the new script on it: `<script path> .claude/worktrees/setup-check`, from the main checkout (the worktree's own copy is the committed one, which this run replaces). Check that the `.worktreeinclude` files arrived and the install ran.
3. Run it again: the second run must skip the install.
4. Remove the worktree and the branch: `git worktree remove --force .claude/worktrees/setup-check` and `git branch -D setup-check-tmp`.

This runs the real install, so it can take a while and use the network; say so before starting. When the install fails for a reason outside the script (no network, a missing toolchain the version manager can't fetch), report it and keep the script.

## 5. Report

List what was written or changed, file by file, with what changed on a refresh. Say what was *unverified*. Tell the user the files are meant to be committed, so every worktree, person and agent on the project gets the same setup, and that `/worktree` (the `worktree` skill) now uses them. Don't commit them yourself.

Files in this skill

  • SKILL.md9.4 KB
  • agents/openai.yaml156 B
  • evals/evals.json4.9 KB
  • evals/fixtures/notes-api-refresh.sh1.3 KB
  • evals/fixtures/notes-api.sh267 B
  • evals/fixtures/notes.sh7 KB
  • evals/fixtures/storefront.sh4.2 KB
  • evals/stubs/bun1016 B
  • evals/stubs/docker668 B
  • evals/stubs/proto685 B
  • evals/stubs/uv1.1 KB
  • references/ecosystems.md4.9 KB
  • templates/worktree-setup.sh3.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.