From worktree
This skill should be used for managing git worktrees when users need to work on multiple branches simultaneously, create isolated environments for experiments, or safely merge and clean up parallel development work. Uses the crewchief worktree CLI.
npx claudepluginhub manifoldlogic/claude-code-plugins --plugin worktreeThis skill uses the workspace's default tool permissions.
Git worktrees enable working on multiple branches simultaneously by creating separate working directories that share the same repository. The crewchief worktree CLI streamlines this workflow with automated branch creation, environment setup (copying ignored files like `.env`), safe merging, and cleanup operations.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Checks Next.js compilation errors using a running Turbopack dev server after code edits. Fixes actionable issues before reporting complete. Replaces `next build`.
Git worktrees enable working on multiple branches simultaneously by creating separate working directories that share the same repository. The crewchief worktree CLI streamlines this workflow with automated branch creation, environment setup (copying ignored files like .env), safe merging, and cleanup operations.
Unlike traditional branch switching (git checkout), worktrees provide:
The worktree workflow consists of five phases:
Create a new worktree with a dedicated branch:
Naming: Always use the user's exact input as the worktree/branch name. Do not add prefixes, suffixes, or modify the name in any way. If the user says "create worktree PANE-001", the name is PANE-001.
crewchief worktree create feature-x
This operation:
.env, node_modules/.bin, etc.) based on configSwitch to an existing worktree:
# Print path (for scripting)
cd $(crewchief worktree use feature-x)
# Open interactive subshell
crewchief worktree use feature-x --shell
The --shell option spawns an interactive shell in the worktree directory. Type exit to return to your original location.
Make changes and commit normally within the worktree:
# Worktree is a regular git checkout
git add .
git commit -m "Implement feature"
git push origin feature-x
Worktrees function as standard git working directories with full git command support.
Merge changes back to the source branch and clean up:
crewchief worktree merge feature-x
This operation:
Important: You must run this command from outside the worktree being merged.
Remove a worktree without merging:
# Remove worktree and branch
crewchief worktree clean feature-x
# Keep branch, remove worktree only
crewchief worktree clean feature-x --keep-branch
# Remove all worktrees except current
crewchief worktree clean --all
Use --keep-branch to preserve work for later use. The worktree directory is removed, but the branch remains available for future checkout.
The CLI prevents removing the worktree you're currently working in:
Error: Refusing to remove the current working tree.
Switch to another directory and try again.
Solution: Navigate to a different directory (typically the main repository) before running clean.
Merging must be performed from outside the target worktree:
Error: Cannot merge a worktree while inside it.
Please switch to the main repository first.
Solution: Exit the worktree (if using --shell, type exit), then run the merge command.
Git protects unmerged work by refusing to delete branches that haven't been merged:
Branch feature-x not fully merged - skipped deletion
To delete anyway (CAUTION: may lose work):
git branch -D feature-x
Or merge the branch first:
git checkout main && git merge feature-x
Solution: Either merge the branch first, or use git branch -D to force delete if you're certain the work should be discarded.
The merge operation fails if the working tree has uncommitted changes:
Error: Working tree has uncommitted changes.
Commit or stash them before merging.
Solution: Commit or stash changes in your current working directory before merging.
crewchief worktree create <name> [options]
Options:
--branch <base> Base branch to create from (default: main)
--shell Start interactive subshell after creating
--no-copy-ignored Skip copying ignored files (override config)
Examples:
# Create and print path
cd $(crewchief worktree create feature-x)
# Create and open subshell
crewchief worktree create feature-x --shell
# Create from specific branch
cd $(crewchief worktree create hotfix --branch release-1.0)
crewchief worktree list
Displays all active worktrees with their paths, branches, and agent status (if applicable).
crewchief worktree use <name> [options]
Options:
--shell Start interactive subshell in worktree
-p, --print Print absolute path (default behavior)
Examples:
# Switch to worktree (prints path)
cd $(crewchief worktree use feature-x)
# Open worktree in subshell
crewchief worktree use feature-x --shell
# Use in scripts
path=$(crewchief worktree use my-branch)
code "$path"
crewchief worktree clean [selector] [options]
Options:
--all Remove all non-current worktrees
--keep-branch Keep git branch after removing worktree
--keep-maproom Skip maproom database cleanup
Examples:
# Remove specific worktree
crewchief worktree clean feature-x
# Keep branch for later use
crewchief worktree clean feature-x --keep-branch
# Remove all worktrees except current
crewchief worktree clean --all
crewchief worktree merge <name> [options]
Options:
--strategy <type> Merge strategy: ff, squash, cherry-pick (default: ff)
--no-delete Keep worktree after merging
--dry-run Show what would be done without making changes
--no-copy-ignored Skip copying ignored files back to source
--message <msg> Custom commit message
-y, --yes Skip confirmation prompts
Examples:
# Standard merge with fast-forward
crewchief worktree merge feature-x
# Squash commits into single commit
crewchief worktree merge feature-x --strategy squash
# Preview merge without executing
crewchief worktree merge feature-x --dry-run
# Merge but keep worktree
crewchief worktree merge feature-x --no-delete
crewchief worktree copy-ignored <selector> [options]
Options:
--dry-run Show what would be copied without copying
--no-copy-ignored Override config and skip copying
Manually copy ignored files to a worktree based on worktree.copyIgnoredFiles config. This is automatically called during create unless --no-copy-ignored is specified.
Complete lifecycle from creation to merge:
# Create feature worktree
crewchief worktree create feature-auth --shell
# Work in the worktree
git add src/auth.ts
git commit -m "Add authentication module"
git push origin feature-auth
# Exit subshell
exit
# Merge back to main
crewchief worktree merge feature-auth
This workflow:
Try something without committing to it:
# Create experimental worktree
crewchief worktree create experiment --shell
# Try changes
npm install experimental-package
# ... test it out ...
# Exit and discard
exit
crewchief worktree clean experiment
Use this for:
Work on multiple features simultaneously:
# Create multiple worktrees
crewchief worktree create feature-a
crewchief worktree create feature-b
# Terminal 1: Work on feature A
cd $(crewchief worktree use feature-a)
npm run dev
# Terminal 2: Work on feature B
cd $(crewchief worktree use feature-b)
npm test
# Merge when ready
crewchief worktree merge feature-a
crewchief worktree merge feature-b
Benefits:
Check out a PR for review without disrupting current work:
# Create worktree from PR branch
crewchief worktree create review-pr-123 --branch feature-branch --shell
# Review, test, leave comments
npm test
npm run lint
# Clean up after review
exit
crewchief worktree clean review-pr-123
Keep the branch but remove the worktree:
# Clean worktree but preserve branch
crewchief worktree clean experiment --keep-branch
# Later, recreate worktree from existing branch
crewchief worktree create experiment --branch experiment
Use when:
Error: Worktree 'feature-x' not found.
Create it with: crewchief worktree create feature-x
Solution: The worktree doesn't exist. Create it first or check the name with crewchief worktree list.
Error: Ambiguous selector 'feat'. Candidates:
/path/to/feature-a [feature-a]
/path/to/feature-b [feature-b]
Solution: Use a more specific selector (full branch name or unique path component).
Warning: No commits to merge from this worktree
Do you want to remove this worktree anyway?
Solution: This occurs when the worktree branch has no commits beyond the base branch. Confirm cleanup or cancel if commits are expected.
Error: Merge failed: Merge conflict in src/app.ts
Solution: Merge conflicts require manual resolution:
git merge --continuecrewchief worktree clean feature-x --keep-branchWarning: Maproom binary not found - database cleanup skipped
Install maproom or run: maproom db cleanup-stale --confirm
Solution: Maproom cleanup is best-effort. If the binary isn't available, clean up manually:
maproom db cleanup-stale --confirm
Common maproom cleanup issues:
--keep-maproomError: Branch 'feature-x' already exists
Solution: Either:
crewchief worktree create feature-x --branch feature-xgit branch -d feature-xFor CLI implementation details and advanced usage:
packages/cli/src/cli/worktree.tscrewchief.config.js (worktree.copyIgnoredFiles)crewchief worktree --help