← 返回 Skills 市场
imsai-sh

git-worktree-setup

作者 sai · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
60
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install git-worktree-setup
功能描述
Use when the user explicitly asks to "generate / update a git worktree auto-setup script for this repo." Note this skill is NOT triggered when a new worktree...
使用说明 (SKILL.md)

Git Worktree Setup

What this skill is / is not

Produces: a tailored scripts/setup-worktree.sh (or similar) for the current repo + the matching agent-tool hook config that auto-invokes it + a manual entry-point as a safety net.

Is NOT: the thing that runs every time a new worktree is created. That's the hook. This skill only runs when the user explicitly asks for it:

  • "Set me up worktree auto-bootstrap"
  • "Every git worktree add requires me to manually install / copy .env — automate it"
  • "Project structure changed — update the worktree init script"

Core working style: audit the repo yourself → put a concrete draft on the table → ask only the questions you couldn't infer → land it.

Don't dump 7 questions on the user upfront — that's annoying. Read the code, read the configs, infer everything inferable, walk in with a draft proposal, and let the user adjust.

4-step workflow

Step 1: Audit the repo yourself (do not ask the user)

This is dynamic inference, not checking boxes off a static list. The table below is examples of common signals — you must expand the investigation based on what you actually find. Any tool, any stack, any project-specific convention is fair game. Read unfamiliar config files; grep for unknown CLI names; if the README / CONTRIBUTING / Makefile / justfile / Taskfile mentions "setup" / "bootstrap" / "install" steps, read them — they often hold the repo's own definition of "what a fresh machine needs."

Starting signals (examples, not exhaustive):

What to look at What to infer
package.json (root + workspaces field) npm/pnpm/yarn? monorepo? what workspace globs?
pnpm-workspace.yaml / lerna.json / nx.json / turbo.json confirms monorepo tooling
pyproject.toml / Pipfile / uv.lock / requirements.txt Python? poetry / uv / pip? share .venv?
Cargo.toml (with workspace section) Rust? share target/?
go.mod Go? usually nothing to share
Gemfile / mix.exs / composer.json / pubspec.yaml etc. other ecosystems — infer their deps dirs analogously
.gitignore hunt ignored entries: node_modules / .venv / .env / dist / *.state etc. — these are the share/copy candidates; don't skip unfamiliar ignores either, they're often project-specific cache
.env.example / .dev.vars.example / apps/*/.dev.vars.example / config/*.example hints at which secret / config files need Copy
docker-compose*.yml / compose.yml / Dockerfile.dev stateful services list (pg/redis/mysql) + volume paths + host port bindings
wrangler.toml / fly.toml / serverless.yml / terraform/* etc. various IaC / platform configs often imply a local state directory
Existence of .claude/ / .cursor/ / .codex/ / .aider* / .opencode/ etc. infer the user's current agent tooling
Makefile / justfile / Taskfile.yml / bin/setup / script/bootstrap project's own setup entry point — its install / link / copy steps are gold for worktree bootstrap
"Getting started" / "Local dev" sections in README.md / CONTRIBUTING.md / docs/setup*.md the human-language "what a fresh machine needs" list
.github/workflows/*.yml / .gitlab-ci.yml etc. how CI sets up the env ≈ what local probably needs
scripts/setup-worktree.sh / scripts/setup-worktree.sh / bin/worktree-* etc. already exists? → decide new-build vs update mode
Whether main repo's node_modules/, apps/*/node_modules/, .venv/ etc. actually exist on disk validates the inference + tells you what's currently linkable
Any unfamiliar top-level directory e.g. references/, vendor/, third_party/, fixtures/ — could be deliberate shared resources; ls inside before asking (symlinks? large files? test data?)

Expand actively: each of the above can lead to further investigation. Reading package.json, you spot husky → check whether .husky/ should be shared. You spot playwright → check whether browser cache (~/.cache/ms-playwright) should be shared. Reading pyproject.toml, you find [tool.uv] → where does uv put its cache. Don't skip just because something isn't in the table.

