ce-worktree
everyinc/compound-engineering-plugin
Configurez des worktrees git isolés. Utilisez cette option lorsque vous démarrez un travail isolé, ou lorsque ce-worktree/ce-code-review propose une option de worktree ; détectez d’abord l’isolation existante.
...Développer toutÀ propos de ce-worktree
L'isolation des worktrees gère la configuration de worktrees git isolés afin que le travail puisse se poursuivre sans perturber le répertoire de travail principal de l'utilisateur. Étant donné que la plupart des environnements de développement créent déjà un worktree au début de la session, le rôle principal de cette compétence est de détecter une isolation existante avant de créer quoi que ce soit de redondant. Elle suit un ordre strict des opérations : détecter une isolation existante, privilégier un outil de worktree natif, puis revenir à git standard uniquement lorsque ni l'un ni l'autre ne s'applique.
La détection consiste à comparer le répertoire git absolu résolu avec le répertoire git commun absolu résolu. Comme git utilise des formes de chemins absolus et relatifs en fonction du répertoire courant, la compétence résout d'abord chaque chemin en un chemin absolu plutôt que d'effectuer une comparaison brute de chaînes, ce qui donnerait autrement un résultat faux indiquant une « isolation déjà existante ». Lorsque ces deux chemins diffèrent, elle distingue un worktree lié d'un sous-module en utilisant la vérification de l'arbre de travail du super-projet, et travaille sur place lorsqu'elle se trouve déjà à l'intérieur d'un worktree isolé. Lorsqu'un primitif de worktree natif existe (tel qu'un outil EnterWorktree, une commande /worktree ou un drapeau --worktree), elle l'utilise et s'arrête, car l'ajout d'un worktree git effectué en arrière-plan crée un état fantôme que l'environnement de développement ne peut ni voir ni nettoyer.
Le recours à git s'exécute depuis la racine du dépôt, choisit un nom de branche significatif dérivé de la description du travail, s'assure que .worktrees/ est ignoré par git (en vérifiant avec un slash final afin que les règles ne concernant que les répertoires soient respectées), effectue une tentative de récupération non fatale de la branche de base, crée le worktree sous .worktrees/
FAQ
Pourquoi la compétence vérifie-t-elle l'isolation existante avant de créer un worktree ?
La plupart des environnements de développement créent déjà un worktree par défaut au début de la session, de sorte que le cas courant est que l'isolation existe déjà. Créer un autre worktree à partir de l'intérieur d'un worktree existant conduit dans le mauvais arbre et reste invisible pour l'environnement de développement qui a créé le worktree actuel.
Comment évite-t-elle un résultat faux indiquant « déjà isolé » lors de la détection ?
Elle résout d'abord le répertoire git et le répertoire git commun en chemins absolus, puis les compare, au lieu d'effectuer une comparaison brute de chaînes. Git renvoie des formes absolues et relatives mélangées en fonction du répertoire courant, ce qui produirait autrement un faux positif.
Quand faut-il utiliser l'outil de worktree natif au lieu de git standard ?
Chaque fois que l'environnement de développement fournit un primitif natif tel qu'un outil EnterWorktree/WorktreeCreate, une commande /worktree ou un drapeau --worktree, la compétence l'utilise et s'arrête. Les outils natifs placent, suivent et nettoient le worktree afin que l'environnement de développement puisse le gérer ; un ajout de worktree git effectué en arrière-plan crée un état fantôme que l'environnement de développement ne peut pas voir.
Que se passe-t-il si l'ajout de worktree git échoue avec une erreur de permission ou de bac à sable ?
L'échec nécessite une décision utilisateur bloquante avant de toucher au répertoire de travail actuel. La compétence signale l'erreur et demande à l'utilisateur via l'outil de questionnement de la plateforme (par exemple AskUserQuestion dans Claude Code), en proposant des options telles que travailler dans le répertoire de travail actuel ou arrêter pour résoudre le problème, et ne poursuit dans le répertoire principal qu'après confirmation explicite.
Comment la compétence empêche-t-elle la validation du contenu des worktrees ?
Avant de créer quoi que ce soit, elle vérifie que .worktrees/ est ignoré par git en exécutant git check-ignore avec un slash final, de sorte qu'une règle existante ne concernant que les répertoires soit respectée même avant la création du répertoire, et ajoute une ligne .worktrees/ à .gitignore si nécessaire.
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-workandce-code-reviewuse 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.
- 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.gitignoreedit land in a subdirectory (e.g.src/.worktrees/...). - 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, elsemain. - 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. - Refresh the base with
git fetch origin <from-branch>. This is non-fatal — nooriginremote, a differently-named remote, or a local-only branch is not an abort; continue with the local ref. - 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 iforigin/<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>thengit worktree add .worktrees/pr-<n> pr-<n>. Never a detachedFETCH_HEAD: that orphans the fix loop's commits instead of updating the PR. (For push-tracking back to the PR, create it detached —git worktree add --detach .worktrees/pr-<n>— thencdin and rungh pr checkout <n>, which is fork-safe.) - If git reports the ref is already checked out elsewhere, apply the one-branch-one-worktree rule above — do not force a second worktree.
- New work:
cdinto it, then report the path and branch.
If git worktree add fails with a sandbox or permission error, the requested isolation does not exist. Do not proceed in the current checkout — the user chose isolation specifically to avoid it. Report the failure and ask, offering options such as "work in the current checkout" vs "stop and resolve the permission issue", using the platform's blocking question tool: AskUserQuestion in Claude Code (call ToolSearch with select:AskUserQuestion first if its schema isn't loaded), request_user_input in Codex, ask_question in Antigravity CLI (agy), ask_user in Pi (via the pi-ask-user extension). Only when no blocking tool exists in the harness or the call errors, present the numbered options in chat and wait for the reply. Never skip the confirmation, and do not retry alternative paths automatically.
Tous les fichiers
0 fichiersInstaller ce-worktree
Téléchargez et extrayez les fichiers de compétences dans votre répertoire .claude/skills/.
Télécharger le ZIPClonez le dépôt et copiez les fichiers de compétence dans votre projet.
git clone https://github.com/EveryInc/compound-engineering-plugin/blob/main/skills/ce-worktree/SKILL.md # Copy SKILL.md to your .claude/skills/ directory
Copier





Maison
