Token导航 LogoToken导航TokenDH.com
AI 工具执行命令github未标认证来源可访问clear审计提醒

worktree-manager工作树管理器

Agent Skill

worktree-manager 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,073

周安装

43

GitHub Stars

12

下载量

347
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:worktree-manager(工作树管理器)
来源仓库:https://github.com/scientiacapital/skills
仓库路径:skills/worktree-manager
安装命令:
npx skills add https://github.com/scientiacapital/skills --skill worktree-manager
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/scientiacapital/skills --skill worktree-manager

简介

worktree-manager 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。
  • 通过 npx skills add 命令从指定仓库安装并使用该技能。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 可结合来源仓库和原始 README 进一步核验具体用法和功能边界。

SKILL.md

<quick_start> Create a single worktree with agent:

/worktree create feature/auth

Claude will:

  1. Allocate ports (8100-8101)
  2. Create worktree at ~/tmp/worktrees/[project]/feature-auth
  3. Install dependencies
  4. Create WORKTREE_TASK.md for the agent
  5. Launch terminal with Claude Opus 4.6 agent </quick_start>

Native --worktree Flag (Claude Code v2.1.49+)

Claude Code now has built-in worktree support:

# Named worktree
claude --worktree feature-auth   # or: claude -w feature-auth

# Auto-generated name
claude -w

What It Does

  • Creates worktree at <repo>/.claude/worktrees/<name>/
  • Branch: worktree-<name> (auto-created from default remote branch)
  • On exit: auto-cleanup if no changes; prompts to keep/remove if changes exist

Tip: Add .claude/worktrees/ to .gitignore

When to Use Native vs This Skill

ScenarioUse
Quick isolated work, single agentclaude -w feature-name
Multi-agent teams, port allocation, registryThis skill (worktree-manager)
Subagent isolationisolation: "worktree" in Task tool param
Non-git VCS (Perforce, SVN)WorktreeCreate/WorktreeRemove hooks

WorktreeCreate / WorktreeRemove Hooks

New hook events for VCS-agnostic worktree lifecycle. These replace the default git worktree behavior when configured:

{
  "hooks": {
    "WorktreeCreate": [{
      "hooks": [{
        "type": "command",
        "command": "bash -c 'INPUT=$(cat); NAME=$(echo \"$INPUT\" | jq -r .name); mkdir -p /tmp/worktrees/$NAME && echo $NAME'"
      }]
    }],
    "WorktreeRemove": [{
      "hooks": [{
        "type": "command",
        "command": "bash -c 'INPUT=$(cat); PATH=$(echo \"$INPUT\" | jq -r .path); rm -rf $PATH'"
      }]
    }]
  }
}

When to use hooks vs native: Use hooks when working with non-git VCS systems or when you need custom isolation logic (e.g., Docker containers, remote dev servers). For standard git repos, the native claude -w flag or this skill's workflow is preferred.

Note: These hooks do NOT support matchers. They fire once per worktree lifecycle event. The hook receives {name, path} via stdin JSON.

<success_criteria> A worktree setup is successful when:

  • Worktree created at ~/tmp/worktrees/[project]/[branch-slug]
  • Ports allocated and registered globally
  • Dependencies installed
  • Agent launched in terminal (Ghostty/iTerm2/tmux)
  • Entry added to ~/.claude/worktree-registry.json </success_criteria>

<current_state> Git repository:!git status --short --branch 2>/dev/null

Existing worktrees:!git worktree list 2>/dev/null

Worktree registry:!cat ~/.claude/worktree-registry.json 2>/dev/null | jq -r '.worktrees[] | "\(.project)/\(.branch) → \(.status)"' | head -10

Available ports:!cat ~/.claude/worktree-registry.json 2>/dev/null | jq '.portPool.allocated | length' || echo "0" allocated </current_state>

<activation_triggers>

When This Skill Activates

Trigger phrases:

  • "spin up worktrees for X, Y, Z"
  • "create 3 worktrees for features A, B, C"
  • "new worktree for feature/auth"
  • "what's the status of my worktrees?"
  • "show all worktrees" / "show worktrees for this project"
  • "clean up merged worktrees"
  • "launch agent in worktree X"

Invocation

Command syntax:

  • /worktree create feature/auth - Single worktree
  • /worktree create feat1 feat2 feat3 - Multiple worktrees
  • /worktree status - Check all worktrees
  • /worktree status --project myapp - Filter by project
  • /worktree cleanup feature/auth - Remove worktree
  • /worktree launch feature/auth - Launch agent in worktree

</activation_triggers>

<file_locations>

Key Files