By the end of audit you should have:

  • a resource candidate list pre-classified into Share / Copy / Generate, each item with its source evidence
  • the inferred agent tool (based on config dir presence)
  • whether a script already exists (decides new vs update)
  • the open questions worth asking (items audit can't decide but are decision-critical)

Step 2: Walk in with a concrete draft (don't bombard with questions)

Aggregate the audit into a resource list proposal, three tiers laid out. Give a concrete recommendation for what you can infer; mark "needs confirmation" for what you can't. Example:

I went through the repo: looks like an npm-workspaces monorepo (apps/api, apps/web, packages/*), Cloudflare Workers + Vite. .claude/settings.json exists, so Claude Code.

Here's what I'd configure for worktree auto-init:

  • Share (symlink): node_modules, apps/*/node_modules, packages/*/node_modules
  • Copy: apps/api/.dev.vars (saw .dev.vars.example)
  • Hook: .claude/settings.json add SessionStart calling bash $(...)/scripts/setup-worktree.sh
  • Manual entry point: bash scripts/setup-worktree.sh always works

A few I need to confirm:

  1. .wrangler/state (Cloudflare local D1/R2 state): share across worktrees? Share = all worktrees see same local DB; isolated = each its own. Depends on whether you'll run dev in multiple worktrees concurrently.
  2. Besides Claude Code, do you / your team also use Codex / Cursor / Gemini CLI? Want hooks for those too?
  3. Didn't see custom reference-repo / build-output sharing needs — confirm none?

Look right?

Step 3: Tighten with 1-2 follow-ups based on the answer

After the user answers, only ask the necessary follow-ups based on what they said. Common follow-ups:

  • User says "yes, I run multiple worktrees concurrently" → "For stateful services (pgdata, SQLite WAL), do you want concurrent isolation (Copy) or sharing (Share)? Default recommendation is Copy to prevent corruption."
  • User says they also use Codex/Cursor/Gemini → "I'm not familiar with X's hook mechanism — could you point me at the docs / how do you expect it to auto-run? Worst case I can hook in via git's post-checkout."
  • User mentions a custom resource → "Share or Copy? Is it written to often?"

Don't open another round of questions — decide what you can decide.

Step 4: Generate + verify

  1. Copy setup-worktree.sh template into \x3Crepo>/scripts/
  2. Fill in the "resource declarations" block at the bottom per the agreed plan (leave the helper functions block as-is)
  3. Merge the matching hook config (from hook-config.json) into .claude/settings.json (or whatever the tool's config location is; multiple tools = multiple hooks)
  4. Run twice to verify idempotency: first run links, second run skips everything
  5. In a freshly-created worktree, actually run dev / test end-to-end
  6. Report back: what was installed, what files changed, how to invoke manually

When updating an existing script: use Edit to diff-edit the resource declarations block. Don't touch the helper functions unless they're genuinely outdated.

Three-tier strategy (the agent's classification framework)

Tier Examples Why How
Share (symlink) node_modules, package-manager caches, stateful DB shared across worktrees saves disk + install time; multiple worktrees see same data ln -s $MAIN/\x3Cpath> $WORKTREE/\x3Cpath>
Copy secrets / env files, signing keys, stateful files used concurrently each worktree may diverge; mustn't break if main is deleted; mustn't get torn under concurrent writes cp -R once (re-run skips)
Generate dev port, COMPOSE_PROJECT_NAME, local socket must differ per-worktree hash(branch) % range for ports; clean_branch_name for container names

Stateful data: in single-writer concurrent mode, must be Copy (Postgres, SQLite WAL are single-writer); for sequential use, can be Share. This must be in Step 2's "needs confirmation" list — don't decide it for the user.

Agent tool trigger reference

Agent tool Trigger mechanism
Claude Code SessionStart hook (most portable) / WorktreeCreate hook (only fires for claude --worktree, strict stdout contract: print only path, progress to /dev/tty)
Codex No equivalent hook mechanism currently — manual script + post-checkout git hook
Cursor Same as above
Gemini CLI Not sure — ask the user for docs
Aider / others Not sure — ask the user for docs
Multi-tool / no agent tool Universal fallback: post-checkout git hook + manual bash scripts/setup-worktree.sh

Key principles:

  • For tools you don't know, don't make up hook configs. Ask the user.
  • Always preserve the manual entry point bash scripts/setup-worktree.sh. Any hook breaking or tool-switching shouldn't leave you stuck.
  • Multi-tool? Hook them all to the same script — the script itself is idempotent.

Quick reference: common resources → default tier

Resource Default tier Note
Root node_modules/ Share npm workspaces hoist target
apps/*/node_modules/, packages/*/node_modules/ Share — don't skip bundlers walk only one parent up from workspace; subpath exports like zod/v3 only exist in the workspace's local install
.venv/, venv/ Share (semi-readonly) Python virtualenv shebangs are absolute-path-baked; same machine OK
Build cache (.next/, target/, dist/) Skip or Share usually rebuilds fast enough
.env*, .dev.vars Copy secrets can't be shared
*.wrangler/state, pgdata/, redis-data/ Depends on concurrency — list as needs-confirmation share/copy depends on concurrent use
Dev port Generate hash branch
COMPOSE_PROJECT_NAME Generate clean branch name
Custom (reference-repo symlinks, build artifacts, etc.) Find during audit; if unsure list as needs-confirmation in Step 2

Common mistakes (self-check while writing the script)

  • Linking only root node_modules, missing workspaces: symptom Could not read from file: .../zod/v4. Loop both apps/* and packages/*.
  • git worktree add polluting stdout (under WorktreeCreate hook): redirect with >/dev/null 2>&1, send progress to /dev/tty.
  • Symlinking single-writer stateful directories: concurrent dev corrupts. Step 2 must list as needs-confirmation.
  • Not idempotent: re-runs must skip everything. Template's link_resource handles this.
  • Dead symlinks: check [ -e "$target" ] before linking.
  • Hardcoding the main repo path: derive with git rev-parse --git-common-dir.
  • Symlinking .env: must be Copy (symlink edits leak across worktrees).
  • Skipping audit and bombarding the user with questions: audit first, infer what's inferrable; questions to the user are judgement calls, not facts.
  • Deciding stateful policy for the user: Step 2 must ask.

Implementation resources

Verification checklist (run after generate / update)

  • Script runs on fresh git worktree add and exits 0
  • Re-run = no-op (all "skip — already linked")
  • npm run dev (or stack equivalent) actually starts, no "module not found"
  • Tests / typecheck pass in the new worktree
  • Removing main-repo's optional resource → script logs "skip" not error
  • Under WorktreeCreate: stdout contains only the worktree path
  • Manual entry point (bash scripts/setup-worktree.sh) also runs
  • Confirmed resource list matches what got generated
安全使用建议
This skill appears safe for its stated purpose if you want automated git worktree bootstrapping. Before installing or using it, review the generated resource declarations and hook config, confirm which secrets and state directories should be copied versus symlinked, and avoid auto-running the hook until the script has been checked in your specific repository.
功能分析
Type: OpenClaw Skill Name: git-worktree-setup Version: 1.0.0 The skill bundle automates git worktree initialization by instructing the AI agent to perform an autonomous repository audit, which involves reading arbitrary configuration files, environment examples, and project structures (SKILL.md). It generates a bash script (setup-worktree.sh) that executes potentially destructive commands like 'rm -rf' to manage symlinks and modifies agent configuration files to install execution hooks (hook-config.json). While these capabilities are aligned with the stated purpose of environment automation, the broad autonomous file access and script generation constitute high-risk behaviors according to the analysis criteria.
能力评估
Purpose & Capability
The stated purpose and artifacts align: the skill audits a repo, proposes a worktree bootstrap plan, and generates a setup script plus hook configuration. The notable capability is that this naturally involves local file mutation, symlinks, and copying env/secret files.
Instruction Scope
The workflow is scoped to the current repository and asks for user confirmation before landing changes, but it deliberately tells the agent to inspect many project files and infer setup behavior.
Install Mechanism
There is no install spec or hidden installer in the provided artifacts. README installation uses a normal skills CLI or git clone path.
Credentials
The included setup template performs purpose-aligned local environment changes, including symlinking dependencies/state, copying env files, and replacing existing destination directories for declared resources.
Persistence & Privilege
The skill provides hook configurations that persistently run the generated setup script on Claude Code SessionStart or WorktreeCreate. This is disclosed and central to the purpose, but should be reviewed before enabling.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install git-worktree-setup
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /git-worktree-setup 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of git-worktree-setup. - Introduces an agent skill to generate or update a tailored git worktree auto-setup script (`setup-worktree.sh`) and agent tool hook config for the current repo. - Audits project structure to infer which resources should be shared or copied in new worktrees; proposes a concrete draft plan and only asks the user for information that can't be automatically determined. - Supports multiple agent tools (Claude Code, Codex, Cursor, OpenCode, Gemini CLI, etc.) and provides both auto and manual invocation options. - Designed to update the setup script as the project evolves, not to run on every new worktree—only on explicit user request.
元数据
Slug git-worktree-setup
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

git-worktree-setup 是什么?

Use when the user explicitly asks to "generate / update a git worktree auto-setup script for this repo." Note this skill is NOT triggered when a new worktree... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 60 次。

如何安装 git-worktree-setup?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install git-worktree-setup」即可一键安装,无需额外配置。

git-worktree-setup 是免费的吗?

是的,git-worktree-setup 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

git-worktree-setup 支持哪些平台?

git-worktree-setup 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 git-worktree-setup?

由 sai(@imsai-sh)开发并维护,当前版本 v1.0.0。

💬 留言讨论