worktree-detection

Detect a Git worktree path by matching a task identifier.

26|4|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/marmelab/crm-builder --skill worktree-detection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: worktree-detection
Source: https://github.com/marmelab/crm-builder/tree/main/claudeConfig/.claude/skills/worktree-detection
Command: npx skills add https://github.com/marmelab/crm-builder --skill worktree-detection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of locating a specific Git worktree for a given task number without relying on hardcoded directory paths.

Core Features & Use Cases

  • Worktree discovery by task identifier: Locates the correct worktree path by matching the task number embedded in git worktree list output.
  • Hook/script friendly behavior: Exits cleanly with a skip message when no matching worktree exists, avoiding failures during automated runs.
  • Flexible task number extraction: Derives TASK_NUM from TASK_OWNER and TASK_SUBJECT using a TASK-\d+ pattern so it works across varying agent variable formats.

Quick Start

In your hook or automation script, set TASK_NUM to the task you want (for example TASK-005) and run the detection snippet to resolve the matching worktree path or skip if none exists.

Frequently Asked Questions about worktree-detection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find a specific Git worktree path by task number in an automation script?

To find a specific Git worktree path by task number, match a task identifier like TASK-005 against the output of git worktree list. The detection snippet parses the porcelain output, selects the first matching directory, and validates that it exists.

What happens if a hook tries to find a Git worktree but no match is found?

When no matching Git worktree is found, the detection script exits cleanly with a skip message instead of failing. This prevents automated CI hooks and agent-driven workflows from crashing when a specific task worktree does not exist.

Can I extract a task number from agent variables to locate a Git worktree?

Yes, you can extract a task number from agent variables like TASK_OWNER and TASK_SUBJECT. The detection logic uses a TASK-\d+ pattern to derive the task number, allowing it to locate the correct worktree across varying agent variable formats.

What is the best way to avoid hardcoded paths when running scripts on per-task Git worktrees?

The best way to avoid hardcoded paths in per-task worktree scripts is to dynamically discover the directory by matching a task identifier against git worktree list output. This approach validates the selected path before executing operations.

Does worktree path discovery work with CI hooks and agent-driven development workflows?

Yes, worktree path discovery works with CI hooks and agent-driven development workflows. It is specifically designed to parse git worktree list output, select the first matching directory, and gracefully skip execution if no match is found.