Git Worktrees
Use for an isolated workspace, linked-worktree assignment, parallel task, PR review, experiment, or explicit worktree lifecycle.
Required follow-up reads
| Need |
Read |
When |
| Exact raw CLI contract |
references/cli.md |
Before invoking this CLI, parsing its JSON, or recovering a raw-CLI lifecycle |
Do not preload the reference for consumer-only or native-manager work.
Route before acting
Choose one role and one lifecycle authority. Preserve state on ambiguity.
1. Consume an existing linked worktree
- Consume the current or explicitly assigned linked worktree in place
- Treat consumer worktrees as read-only by default
- Write only with an explicit assignment binding physical path, common Git directory, and actor/session identity
- Validate that binding through read-only discovery; cwd grants no authority
- Foreign, unassigned, or pre-existing worktrees are consumer-only
- NEVER create, relocate, adopt, reuse, or remove a consumer worktree
2. Use a harness-native manager
- Lifecycle requested? First determine whether a harness-native manager claims it
- A native claim for create or remove owns that mutation
- Use exactly one native manager for its claimed lifecycle
- Keep its stable handle and use that manager for later cleanup
- Native-manager failure? Preserve state; NEVER fall back to raw Git or this CLI
- This raw CLI cannot discover native managers. Use harness context, assignment, and native-manager instructions before selecting it
3. Use this raw-Git CLI
Use it only when all are true:
- The caller explicitly requests a controller-managed lifecycle
- No native manager claims any requested lifecycle mutation
- The target is a usable non-bare Git repository
- The worktree is not foreign, pre-existing, or consumer-assigned
Read references/cli.md first. Invoke only through:
uv run --script <skill-dir>/scripts/cli.py <command> ...
Every normal command returns one JSON line on stdout. Parse it; do not infer success from filesystem state.
Raw-CLI lifecycle
inspect --repo PATH before every lifecycle decision; it is read-only
acquire with explicit owner, session actor, task, name, and mode
- Keep the returned owner capability token secret; it is returned once
- Use the ready worktree only after successful
acquire
handoff before a delegated worker uses the lease; retain its one-time token
- Workers edit only the assigned ready path; they never own lifecycle
complete-handoff --quiescent after every handoff holder stops its task processes
- Check
status when release eligibility or repository state is uncertain
release --quiescent only with the owner token, no active handoffs, and an explicitly requested cleanup
acquire allocates below ${XDG_DATA_HOME:-~/.local/share}/agents/worktrees; callers never choose a destination. New branches use work/<allocated-name>.
Hard no-go actions
- NEVER mix native management, this CLI, and direct raw-Git lifecycle mutations
- NEVER use
--force, direct directory deletion, automatic repair, or stale-lock breaking
- NEVER reset, clean, stash, prune, delete branches, commit, or push as lifecycle work
- NEVER release a dirty, primary, foreign, unregistered, mismatched, or uncertain worktree
- NEVER expose owner or handoff tokens in logs, prompts, task output, or issue text
- NEVER run implicit setup; pass only requested setup argv values
Failure and recovery
- Nonzero or
ok:false means preserve evidence and state
- Failed creation or setup retains a durable failed lease; NEVER auto-clean it
- A conflict, timeout, dirty status, or active handoff is a safe refusal, not a repair request
- Re-run read-only
inspect or status to learn current state
- Use the original manager for recovery. Native-managed state stays native-managed
- Cannot establish ownership, identity, quiescence, or manager authority? Stop lifecycle mutation and report the blocker
1---2name: git-worktrees3description: Use when Git worktrees must be created, consumed, removed, leased, or routed through a worktree manager.4license: AGPL-3.0-or-later5---67# Git Worktrees89Use for an isolated workspace, linked-worktree assignment, parallel task, PR review, experiment, or explicit worktree lifecycle.1011## Required follow-up reads1213|Need|Read|When|14|---|---|---|15|Exact raw CLI contract|`references/cli.md`|Before invoking this CLI, parsing its JSON, or recovering a raw-CLI lifecycle|1617Do not preload the reference for consumer-only or native-manager work.1819## Route before acting2021Choose one role and one lifecycle authority. Preserve state on ambiguity.2223### 1. Consume an existing linked worktree2425- Consume the current or explicitly assigned linked worktree in place26- Treat consumer worktrees as read-only by default27- Write only with an explicit assignment binding physical path, common Git directory, and actor/session identity28- Validate that binding through read-only discovery; cwd grants no authority29- Foreign, unassigned, or pre-existing worktrees are consumer-only30- NEVER create, relocate, adopt, reuse, or remove a consumer worktree3132### 2. Use a harness-native manager3334- Lifecycle requested? First determine whether a harness-native manager claims it35- A native claim for create or remove owns that mutation36- Use exactly one native manager for its claimed lifecycle37- Keep its stable handle and use that manager for later cleanup38- Native-manager failure? Preserve state; NEVER fall back to raw Git or this CLI39- This raw CLI cannot discover native managers. Use harness context, assignment, and native-manager instructions before selecting it4041### 3. Use this raw-Git CLI4243Use it only when all are true:4445- The caller explicitly requests a controller-managed lifecycle46- No native manager claims any requested lifecycle mutation47- The target is a usable non-bare Git repository48- The worktree is not foreign, pre-existing, or consumer-assigned4950Read `references/cli.md` first. Invoke only through:5152```text53uv run --script <skill-dir>/scripts/cli.py <command> ...54```5556Every normal command returns one JSON line on stdout. Parse it; do not infer success from filesystem state.5758## Raw-CLI lifecycle59601. `inspect --repo PATH` before every lifecycle decision; it is read-only612. `acquire` with explicit owner, session actor, task, name, and mode623. Keep the returned owner capability token secret; it is returned once634. Use the ready worktree only after successful `acquire`645. `handoff` before a delegated worker uses the lease; retain its one-time token656. Workers edit only the assigned ready path; they never own lifecycle667. `complete-handoff --quiescent` after every handoff holder stops its task processes678. Check `status` when release eligibility or repository state is uncertain689. `release --quiescent` only with the owner token, no active handoffs, and an explicitly requested cleanup6970`acquire` allocates below `${XDG_DATA_HOME:-~/.local/share}/agents/worktrees`; callers never choose a destination. New branches use `work/<allocated-name>`.7172## Hard no-go actions7374- NEVER mix native management, this CLI, and direct raw-Git lifecycle mutations75- NEVER use `--force`, direct directory deletion, automatic repair, or stale-lock breaking76- NEVER reset, clean, stash, prune, delete branches, commit, or push as lifecycle work77- NEVER release a dirty, primary, foreign, unregistered, mismatched, or uncertain worktree78- NEVER expose owner or handoff tokens in logs, prompts, task output, or issue text79- NEVER run implicit setup; pass only requested setup argv values8081## Failure and recovery8283- Nonzero or `ok:false` means preserve evidence and state84- Failed creation or setup retains a durable failed lease; NEVER auto-clean it85- A conflict, timeout, dirty status, or active handoff is a safe refusal, not a repair request86- Re-run read-only `inspect` or `status` to learn current state87- Use the original manager for recovery. Native-managed state stays native-managed88- Cannot establish ownership, identity, quiescence, or manager authority? Stop lifecycle mutation and report the blocker8990<critical>91Select a native manager before this CLI; the CLI cannot discover one. Consumer and foreign worktrees are never raw-CLI lifecycle targets. On uncertainty or failure, preserve state rather than repairing it.92</critical>