dariopalminio/agile-sddf-extension/git-worktrees-use
Claude Code and agent skill by dariopalminio/agile-sddf-extension
- community
Checking that the SKILL.md file is still in the repository.
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
Install
npx vskill@latest install dariopalminio/agile-sddf-extension/git-worktrees-useSKILL.md
The same SKILL.md was published earlier as dariopalminio/agile-sddf-extension/git-worktrees-use.
Using Git Worktrees
Overview
Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
Core principle: Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
Announce at start: "I'm using the git-worktrees-use skill to set up an isolated workspace."
Step 0: Detect Existing Isolation
Before creating anything, check if you are already in an isolated workspace.
Submodule guard: GIT_DIR != GIT_COMMON is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
If `GIT_DIR != GIT_COMMON` (and not a submodule): You are already in a linked worktree. Skip to Step 3 (Project Setup). Do NOT create another worktree.
Report with branch state:
- On a branch: "Already in isolated workspace at
<path>on branch<name>." - Detached HEAD: "Already in isolated workspace at
<path>(detached HEAD, externally managed). Branch creation needed at finish time."
If `GIT_DIR == GIT_COMMON` (or in a submodule): You are in a normal repo checkout.
Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
"Would you like me to set up an isolated worktree? It protects your current branch from changes."
Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 3.
Step 1: Create Isolated Workspace
You have two mechanisms. Try them in this order.
1a. Native Worktree Tools (preferred)
The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like EnterWorktree, WorktreeCreate, a /worktree command, or a --worktree flag. If you do, use it and skip to Step 3.
Native tools handle directory placement, branch creation, and cleanup automatically. Using git worktree add when you have a native tool creates phantom state your harness can't see or manage.
If the native flow does not propagate Claude/Cursor settings and the user expects parity with the main checkout, copy .claude/settings.json and .claude/settings.local.json from the primary workspace using the same loop as Step 1b after the native tool finishes—only when files exist on disk.
Only proceed to Step 1b if you have no native worktree tool available.
1b. Git Worktree Fallback
Only use this if Step 1a does not apply — you have no native worktree tool available. Create a worktree manually using git.
Directory Selection
Use a single location: .worktrees/ inside the repository root.
- Set the repository root and worktree base directory:
``bash SOURCE_ROOT=$(git rev-parse --show-toplevel) LOCATION="$SOURCE_ROOT/.worktrees" ``
- Ensure the directory exists:
``bash mkdir -p "$LOCATION" ``
- Always create the worktree at:
``bash path="$LOCATION/$BRANCH_NAME" ``
No global/sibling alternatives should be used unless the user explicitly overrides this rule for a one-off task.
Safety Verification
MUST verify `.worktrees/` is ignored before creating worktree:
If NOT ignored: Add .worktrees/ to .gitignore, commit the change, then proceed.
Why critical: Prevents accidentally committing worktree contents to repository.
Create the Worktree
Capture the main checkout root before `git worktree add`. After cd into the new worktree, git rev-parse --show-toplevel points at the worktree directory, not the checkout where .claude/settings*.json usually lives.
Sandbox fallback: If git worktree add fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
Copy Claude configuration (Step 1b only)
After creating the worktree with git (Step 1b), copy local Claude settings from the main checkout so Cursor/Claude CLI behavior matches the primary workspace. These files are often untracked.
Do not copy if the user declines or if a native tool (Step 1a) already propagates settings—respect the harness.
Run after cd "$path" (still using SOURCE_ROOT captured above):
Symlinks: If the source tree uses symlinks for .claude (e.g. .claude/skills → ../../ai-specs/skills), copying only these JSON files does not recreate symlink targets. Either repeat the same symlink layout in the worktree or rely on project-relative paths inside settings.json.
Step 3: Project Setup
Auto-detect and run appropriate setup:
Step 4: Verify Clean Baseline
Run tests to ensure workspace starts clean:
If tests fail: Report failures, ask whether to proceed or investigate.
If tests pass: Report ready.
Report
Step 5: Cleanup — Remove the Worktree When Done
Run cleanup once the work is complete. "Done" means: branch merged, PR closed, the experiment was discarded, or the user has explicitly confirmed they no longer need the isolated workspace. Never remove a worktree that still contains uncommitted, unpushed, or unmerged changes the user may want.
5.0 Detect Cleanup Mode
- If `GIT_DIR == GIT_COMMON`: You were never in a linked worktree (Step 0 sent you straight to Step 3). There is nothing to clean up — skip Step 5 entirely.
- If `GIT_DIR != GIT_COMMON`: You are inside a linked worktree. Continue with cleanup.
5.1 Verify Work Is Saved
Before removing anything, confirm there is no work to lose:
If either command returns output: Stop. Report the unsaved work to the user and ask how to proceed (commit/push, stash, or force discard). Never delete a worktree with unsaved work without explicit user confirmation.
Capture the worktree path and branch name before leaving the directory:
5.2 Native Worktree Tools (preferred)
If you used a native worktree tool in Step 1a (EnterWorktree, WorktreeCreate, /worktree, etc.), use the matching native command to remove the worktree (e.g. LeaveWorktree, WorktreeRemove, /worktree remove). Native tools clean up directories, branches, and harness state consistently.
Only proceed to 5.3 if no native cleanup tool is available.
5.3 Git Worktree Fallback Cleanup
Only use this if Step 5.2 does not apply — you created the worktree manually in Step 1b.
Sandbox fallback: If removal fails due to permissions, report the failure and the path that needs manual cleanup. Do not retry destructively.
5.4 Verify Cleanup
Report
Quick Reference
| Situation | Action | |
|---|---|---|
| Already in linked worktree | Skip creation (Step 0) | |
| In a submodule | Treat as normal repo (Step 0 guard) | |
| Native worktree tool available | Use it (Step 1a) | |
| No native tool | Git worktree fallback (Step 1b) | |
| Need a worktree location | Use <repo>/.worktrees/<branch> | |
| Directory not ignored | Add to .gitignore + commit | |
| Permission error on create | Sandbox fallback, work in place | |
| Tests fail during baseline | Report failures + ask | |
| No package.json/Cargo.toml | Skip dependency install | |
| Work complete, in linked worktree | Run Step 5 cleanup | |
| Never created a worktree | Skip Step 5 | |
| Uncommitted/unpushed changes at cleanup | Stop and ask user | |
| Native cleanup tool available | Use it (Step 5.2) | |
| No native cleanup tool | git worktree remove (Step 5.3) | |
| Worktree directory deleted manually | git worktree prune | |
| Git fallback: clone Claude behavior into worktree | Copy .claude/settings*.json from SOURCE_ROOT (Step 1b) | |
Repo uses .claude symlinks | Copy JSON only is not enough—recreate symlinks or paths |
Common Mistakes
Fighting the harness
- Problem: Using
git worktree addwhen the platform already provides isolation - Fix: Step 0 detects existing isolation. Step 1a defers to native tools.
Skipping detection
- Problem: Creating a nested worktree inside an existing one
- Fix: Always run Step 0 before creating anything
Skipping ignore verification
- Problem: Worktree contents get tracked, pollute git status
- Fix: Always use
git check-ignorebefore creating project-local worktree
Assuming directory location
- Problem: Creates inconsistency, violates project conventions
- Fix: Always use
<repo>/.worktrees/<branch>unless user explicitly overrides for one task
Proceeding with failing tests
- Problem: Can't distinguish new bugs from pre-existing issues
- Fix: Report failures, get explicit permission to proceed
Removing a worktree with unsaved work
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/git-worktrees-use/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/dariopalminio/agile-sddf-extension/git-worktrees-use)