Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Worktree?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/alexander-tyagunov-worktree)
---
name: worktree
description: Creates a git worktree for isolated feature work; respects disableGit. Use to isolate a feature on its own branch.
allowed-tools: Read, Bash(git switch -), Bash(git commit -m *), Bash(git worktree add *), Bash(git add .workspace/shared/*), Bash(git check-ignore -q *)
argument-hint: "[feature-name] [spec, plan and design paths]"
---
# /worktree — Git Worktree Isolation
Create an isolated git worktree for feature development.
## Check disableGit Mode
Read `.workspace/local/prefs.md` for `disableGit: true`. If set, skip all git operations and work in the current directory.
## Process (git mode)
1. **Get the name without asking.** Use the first word of `$ARGUMENTS` when it is non-empty. Otherwise take the feature name from the approved plan or spec of this session, else derive a kebab-case name from the request. Say the name in the confirmation line; the user renames by saying so.
2. **Find the feature's documents.** A new worktree holds only committed files, and `/spec` and `/breakdown` leave their documents uncommitted, at every size. Take the paths from `$ARGUMENTS`, else from this session, else the entries for this feature under `.workspace/shared/specs/`, `.workspace/shared/plans/` and `.workspace/shared/designs/`. Add, when they exist: `.workspace/shared/design-tokens.css` and `.workspace/shared/brand.md` (the mockup step writes them), the feature's decision records under `.workspace/shared/decisions/` and its intent file under `.workspace/shared/intents/`.
- **Ignored workspace first.** Run `git check-ignore -q <path>` for each path. Exit 0 means git ignores it (the Private workspace mode of `/setup` ignores all of `.workspace/`): `git add` would fail, so drop the path and say one line, "Not carried, git-ignored: <paths>." When every path is ignored, the worktree cannot hold the spec or the plan: say so, create it by step 4, and give the build the absolute paths of the spec and the plan folder in the main checkout.
- Then run `git status --porcelain -- <paths>` on the paths that are left. No path, or empty output, means nothing to carry: go to step 4.
3. **Commit the documents on the feature branch, then come back.** Run `git diff --cached --name-only` first. When it lists a file, stop and say so: this commit must hold the documents only. Then run each line as its own plain command, so it matches this skill's pre-approval:
```bash
git switch -c feature/<name>
git add <spec path>
git add <plan folder>
git add <design folder>
git add <tokens file>
git add <brand book>
git add <decision record>
git add <intent file>
git commit -m "docs: spec and plan for <feature>"
git switch -
git worktree add ../<repo-name>-<name> feature/<name>
```
Run one `git add` per path that exists (a missing path fails and stages nothing), and stage nothing else. A `git add` of a path under `.workspace/shared/` is pre-approved. `git switch -c` is not: Claude Code asks once, for the new branch, and the plan gate said so. Other uncommitted work travels to the new branch and back with the two switches and stays uncommitted. The documents now live on `feature/<name>` only; nothing is copied. When `git switch -c` fails (the branch exists), nothing changed: report it and stop. When a later command fails or the user declines a `git add`, run `git switch -` so the user is back on the starting branch, then report it and stop. Then go to step 5.
4. **Create the worktree with a new branch**, when step 2 found nothing to carry:
```bash
git worktree add ../<repo-name>-<name> -b feature/<name>
```
5. **Workspace files** — tracked files (`.workspace/shared/`) come with the branch; gitignored ones such as `.workspace/local/prefs.md` don't. Worktrees that Claude Code creates itself (`claude --worktree`, subagent worktree isolation) copy the gitignored files listed in a `.worktreeinclude` file at the repo root, so listing `.workspace/local/prefs.md` there is a useful tip for the user. For this plain `git worktree add`, copy any local file the new worktree needs (that copy goes through the normal permission prompt).
6. **Confirm** the new worktree path and branch to the user in one line, and name the documents commit when step 3 made one. **Then work in the worktree.** The session's own folder does not change, so run every later command with the worktree as the working directory (`cd <worktree> && …`), and read and edit files by their path under it. The build reads the spec and plan there. Run state and evidence stay with the main checkout: `run-state` and `evidence` find its `.workspace/local/` from inside the worktree, and `evidence` hashes the worktree's own head and tree. Do not copy `run.json` or the evidence file. Claude Code may ask once before it edits files outside the folder the session started in.
## Alternatives at agent scale
Pick the lightest isolation that fits. Feature-detect each one. Do not ask the user to check a version.
- **`claude --worktree <name>`.** Use it when `claude --help` lists `--worktree`. It starts a new session in its own worktree and copies the files listed in `.worktreeinclude`. Tell the user the command. Do not run it from this session.
- **Agent `isolation: worktree`.** Use it for a dispatched subagent that edits files in parallel with others. Set it in the agent's frontmatter or in the `Agent` call when the tool accepts it. Claude Code removes the worktree when the agent made no change.
- **`git sparse-checkout` in a monorepo.** Use it when the repository has more than about 10,000 tracked files and the feature touches one or two packages. After the worktree exists, run `git -C ../<repo-name>-<name> sparse-checkout set --cone <package-dirs>`. That command is not pre-approved, so it prompts. Add the shared config folders the build needs.
- **Plain `git worktree add`.** Use it in every other case (the process above).
Keep each change small and state its intent in the branch name and the first commit ([lore/git.md](../../lore/git.md)).
## Process (disableGit mode)
1. Create a feature directory: `mkdir -p .features/<name>`
2. Note: no git isolation — be careful about conflicts with other in-progress work
3. Say: "Working in .features/<name>/ (disableGit mode — no worktree created)."
## Keep sibling worktrees in the loop
Worktrees isolate the files, not the consequences: a rename, a signature change, or a shared-dependency bump made here breaks whatever a sibling session is building on. When Claude Code's cross-session messaging is available, tell the affected session yourself instead of letting it discover the breakage — `ListAgents` finds the sessions working the other worktrees, `SendMessage` delivers one self-contained sentence about what landed.
Feature-detect it: no `ListAgents`, or no peer listed, means carry on exactly as before and note the change in your own summary. It isn't available in every environment, and a session inside a container can't see one on the host. See [lore/cross-session.md](../../lore/cross-session.md).
**Autonomy.** Gates: none. Everything else runs without asking.
## Cleanup After Merge
After the PR merges:
```bash
git worktree remove ../<repo-name>-<name>
git branch -d feature/<name>
```
## Obstacles
This is a thin git-worktree utility. If a worktree cannot be created (branch already exists, dirty tree), report it in prose to the caller and stop; it emits no structured upward Obstacles block.
See [lore/obstacles.md](../../lore/obstacles.md).
## Completion Signal
"Worktree ready. Worktree at `<path>`, branch `<branch>`."