mcpbeat Sign in

Using Git Worktrees Skill for Claude

Use this whenever you need to create an isolated workspace.

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
4940
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/microsoft/FluidFramework --skill using-git-worktrees

What it tells the agent to use

found in the instruction text
Bash runs shell commands — read the instruction before connecting

The instruction itself

5 sections, as written by the author

<required>

*CRITICAL* Add the following steps to your Todo list using TodoWrite:

  • Find the worktrees directory.
  • Check existing directories using the Bash tool: ls -d .worktrees 2>/dev/null
  • If not found, ask me for permission to create a .worktrees directory
  • If given permission, create .worktrees.
  • Verify .gitignore before creating a worktree using the Bash tool:
# Check if directory pattern in .gitignore
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore
  • If not found, add the appropriate line to the .gitignore immediately.
  • Create the worktree
  • Come up with a good branch name based on the request.
  • Create the worktree with the Bash tool: `git worktree add ".worktrees/$BRANCH_NAME" -b "$BRANCH_NAME"
  • cd into the newly created path with the Bash tool: cd $path
  • Auto-detect and run project setup.
# Node.js
if [ -f package.json ]; then npm install; fi

# Rust
if [ -f Cargo.toml ]; then cargo build; fi

# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

# Go
if [ -f go.mod ]; then go mod download; fi
  • If there is no obvious project setup, you _MUST_ ask me.
  • Run tests to ensure the worktree is clean.
# Examples - use project-appropriate command
npm test
cargo test
pytest
go test ./...

If tests fail: Report failures, ask whether to proceed or investigate.

If tests pass: Report ready.

  • Report Location
New working directory: <full-path>
Tests passing (<N> tests, 0 failures)
All commands and tools will now refer to: <full-path>
  • Understand that you are now in a new working directory. Your Bash tool instructions from here on out should refer to the worktree directory, NOT your original directory. This is ABSOLUTELY CRITICAL.

</required>

Maintaining Working Directory in Worktree

CRITICAL: Once you create and enter a worktree, you must stay within

it for the entire session.

Rules:

  • Never use cd .. from within a worktree - It will eventually take

you outside the worktree boundary

  • Always use absolute paths for commands - Use npm run lint from

within the worktree, not cd .. && npm run lint

  • If you need to run root-level commands, use the full worktree path:

<bad-example>

cd .. && npm run lint

</bad-example>

<good-example>

npm run lint # (from worktree root)

</good-example>

<good-example>

cd /home/$USER/code/project/.worktrees/branch-name && npm run lint

</good-example>

  • Verify your location frequently:
pwd  # Should show .worktrees/branch-name in path
git branch  # Should show * on your feature branch, not main
  • If you accidentally exit the worktree:
  • Immediately recognize it (check if you're on main branch)
  • Navigate back: cd /full/path/to/.worktrees/your-branch
  • Verify: git branch should show your branch, not main

Red Flags:

  • Running git status and seeing "On branch main" when you should be on a feature branch
  • Running pwd and NOT seeing .worktrees/ in the path
  • Any cd .. command while in a worktree

Quick Reference

| Situation | Action |

| --------------------------- | -------------------------- |

| .worktrees/ exists | Use it (verify .gitignore) |

| `.worktree/s does not exist | Check CLAUDE.md → Ask user |

| Directory not in .gitignore | Add it immediately |

| Tests fail during baseline | Report failures + ask |

| No package.json/Cargo.toml | Skip dependency install |

Common Mistakes

Skipping .gitignore verification

  • Problem: Worktree contents get tracked, pollute git status
  • Fix: Always grep .gitignore before creating project-local worktree

Assuming directory location

  • Problem: Creates inconsistency, violates project conventions
  • Fix: Follow priority: existing > CLAUDE.md > ask

Missing project installation

  • Problem: Tests and lint will fail, breaking the project
  • Fix: Always install the project when creating a new worktree

Proceeding with failing tests

  • Problem: Can't distinguish new bugs from pre-existing issues
  • Fix: Report failures, get explicit permission to proceed

Hardcoding setup commands

  • Problem: Breaks on projects using different tools
  • Fix: Auto-detect from project files (package.json, etc.)

Example Workflow

You: I'm using the Using Git Worktrees skill to set up an isolated workspace.

[Check .worktrees/ - exists]
[Verify .gitignore - contains .worktrees/]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]

Worktree ready at myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth feature

Red Flags

Never:

  • Create worktree without .gitignore verification (project-local)
  • Skip baseline test verification
  • Proceed with failing tests without asking
  • Assume directory location when ambiguous
  • Skip CLAUDE.md check

Always:

  • Follow directory priority: existing > CLAUDE.md > ask
  • Verify .gitignore for project-local
  • Auto-detect and run project setup
  • Verify clean test baseline

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

30k tokens scripts
Changelog Generator
by frostant
×9

Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
MCP Builder
by JayZeeDesign
×7

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

39k tokens
Vercel React Best Practices
by ratacat
×5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification

1k tokens

How to use it

Copy the folder

Take microsoft/using-git-worktrees from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.

Install what it needs

The instructions reference pip, npm. Without those the skill loads but fails at the first command.