FilePurpose
~/.claude/worktree-registry.jsonGlobal registry - tracks all worktrees across all projects
~/.claude/skills/worktree-manager/config.jsonSkill config - terminal, shell, port range settings
~/.claude/skills/worktree-manager/scripts/Helper scripts - optional, can do everything manually
~/tmp/worktrees/Worktree storage - all worktrees live here
.claude/ (per-project)Project config - CLAUDE.md, hooks, permissions, custom agents
.claude/worktree.json (per-project)Project config - optional custom settings
WORKTREE_TASK.md (per-worktree)Auto-loaded task prompt - agent reads on startup

</file_locations>

<core_concepts>

Core Concepts

Centralized Worktree Storage

All worktrees live in ~/tmp/worktrees/<project-name>/<branch-slug>/

~/tmp/worktrees/
├── obsidian-ai-agent/
│   ├── feature-auth/           # branch: feature/auth
│   ├── feature-payments/       # branch: feature/payments
│   └── fix-login-bug/          # branch: fix/login-bug
└── another-project/
    └── feature-dark-mode/

Branch Slug Convention

Branch names are slugified for filesystem safety:

  • feature/authfeature-auth
  • fix/login-bugfix-login-bug

Slugify manually: echo "feature/auth" | tr '/' '-'

Port Allocation

  • Global pool: 8100-8199 (100 ports total)
  • Per worktree: 2 ports allocated (for API + frontend patterns)
  • Globally unique: Ports tracked to avoid conflicts across projects

See: reference/port-allocation.md for detailed operations.

Required Defaults

CRITICAL: These settings MUST be used when launching agents:

SettingValueReason
TerminalGhostty or iTerm2Auto-detected, configurable in config.json
Model--model opusOpus 4.6 alias (most capable)
Flags--dangerously-skip-permissionsRequired for autonomous file ops

Launch command pattern:

# Recommended: agent inherits .claude/ config (CLAUDE.md, hooks, permissions)
claude --model opus --dangerously-skip-permissions

# Or with explicit permission allowlist (safer, from .claude/settings.json):
claude --model opus --allowedTools "Bash(npm test),Bash(npm run build),Edit,Write,Read,Glob,Grep"

Subagent Worktree Isolation

Subagents can be configured to run in isolated worktrees:

# In subagent frontmatter:
---
name: my-subagent
isolation: worktree
---

The subagent runs in a temporary worktree. On completion:

  • If no changes: auto-cleanup
  • If changes exist: changes preserved for review

</core_concepts>

Skill Config

Location: ~/.claude/skills/worktree-manager/config.json

{
  "terminal": "ghostty",
  "terminalPreference": "auto",
  "enableNumberedTabs": true,
  "shell": "zsh",
  "defaultModel": "opus",
  "claudeCommand": "claude --model opus --dangerously-skip-permissions",
  "portPool": { "start": 8100, "end": 8199 },
  "portsPerWorktree": 2,
  "worktreeBase": "~/tmp/worktrees",
  "defaultCopyDirs": [".claude"],
  "envFilePriority": [".env.local", ".env", ".env.example"],
  "autoCleanupOnMerge": true
}

.claude/ Directory Propagation

When creating worktrees, the entire .claude/ directory is copied so agents inherit project-level config:

.claude/
├── CLAUDE.md              # Project instructions (auto-loaded by Claude Code)
├── settings.json          # Hooks and permissions
│   ├── hooks.PostToolUse  # Auto-format on Write|Edit (e.g., "bun run format || true")
│   └── permissions.allow  # Whitelisted bash commands for agents
├── agents/                # Custom subagent definitions
│   ├── build-validator.md # Validates builds pass
│   ├── code-architect.md  # Plans implementation
│   ├── code-simplifier.md # Refactors for clarity
│   └── verify-app.md      # End-to-end verification
└── PROJECT_CONTEXT.md     # Session continuity (project-context-skill)

Why this matters:

  • CLAUDE.md: Agent reads project conventions, dev commands, tech stack
  • Hooks: Auto-formatting runs after every Write/Edit, keeping code consistent across agents
  • Permissions: Agents can run pre-approved commands without prompting (e.g., npm test, bun run build)
  • Custom agents: Agents can dispatch subagents (e.g., verify-app.md for end-to-end checks)

Hook example (settings.json):

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [{ "type": "command", "command": "bun run format || true" }]
      }
    ]
  }
}

Workflows

Create Multiple Worktrees

User says: "Spin up 3 worktrees for feature/auth, feature/payments, and fix/login-bug"

You do (can parallelize with subagents):

For EACH branch (can run in parallel):

1. SETUP
   PROJECT=$(basename $(git remote get-url origin 2>/dev/null | sed 's/\.git$//') || basename $(pwd))
   REPO_ROOT=$(git rev-parse --show-toplevel)
   BRANCH_SLUG=$(echo "feature/auth" | tr '/' '-')
   WORKTREE_PATH=~/tmp/worktrees/$PROJECT/$BRANCH_SLUG

2. ALLOCATE PORTS
   Find 2 unused ports from 8100-8199, add to registry

3. CREATE WORKTREE
   mkdir -p ~/tmp/worktrees/$PROJECT
   git worktree add $WORKTREE_PATH -b $BRANCH

4. COPY PROJECT CONFIG (.claude/ directory)
   cp -r .claude $WORKTREE_PATH/ 2>/dev/null || true
   Copy .env.local or .env as appropriate

5. CREATE WORKTREE_TASK.md
   Create detailed task file for agent

6. INSTALL DEPENDENCIES
   Detect package manager, run install command

7. VALIDATE (optional)
   Start server, health check, stop

8. REGISTER IN GLOBAL REGISTRY
   Update ~/.claude/worktree-registry.json with entry

9. LAUNCH AGENT
   ghostty -e "cd $WORKTREE_PATH && claude --model opus --dangerously-skip-permissions"

AFTER ALL COMPLETE:
- Report summary table to user

Check Status

With script:

~/.claude/skills/worktree-manager/scripts/status.sh
~/.claude/skills/worktree-manager/scripts/status.sh --project my-project

Manual:

cat ~/.claude/worktree-registry.json | jq -r '.worktrees[] | "\(.project)\t\(.branch)\t\(.ports | join(","))\t\(.status)"'

Cleanup Worktree

See: reference/cleanup-operations.md for full cleanup procedure.

Quick cleanup:

~/.claude/skills/worktree-manager/scripts/cleanup.sh <project> <branch> --delete-branch

Reference Files

For detailed operations, see:

TopicFile
Registry operationsreference/registry-operations.md
Port allocationreference/port-allocation.md
Agent launchingreference/agent-launching.md
System notificationsreference/system-notifications.md
Script referencereference/script-reference.md
Cleanup operationsreference/cleanup-operations.md
Advanced workflowsreference/advanced-workflows.md
Troubleshootingreference/troubleshooting.md

<safety_guidelines>

Safety Guidelines

  1. Before cleanup, check PR status:

- PR merged → safe to clean everything - PR open → warn user, confirm before proceeding - No PR → warn about unsubmitted work

  1. Before deleting branches, confirm if:

- PR not merged - No PR exists - Worktree has uncommitted changes

  1. Port conflicts: If port in use by non-worktree process, pick different port
  2. Environment files: Never commit .env or .env.local to git

</safety_guidelines>

<example_session>

Example Session

User: "Spin up 2 worktrees for feature/dark-mode and fix/login-bug"

You:

  1. Detect project: obsidian-ai-agent (from git remote)
  2. Detect package manager: uv (found uv.lock)
  3. Allocate 4 ports: 8100 8101 8102 8103
  4. Create worktrees: git worktree add ~/tmp/worktrees/obsidian-ai-agent/feature-dark-mode -b feature/dark-mode git worktree add ~/tmp/worktrees/obsidian-ai-agent/fix-login-bug -b fix/login-bug
  5. Copy.claude/ and.env to each
  6. Install deps: (cd <path> && uv sync)
  7. Register both in ~/.claude/worktree-registry.json
  8. Launch agents: ghostty -e "cd ~/tmp/worktrees/.../feature-dark-mode && claude --model opus --dangerously-skip-permissions"
  9. Report: Created 2 worktrees with agents: | Branch | Ports | Path | Task | |--------|-------|------|------| | feature/dark-mode | 8100, 8101 | ~/tmp/worktrees/.../feature-dark-mode | Implement dark mode | | fix/login-bug | 8102, 8103 | ~/tmp/worktrees/.../fix-login-bug | Fix login redirect | Both agents running in Ghostty windows.

</example_session>


Boris Cherny Workflow Integration

iTerm2 notifications, web session handoff (/teleport), ralph-loop for autonomous sessions, and daily workflow protocols.

See reference/advanced-workflows.md for iTerm2 setup, teleport handoff, ralph-loop patterns, terminal strategy, and daily workflow protocol.

Emit Outcome Sidecar

As the final step, write to ~/.claude/skill-analytics/last-outcome-worktree-manager.json:

{"ts":"[UTC ISO8601]","skill":"worktree-manager","version":"1.2.0","variant":"default",
 "status":"[success|partial|error]","runtime_ms":[estimated ms from start],
 "metrics":{"worktrees_created":[n],"agents_launched":[n],"worktrees_cleaned":[n]},
 "error":null,"session_id":"[YYYY-MM-DD]"}

Use status "partial" if some stages failed but results were produced. Use "error" only if no output was generated.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

28.93%
按下载量换算100

Antigravity

22.06%
按下载量换算77

Gemini CLI

16.28%
按下载量换算56

Codex

13.5%
按下载量换算47

OpenCode

7.8%
按下载量换算27

windsurf

2.99%
按下载量换算10

安全审计

Gen Agent Trust Hub

可疑

Socket

可疑

Snyk

可疑

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/scientiacapital/skills --skill worktree-manager;npx skills add scientiacapital/skills --skill "worktree-manager" 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills