Agent Skillsmarmelab/atomic-crm › worktree-detection

worktree-detection

GitHub

提供通过任务编号动态查找 Git worktree 的脚本模式,避免硬编码路径。适用于 hooks 或自动化脚本中定位特定任务的工作区,确保跨环境兼容性和健壮性。

.claude/skills/worktree-detection/SKILL.md marmelab/atomic-crm

Trigger Scenarios

在 hook 或脚本中需要定位特定任务的 worktree 需要动态获取工作区路径而非使用硬编码路径

Install

npx skills add marmelab/atomic-crm --skill worktree-detection -g -y
More Options

Non-standard path

npx skills add https://github.com/marmelab/atomic-crm/tree/main/.claude/skills/worktree-detection -g -y

Use without installing

npx skills use marmelab/atomic-crm@worktree-detection

指定 Agent (Claude Code)

npx skills add marmelab/atomic-crm --skill worktree-detection -a claude-code -g -y

安装 repo 全部 skill

npx skills add marmelab/atomic-crm --all -g -y

预览 repo 内 skill

npx skills add marmelab/atomic-crm --list

SKILL.md

Frontmatter
{
    "name": "worktree-detection",
    "description": "How to find a Git worktree by task number without hardcoding paths. Use in hooks or scripts that need to locate a specific task's worktree."
}

Worktree Detection

Reference snippet for locating a task's Git worktree from its task number, without hardcoding paths.

When to Use

  • Inside a hook or script that must act on a specific task's worktree.
  • Any time you'd otherwise hardcode a /tmp/... worktree path.

Pattern

TASK_NUM="TASK-005"

WORKTREE=$(git worktree list --porcelain \
  | grep "^worktree " \
  | awk '{print $2}' \
  | grep -i "${TASK_NUM}" \
  | head -1)

if [ -z "$WORKTREE" ] || [ ! -d "$WORKTREE" ]; then
  echo "No worktree found for ${TASK_NUM} — skipping"
  exit 0
fi

Why this works

git worktree list reads from Git's internal registry — it knows every worktree regardless of where it was created. No assumptions about directory structure or machine-specific paths.

Extracting TASK_NUM from agent variables

TASK_NUM=$(echo "$TASK_OWNER $TASK_SUBJECT" | grep -oP 'TASK-\d+' | head -1)

Works whether the task number appears in the owner field or the subject line.

Red Flags

  • A hardcoded /tmp/... worktree path instead of querying git worktree list.
  • Assuming a directory layout rather than reading Git's registry.
  • Treating a missing worktree as an error instead of skipping cleanly (exit 0).

Verification

  • Worktree resolved via git worktree list --porcelain, never a hardcoded path.
  • A missing/absent worktree is handled (skip, don't crash).

Version History

  • 167a4cd Current 2026-08-20 13:20

Same Skill Collection

.claude/skills/adr-writing/SKILL.md
.claude/skills/backend-dev/SKILL.md
.claude/skills/delete-initial-resource/SKILL.md
.claude/skills/e2e-conventions/SKILL.md
.claude/skills/frontend-dev/SKILL.md
.claude/skills/grill-me/SKILL.md
.claude/skills/playwright-testing/SKILL.md
.claude/skills/ponytail-audit/SKILL.md
.claude/skills/ponytail-debt/SKILL.md
.claude/skills/ponytail-help/SKILL.md
.claude/skills/ponytail-review/SKILL.md
.claude/skills/resolving-rollback-conflicts/SKILL.md
.claude/skills/setup-interview/SKILL.md
.claude/skills/shadcn-customization/SKILL.md
.claude/skills/update-branding/SKILL.md
.claude/skills/ponytail/SKILL.md

Metadata

Files
0
Version
167a4cd
Hash
f0db2bde
Indexed
2026-08-20 13:20

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-25 10:30
浙ICP备14020137号-1 $방문자$