Skip to content
Skillpedia
General coding26k Β· #10052

ce-worktree

What it does

It creates an isolated workspace on a new or existing branch, so your main folder stays as it is. It is for developers who work on several tasks in one repository.

When to use it

  • βœ“When you start new work and want it kept apart from your main checkout.
  • βœ“When you want to check out a pull request or commit in its own folder.
  • βœ“When a branch is already checked out somewhere, it reports that location instead of creating a second copy.

Skill link

https://github.com/EveryInc/compound-engineering-plugin/blob/main/skills/ce-worktree/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/EveryInc/compound-engineering-plugin/blob/main/skills/ce-worktree/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œSet up a separate workspace for this feature so my main folder stays untouched.”

5 new skills a week. 1 minute to read.

How it works

It first checks whether the work is already isolated, then uses the built-in worktree tool or plain git to create the new workspace, and reports its path and branch.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Worktree Isolation

Ensure the current work happens in an isolated workspace, without disturbing the user's main checkout. Most coding harnesses now create a worktree by default at session start, so the common case is that isolation already exists.

Done when: the caller is working in an isolated tree β€” existing or newly created β€” and its path and branch have been reported, or a blocker has been reported instead.

Order of operations: detect existing isolation -> prefer a native worktree tool -> fall back to plain git. Never create a worktree the harness cannot see.

Two modes, set by the caller's need:

  • New work (default). No ref named β€” create a fresh branch from a base (trunk). This is what ce-work and ce-code-review use when the user picks the worktree option.
  • Isolate an existing ref. The caller names a PR head, branch, or commit β€” attach the worktree to that ref instead of creating a new branch. A branch can be checked out in only one worktree at a time. If the named ref is already checked out anywhere (most commonly as the primary checkout's current branch), do not create a second worktree β€” report that it is already checked out at <path> and let the caller act (work there in place; or, only if a clean separate tree is essential, create a detached worktree at the same commit).

Step 0: Detect existing isolation

Compare the resolved absolute git dir against the resolved absolute common git dir. Git mixes absolute and relative forms depending on the current directory (from a subdirectory of a normal checkout, --git-dir comes back absolute while --git-common-dir may be relative), so a raw string compare yields a false "already isolated":

git rev-parse --absolute-git-dir                     # absolute git dir for this worktree
(cd "$(git rev-parse --git-common-dir)" && pwd -P)   # absolute shared (common) git dir

Equal -> normal checkout; continue to Step 1.

Different -> a linked worktree or a submodule. Distinguish with git rev-parse --show-superproject-working-tree:

  • Non-empty -> submodule; treat it as a normal checkout and continue to Step 1.
  • Empty -> already isolated. Report the worktree path (git rev-parse --show-toplevel) and current branch, then work in place β€” a worktree-from-worktree lands in the wrong tree and is invisible to the harness that made the current one. In isolate-an-existing-ref mode, check that ref out here (unless it is already current) rather than nesting a worktree.

Step 1: Prefer the harness's native worktree tool

If the harness provides a native worktree primitive β€” for example an EnterWorktree / WorktreeCreate tool, a /worktree command, or a --worktree flag β€” use it and stop. Native tools place, track, and clean up the worktree so the harness can manage it. A behind-the-back git worktree add creates phantom state the harness cannot see, navigate to, or clean up.

Step 2: Git fallback

Only when there is no native tool and Step 0 found no existing isolation.

  1. Run from the repo root: cd "$(git rev-parse --show-toplevel)". The paths below are repo-root-relative, but the skill runs from the user's current directory β€” without this, .worktrees/<branch> and the .gitignore edit land in a subdirectory (e.g. src/.worktrees/...).
  2. Choose a meaningful branch name from the work description (e.g. feat/login, fix/email-validation) β€” never an opaque auto-generated one. Base: origin's default branch, else main.
  3. Ensure .worktrees/ is gitignored before creating anything: git check-ignore -q .worktrees/ β€” with the trailing slash, so an existing directory-only .worktrees/ rule is honored even before the directory exists (without the slash the probe misses it and dirties a correctly-configured repo). Not ignored -> add a .worktrees/ line to .gitignore.
  4. Refresh the base with git fetch origin <from-branch>. This is non-fatal β€” no origin remote, a differently-named remote, or a local-only branch is not an abort; continue with the local ref.
  5. Create the worktree, per mode:
    • New work: git worktree add -b <branch-name> .worktrees/<branch-name> origin/<from-branch> (use the local <from-branch> ref if origin/<from-branch> does not exist).
    • Existing branch or tag: git worktree add .worktrees/<slug> <target-ref>.
    • PR: check it out on a local branch β€” git fetch origin pull/<n>/head:pr-<n> then `
FAQ

Will this change my main checkout?

No. It is designed to avoid disturbing your main checkout.

Can it attach to an existing pull request branch?

Yes. It can attach a worktree to an existing branch, pull request, or commit.

What if the branch is already in use?

It tells you where the branch is checked out, and you decide what to do next.

Details

Original description by the author

Set up isolated git worktrees β€” create a new branch for fresh work, or attach a worktree to an existing branch, PR, or commit. Use when starting isolated work or isolating an existing ref.

repo: EveryInc/compound-engineering-plugin

Popularity

GitHub stars
26k
Ranking position
#10052
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills