AGENT SKILL

x-manage-worktrees

Manages git worktrees for parallel task and story execution. Operations: create, list, remove, cleanup, detect-context. Follows Rule 14 (Worktree Lifecycle) naming convention under .claude/worktrees/{identifier}/.

License 许可
MIT
最近更新
2026-10-27
Stars
★ 0
Forks
1

01 前言 Front Matter

name
x-manage-worktrees
model
haiku
description
Manages git worktrees for parallel task and story execution. Operations: create, list, remove, cleanup, detect-context. Follows Rule 14 (Worktree Lifecycle) naming convention under .claude/worktrees/{identifier}/.
allowed-tools
Bash, Read
argument-hint
<create|list|remove|cleanup|detect-context> [--branch <name>] [--base <base>] [--id <identifier>] [--dry-run]
context-budget
light
user-invocable
true
requires-capabilities
[]

02 资源文件 2

03 SKILL.md 正文

Global Output Policy

  • Language: English ONLY.
  • Tone: Technical, Direct, and Concise.
  • Efficiency: Remove all conversational fillers and greetings to save tokens.

Triggers

/x-manage-worktrees create --branch feat/task-0049-0001-001-domain [--base develop] [--id task-0049-0001-001]
/x-manage-worktrees list
/x-manage-worktrees remove --id task-0049-0001-001
/x-manage-worktrees cleanup [--dry-run]
/x-manage-worktrees detect-context

Parameters

Operation Parameter Type Required Default Description
create --branch string Yes — Branch name for the worktree
create --base string No develop Base branch to create the new branch from
create --id string No derived from branch (strips feat/, fix/, hotfix/, refactor/ prefixes) Worktree directory identifier
remove --id string Yes — Worktree identifier to remove
cleanup --dry-run boolean No false Preview candidates without removing
detect-context (none) — — — Returns JSON: {inWorktree, worktreePath, mainRepoPath}

All worktrees are placed under .claude/worktrees/{identifier}/. Protected branches (main, develop) cannot host worktrees. Creator-owns-removal invariant enforced per Rule 14 §5 — only the skill that called create may call remove for the same worktree.

Output Contract

Operation Output
create Prints absolute worktree path on success; exits 1 on protected branch or conflict
list Markdown table: ID, Branch, Status (ACTIVE/STALE/MERGED/ORPHAN), Last Commit, Age
remove Confirmation message on success; exits 1 if --id not found
cleanup Summary table of removed worktrees; --dry-run prints candidates only
detect-context Single-line JSON: `{"inWorktree":bool,"worktreePath":string

detect-context is read-only and safe to call from any context — used by orchestrators to decide REUSE | CREATE | LEGACY branching (Rule 14 §3 Non-Nesting Invariant).

Error Envelope

Code Condition Message
PROTECTED_BRANCH create on main or develop Cannot create worktree on protected branch (<name>)
BRANCH_CONFLICT Branch already checked out in another worktree Branch '<name>' is already an active worktree
WORKTREE_EXISTS Target directory already exists Worktree directory already exists: .claude/worktrees/<id>
NOT_FOUND remove --id not found Worktree '<id>' not found
GIT_ADD_FAILED git worktree add non-zero Git error detail; suggest manual cleanup
GIT_REMOVE_FAILED git worktree remove non-zero (retried with --force) Git error detail
NOT_A_REPO detect-context run outside a git repo {"error":"NOT_A_REPO"} to stderr; exit 1
NO_OBSOLETE cleanup finds nothing No obsolete worktrees found (informational, exit 0)

Full Protocol

Complete per-operation Bash implementations (create 7-step workflow, list status classification, cleanup criteria — MERGED/STALE/ORPHAN, detect-context canonical snippet with CWE-116/CWE-209 hardening and JSON-escape), Git Flow integration table (task/story/hotfix base-branch rules), post-merge lifecycle, naming convention derivation, and Integration Notes (x-implement-epic/x-implement-story/x-implement-task callers) in references/full-protocol.md.

04 同仓库更多 Skills

review-bench
review-bench/edercnj_ia-dev-environment

x-parallel-eval

Detects and classifies file-collision risks between work units (tasks, stories, or epic phases) before parallel execution. Reads ## File Footprint blocks produced by x-task-plan / x-story-plan, applies the parallelism-heuristics knowledge pack (hard / regen / soft categories + hotspot overrides), and emits a collision matrix + serialization recommendation in Markdown (default) or JSON.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

parallelism-heuristics

Canonical catalog of file-collision heuristics for parallel task, story, and epic execution. Defines the File Footprint block format, the three Conflict Categories (hard / regen / soft), a hotspot list of high-contention paths, and the degrade-with-warning policy. Consumed by x-task-plan, x-story-plan, x-epic-map, x-parallel-eval, and x-dev-*-implement.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-watch-pr-ci

Polls a PR's CI checks and Copilot review status, blocking until checks complete or timeout. Returns one of 8 stable exit codes (SUCCESS=0, CI_PENDING_PROCEED=10, CI_FAILED=20, TIMEOUT=30, PR_ALREADY_MERGED=40, NO_CI_CONFIGURED=50, PR_CLOSED=60, PR_NOT_FOUND=70). Writes a versioned state-file for session resume.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-validate-docs

Documentation freshness gate: validates 6 dimensions (readme, api-specs, grpc-proto, adr, skill-docs, system-architecture) against code changes in a PR. Stack-aware — only validates targets declared/auto-detected from ProjectConfig.documentation.targets. Returns exit non-zero on staleness; produces structured report.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-update-system-architecture

Incrementally updates docs/architecture/system.md after an epic completes. Appends new entries to the Decision Log (§11) using x-internal-write-report --append (dedup by ## ID: marker) and surgically inserts component/integration changes into sections 1-10 via Edit. Idempotent: re-running with the same epic produces a byte-identical system.md.

★ 0
review-bench
review-bench/edercnj_ia-dev-environment

x-update-architecture

Incrementally updates the service architecture document with changes from architecture plans. Adds new components, integrations, flows, and ADR references without rewriting existing content. Use after implementation to keep architecture documentation current.

★ 0