using-git-worktrees

using-git-worktrees is a skill for Claude Code from jnMetaCode/superpowers-zh. It costs 44 tokens per session (1,919 once invoked), scanned A, original, MIT.

A guide to using Git worktrees, which let you keep multiple branches in separate folders at the same time.

In plain words
What is it for?
Use it before implementation to detect an existing isolated workspace, create one when appropriate, and report its branch and location.
Why use it?
It helps you isolate feature work from the current workspace, reducing the risk of changing the wrong branch or disrupting existing work.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the superpowers-zh plugin — 21 skills, 1 hook shipped together

not rated 8.4krepo +34 5d ago A scan Socket: passSnyk: passSkillSpector: pass 44 tokens original MIT

Good fit Use it before implementation to detect an existing isolated workspace, create one when appropriate, and report its branch and location.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jnmetacode/superpowers-zh/using-git-worktrees
About the project

superpowers-zh is a Chinese community edition of superpowers, a collection of practical skills and development methods for AI coding tools. It helps users apply workflows such as brainstorming, test-driven development, debugging, code review, and other programming tasks across supported coding agents. The catalogue add-ons are the project's translated and original skills, instructions, hook, and plugin components.

jnMetaCode/superpowers-zh · 8,377 stars · on GitHub · sp.aiolaola.com

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add jnMetaCode/superpowers-zh --skill using-git-worktrees
Clone the repo
git clone --depth 1 https://github.com/jnMetaCode/superpowers-zh

Made for: Claude Code.

Or install superpowers-zh, the plugin that ships this one along with the rest of its 21 skills, 1 hook.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for using-git-worktrees

README.md
[![agentmods](https://agentmods.dev/badge/skills/jnmetacode/superpowers-zh/using-git-worktrees/github.svg)](https://agentmods.dev/skills/jnmetacode/superpowers-zh/using-git-worktrees)
Your own site
<a href="https://agentmods.dev/skills/jnmetacode/superpowers-zh/using-git-worktrees"><img src="https://agentmods.dev/badge/skills/jnmetacode/superpowers-zh/using-git-worktrees/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for using-git-worktrees

Your own site · 80×15
<a href="https://agentmods.dev/skills/jnmetacode/superpowers-zh/using-git-worktrees"><img src="https://agentmods.dev/badge/skills/jnmetacode/superpowers-zh/using-git-worktrees.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 44 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,919 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • Socket pass 15 Sept 2026
  • Snyk pass 15 Sept 2026
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00044 $0.01919
Opus 5.5 $0.00018 $0.00768
Sonnet 5.5 $0.00009 $0.00384
Haiku 4.5 $0.00004 $0.00192

Measured 1mo ago against content hash 13ec7407756b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

using-git-worktrees scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/using-git-worktrees/SKILL.md · 176 lines

How it starts

The opening of the file, as written. The whole thing — 176 lines — stays where its author put it; the contents beside it link to each section on GitHub.

使用 Git 工作树

概述

确保工作发生在隔离的工作区中。优先使用你的平台的原生 worktree 工具。仅在没有原生工具可用时,再回退到手动 git worktree。

核心原则: 先检测现有隔离。然后用原生工具。再回退到 git。绝不与 harness 对抗。

开始时宣布: "我正在使用 using-git-worktrees 技能来建立一个隔离的工作区。"

步骤 0:检测现有隔离

创建任何东西之前,先检查你是否已经在一个隔离的工作区里。

GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)

Submodule 守卫: 在 git submodule 内 GIT_DIR != GIT_COMMON 也为真。在判定"已经在 worktree 内"之前,先确认你不在 submodule 里:

# 如果这条命令返回路径,说明你在 submodule 里,不是 worktree —— 按普通仓库处理
git rev-parse --show-superproject-working-tree 2>/dev/null

如果 GIT_DIR != GIT_COMMON(且不是 submodule): 你已经在一个 linked worktree 内。跳到步骤 2(项目设置)。不要再创建一个 worktree。

按分支状态报告:

  • 在某个分支上:"已经在隔离工作区 <path>,分支 <name>。"
  • 分离 HEAD:"已经在隔离工作区 <path>(分离 HEAD,由外部管理)。完成时需要创建分支。"

如果 GIT_DIR == GIT_COMMON(或在 submodule 内): 你在一个普通的仓库检出里。

用户是否已经在你的 instructions 里表明过 worktree 偏好?如果没有,创建 worktree 之前先征求同意:

"你希望我搭一个隔离的 worktree 吗?它能保护你当前分支不被改动。"

如果用户已声明过偏好,直接遵循,不再询问。如果用户拒绝同意,原地工作并跳到步骤 2。

步骤 1:创建隔离工作区

你有两种机制。按这个顺序尝试。

1a. 原生 Worktree 工具(首选)

用户已经请求隔离工作区(步骤 0 已获同意)。你是否已经有创建 worktree 的方法?可能是名为 EnterWorktree、WorktreeCreate 的工具、/worktree 命令,或 --worktree 标志。如果有,用它,然后跳到步骤 2。

原生工具自动处理目录放置、分支创建和清理。在你已经有原生工具的情况下使用 git worktree add,会创建你的 harness 看不到也无法管理的"幻影状态"。

只有在没有原生 worktree 工具可用时,才进入步骤 1b。

1b. Git Worktree 回退

只在步骤 1a 不适用时使用 —— 你没有可用的原生 worktree 工具。手动用 git 创建 worktree。

目录选择

按以下优先级。明确的用户偏好始终优先于观察到的文件系统状态。

  1. 检查你的 instructions 里是否声明过 worktree 目录偏好。 如果用户已指定,不再询问直接用。

  2. 检查是否存在项目本地的 worktree 目录:

    ls -d .worktrees 2>/dev/null     # 首选(隐藏目录)
    ls -d worktrees 2>/dev/null      # 备选
    

    找到就用。如果两者都存在,.worktrees 优先。

  3. 如果没有其他可参考的信息,默认用项目根目录下的 .worktrees/。

安全验证(仅项目本地目录)

创建 worktree 前必须验证目录已被忽略:

git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null

Read the full file on GitHub · 176 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 176 lines · 44 tokens per session scan A 13ec7407756b

Subscribe to this mod's changes

using-git-worktrees is a skill published in the GitHub repository jnMetaCode/superpowers-zh (8,377 stars, last pushed 5d ago), licensed MIT. It adds 44 tokens to every session and 1,919 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

chinese-commit

A guide for writing Git commit messages in a shared format: an English change type followed by a short Chinese summary. Git commits are saved descriptions of changes to a codebase.

Wade-DevCode/awesome-coding-skills-cn · 28 tokens

pr-description

A guide for writing Pull Request descriptions, which explain proposed code changes before teammates review them.

Wade-DevCode/awesome-coding-skills-cn · 20 tokens

git-workflow-and-versioning

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple…

addyosmani/agent-skills · 89 tokens

gentle-ai-collab-perfect

Trigger: contributing to Gentleman-Programming/gentle-ai as an external collaborator. Strict issue-first workflow, honest PR bodies, contributor-vs-maintainer scope, chained-PR strategy, verification protocol, docstring coverage. Load whenever the active repo is Gentleman-Programming/gentle-ai and any part of the…

Gentleman-Programming/gentle-ai · 106 tokens

branch-pr

Create Gentle AI pull requests with issue-first checks. Trigger: creating, opening, or preparing PRs for review.

Gentleman-Programming/gentle-ai · 26 tokens

work-unit-commits

Plan commits as reviewable work units. Trigger: implementation, commit splitting, chained PRs, or keeping tests and docs with code.

Gentleman-Programming/gentle-ai · 33 tokens