Agent skill

Using Git Worktrees

by GanyuanRan in GanyuanRan/Aegis

A skill your agent uses when a coding task needs a concurrent checkout, unrelated dirty state blocks safe branch switching, or the user or repository explicitly requires a worktree.

MITAuto-check passedDevelopment

Install Using Git Worktrees

skills CLI
$ npx skills add GanyuanRan/Aegis --skill using-git-worktrees -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install GanyuanRan/Aegis using-git-worktrees --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/GanyuanRan/Aegis.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/using-git-worktrees .claude/skills/using-git-worktrees && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
using-git-worktrees
GitHub stars
1.3k
Used in
1 other repo
Token cost
~1.9k tokens
SKILL.md length
1,031 words
Files
1
Skills in repo
21
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when a coding task needs a concurrent checkout, unrelated dirty state blocks safe branch switching, or the user or repository explicitly requires a worktree.

  • Works in 6 steps: Environment Detection → Necessity Decision → Safe Placement → …
  • A coding task needs a concurrent checkout
  • SKILL.md covers Overview, Step 0: Environment Detection, Step 1: Necessity Decision and Step 2: Safe Placement, plus 5 more sections
  • Calls git, npm and cargo

What it does

Using Git Worktrees is an agent skill from GanyuanRan/Aegis. Use when a coding task needs a concurrent checkout, unrelated dirty state blocks safe branch switching, or the user or repository explicitly requires a worktree.

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Git worktrees. The repository describes itself as: Make AI coding agents architecture-aware: baseline-first, evidence-verified, drift-checked, and safe across long tasks. The licence is MIT.

When your agent uses it

  • A coding task needs a concurrent checkout
  • Unrelated dirty state blocks safe branch switching
  • Repository explicitly requires a worktree

Example prompts

  • “/using-git-worktrees”

Requirements

  • Python 3
  • Node.js

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Environment Detection
  2. Necessity Decision
  3. Safe Placement
  4. Create the Minimum Checkout
  5. Authority-Led Setup and Baseline
  6. Handoff and Cleanup Ownership

What it can do on your machine

Read from SKILL.md and the folder at commit 4edf34e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git
    • npm
    • cargo
    • pip
    • poetry

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, npm and pip, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Using Git Worktrees loads about 1.9k tokens when it runs. Until then it costs about 45 tokens; SKILL.md has 1,031 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~45
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from GanyuanRan/Aegis at commit 4edf34e, republished under its MIT licence (© GanyuanRan). 1,031 words, ~1,945 tokens.

Download SKILL.mdSave it as .claude/skills/using-git-worktrees/SKILL.md (or your agent's skills folder).
name
using-git-worktrees
description
Use when a coding task needs a concurrent checkout, unrelated dirty state blocks safe branch switching, or the user or repository explicitly requires a worktree.

Using Git Worktrees

Overview

A worktree is an exception for simultaneously checking out another Git history, not a general safety badge. Prefer the current workspace and reuse an existing suitable worktree. A branch decision and a worktree decision are separate.

Core principle: create only with necessity and ownership evidence; pair every created worktree with a cleanup path.

Announce at start: explain which concrete checkout conflict requires a worktree.

Step 0: Environment Detection

Before mutation, record the repository root, HEAD, branch/detached state, staged/unstaged/untracked paths, active Git operations, and:

bash
git worktree list --porcelain

Classify the current host surface's task/chat-bound managed workspace semantics as managed, non-managed, or unknown. Use trusted host/session context, an explicit host contract, or a host-native lifecycle result; do not infer the classification from a product name, directory prefix, command-level workdir, missing tool, or absent metadata. non-managed requires positive evidence that the current surface lacks task-bound managed semantics. When the host exposes workspace fields, record the task workspace and the command's default cwd without a per-command directory override.

Stop on unresolved conflicts, an active merge/rebase/cherry-pick/revert/bisect, or an unexplained detached HEAD. A detached HEAD is acceptable only when trusted host binding evidence identifies it as the intended state of the current managed worktree; Codex-managed worktrees, for example, start detached by default. Preserve user state: no automatic stash, reset, clean, broad staging, or commit.

Before deciding necessity or placement, read the smallest relevant project AGENTS.md, CLAUDE.md, current authority, and existing worktree convention. Repository policy may require or forbid isolation and owns any approved in-repo location; do not discover that policy after creating the checkout.

Step 1: Necessity Decision

Create at most one task-owned worktree only when one of these is true:

  • another branch must remain checked out while this task proceeds;
  • unrelated dirty state prevents a safe checkout in the current workspace;
  • explicit user or current repository authority requires it.

Task complexity, planning, TDD, use of subagents, or a main/master branch name is not sufficient. Same-task subagents share one workspace; do not create per-subagent or nested worktrees. If independent history is unnecessary, do not create a branch either.

Record: reason, branch, exact path, creating coordinator, and expected cleanup event. If the owner or cleanup condition is unknown, stop before creation.

Step 2: Safe Placement

Use an existing repository convention only when the target directory is already ignored (git check-ignore). Never edit or commit .gitignore solely to host a worktree. If no safe in-repo convention exists, use a task-specific external user-level temporary directory outside the repository. Resolve and verify the exact path before creation; do not target a broad home, workspace, or repo root.

Step 3: Create the Minimum Checkout

Prefer reusing an existing branch carrying the same goal. Create a branch only when the approved Git lifecycle requires independent history.

Managed-host binding gate

When the host surface declares task/chat-bound managed workspaces, use its native Worktree/Handoff lifecycle instead of shell creation. Reuse the current task only when trusted host evidence says it is already bound to the intended workspace. If the native operation creates or moves work into another task, continue only in that bound task.

After the native lifecycle operation, or immediately when entering/reusing an already-bound managed workspace, and before the first task content or Git history write, read back one joint postcondition:

  • trusted task workspace;
  • default command cwd without a command-level directory override;
  • intended Git worktree root;
  • intended HEAD and branch/detached state.

All four must describe the same execution environment. git worktree list, a managed-looking path, or a per-command workdir proves only part of that postcondition. If native creation/handoff is unavailable, only UI-driven, or cannot be verified, stop before shell worktree creation or task content/history writes and give the user the host-native re-entry action. Do not silently fall back on git worktree add. Compare resolved path identity using host-appropriate semantics, not raw path strings. The default cwd may equal the worktree root or be inside it; running Git from that default cwd must resolve to the intended worktree root. An intended host-managed detached HEAD satisfies the Git-state component; do not create a branch merely to make that state look like a generic checkout.

If an unbound manual worktree already exists, preserve it and report its exact path, HEAD, branch, status, and ownership evidence. Dirty, untracked, or ownership-unknown state is not auto-migrated, deleted, stashed, reset, or overwritten. A later commit/patch transfer follows normal Git authorization and must be verified in the new bound task before cleanup is offered.

Show full SKILL.md (299 more words)Show less
Generic Git fallback

Use the shell path below only when trusted evidence positively classifies the current host/CLI surface as non-managed. An unknown classification fails closed; an absent native tool or missing binding metadata is not generic-fallback evidence.

bash
# Existing branch
git worktree add <exact-path> <branch>

# New independently justified branch
git worktree add -b <branch> <exact-path> <start-point>

Read back git worktree list --porcelain, the new worktree's HEAD/branch, and its status. Do not use force flags. A command-level workdir may target this checkout on a generic host, but it never proves managed task binding.

Step 4: Authority-Led Setup and Baseline

Read the project's install docs, lockfiles, and existing setup scripts. Run only setup the project explicitly requires. Do not infer npm install, cargo build, pip install, poetry install, or dependency downloads merely from manifest presence.

Run the smallest relevant baseline verification. If setup or tests fail, report the exact failure and preserve the worktree; do not hide it by mutating unrelated files.

Step 5: Handoff and Cleanup Ownership

Report the exact path, branch, start HEAD, baseline result, owner, and cleanup trigger. The creating coordinator remains responsible until it proves cleanup or explicitly hands ownership off.

Use finishing-a-development-branch after the task commit or integration decision. A worktree may usually be removed while its unmerged branch remains; an open PR does not require a permanent checkout.

Red Flags

Never:

  • create a worktree only because a task modifies code;
  • modify .gitignore merely to make worktree creation possible;
  • install dependencies blindly;
  • create one worktree per subagent;
  • treat Git readback, a path prefix, or command-level workdir as proof of managed task binding;
  • use shell worktree creation merely because a host-native capability is deferred, UI-only, or absent from the initial tool list;
  • run global prune or force cleanup as routine hygiene;
  • remove dirty, untracked, locked, user-owned, or ownership-unknown resources.

Integration

Called conditionally by planning/execution workflows only after the necessity decision. Pairs with finishing-a-development-branch for evidence-led cleanup.

© GanyuanRan, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/using-git-worktrees of GanyuanRan/Aegis.

Open the folder on GitHubat commit 4edf34e

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in GanyuanRan/Aegis, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Using Git Worktrees next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Using Git Worktrees compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Using Git Worktrees this skillGanyuanRan/Aegis1.3k1 repos~1.9kAutomated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman41k—~2.6kAutomated safety check: PassGPL-3.0
Nagentdavidondrej/skills4.1k—~1.7kAutomated safety check: NotesMIT
Git Worktree IsolationjnMetaCode/superpowers-zh8.3k1 repos~982Automated safety check: PassMIT
WorktreeAgentsMesh/AgentsMesh2.4k—~553Automated safety check: NotesCustom licence
Cursor Composer Task DelegateChachamaru127/claude-code-harness3.2k—~4.4kAutomated safety check: NotesMIT

Similar skills

  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    41k GitHub stars~2.6k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Nagent

    davidondrej/skills

    Launch a new bb worker thread with the right project, model, worktree, and task brief.

    4.1k GitHub stars~1.7k tokensUpdated yesterday
    DevelopmentAuto-check: notes
  • Git Worktree Isolation

    jnMetaCode/superpowers-zh

    Sets up an isolated workspace before feature work or plan execution, preferring native worktree tools and falling back to git worktree, with instructions in Chinese.

    8.3k GitHub starsUsed in 1 repo~982 tokens
    DevelopmentAuto-check passed
  • Worktree

    AgentsMesh/AgentsMesh

    Creates or reuses an isolated AgentsMesh Git worktree from a verified base branch, preserves existing changes, and optionally starts the worktree-scoped development environment.

    2.4k GitHub stars~553 tokensUpdated 14 days ago
    DevelopmentAuto-check: notes
  • Cursor Composer Task Delegate

    Chachamaru127/claude-code-harness

    Hands one implementation task to Cursor Composer in an isolated git worktree, then reviews its diff and cherry-picks the result into the main branch.

    3.2k GitHub stars~4.4k tokensUpdated 2 days ago
    DevelopmentAuto-check: notes
  • Automate git worktree creation and copy private files (not tracked in git) to new workdirs.

    155 GitHub stars~930 tokensUpdated 3 mo ago
    DevelopmentAuto-check passed

More from GanyuanRan/Aegis

All 21 skills in this repo
  • Anti Entropy Governance

    GanyuanRan/Aegis

    A skill your agent uses when touching retiring old logic, collapsing duplicate owners, removing fallbacks, or schema/persistence/source-of-truth boundaries; identify opportunities automatically…

    1.3k GitHub starsUsed in 1 repo~3.1k tokens
    Auto-check passed
  • Executing Plans

    GanyuanRan/Aegis

    A skill your agent uses when executing a written implementation plan across sessions or with review checkpoints.

    1.3k GitHub starsUsed in 1 repo~2.3k tokens
    Auto-check passed
  • First Principles Review

    GanyuanRan/Aegis

    A skill your agent uses when asked for first-principles or Occam's-razor review, or when high-risk decisions involve competing constraints, fallback growth, duplicate owners, or architecture…

    1.3k GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • Goal Framing

    GanyuanRan/Aegis

    A skill your agent uses when the user explicitly sets an Aegis goal with /aegis-goal, Aegis goal:, or asks to define goal, success evidence, stop condition, or task boundaries before work.

    1.3k GitHub starsUsed in 1 repo~1.2k tokens
    Auto-check passed
  • A skill your agent uses when the user asks to establish shared project language, or project work exposes a conflicting, renamed, or deprecated domain term that needs active semantic modeling.

    1.3k GitHub starsUsed in 1 repo~1.5k tokens
    Auto-check: warnings
  • A skill your agent uses when the user asks to create, write, update, amend, supersede, or evaluate an ADR, architecture decision record, durable architecture decision, decision log, or baseline sync…

    1.3k GitHub starsUsed in 1 repo~1.5k tokens
    Auto-check passed

Questions about Using Git Worktrees

What does Using Git Worktrees do?

A skill your agent uses when a coding task needs a concurrent checkout, unrelated dirty state blocks safe branch switching, or the user or repository explicitly requires a worktree. Using Git Worktrees is an agent skill from GanyuanRan/Aegis. Use when a coding task needs a concurrent checkout, unrelated dirty state blocks safe branch switching, or the user or repository explicitly requires a worktree.

When should I use Using Git Worktrees?

Using Git Worktrees fits situations like: A coding task needs a concurrent checkout; unrelated dirty state blocks safe branch switching; repository explicitly requires a worktree.

How do I install Using Git Worktrees in Claude Code?

Run `npx skills add GanyuanRan/Aegis --skill using-git-worktrees -a claude-code`. Or copy the skill folder (skills/using-git-worktrees in GanyuanRan/Aegis) into .claude/skills/using-git-worktrees in your project. Claude Code loads it when a task matches its description.

How do I install Using Git Worktrees in Codex?

Run `npx skills add GanyuanRan/Aegis --skill using-git-worktrees -a codex`. Or copy the skill folder (skills/using-git-worktrees in GanyuanRan/Aegis) into .agents/skills/using-git-worktrees in your project. Codex loads it when a task matches its description.

Can I use Using Git Worktrees in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add GanyuanRan/Aegis --skill using-git-worktrees -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/using-git-worktrees, .gemini/skills/using-git-worktrees, .github/skills/using-git-worktrees and .opencode/skills/using-git-worktrees in your project.

What does Using Git Worktrees need to run?

Going by SKILL.md and its folder, Using Git Worktrees needs the command-line tools its instructions call (git, npm, cargo, pip and poetry). Our summary lists: Python 3; Node.js.

Does Using Git Worktrees access the network?

SKILL.md contains no URLs. Its commands use git, npm and pip, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Using Git Worktrees safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Using Git Worktrees use?

Using Git Worktrees is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Using Git Worktrees use?

About 1.9k tokens (SKILL.md is roughly 7.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Using Git Worktrees?

Skills that share tags, products or a category with Using Git Worktrees: Migrate Core Code to Submodules (tinyhumansai/openhuman, 41k stars), Nagent (davidondrej/skills, 4.1k stars), Git Worktree Isolation (jnMetaCode/superpowers-zh, 8.3k stars) and Worktree (AgentsMesh/AgentsMesh, 2.4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Using Git Worktrees?

GanyuanRan (a GitHub user) maintains it in GanyuanRan/Aegis, which has 1,322 GitHub stars. The repository holds 21 skills in this directory. The repository was last updated on October 3, 2026.

Source: GanyuanRan/Aegis on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.