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---2disable-model-invocation: true3name: git-worktrees4description: "Use when Git worktrees must be created, consumed, removed, leased, or routed through a worktree manager."5license: AGPL-3.0-or-later6---78# Git Worktrees910Use for an isolated workspace, linked-worktree assignment, parallel task, PR review, experiment, or explicit worktree lifecycle.1112## Required follow-up reads1314|Need|Read|When|15|---|---|---|16|Exact raw CLI contract|`references/cli.md`|Before invoking this CLI, parsing its JSON, or recovering a raw-CLI lifecycle|1718Do not preload the reference for consumer-only or native-manager work.1920## Route before acting2122Choose one role and one lifecycle authority. Preserve state on ambiguity.2324### 1. Consume an existing linked worktree2526- Consume the current or explicitly assigned linked worktree in place27- Treat consumer worktrees as read-only by default28- Write only with an explicit assignment binding physical path, common Git directory, and actor/session identity29- Validate that binding through read-only discovery; cwd grants no authority30- Foreign, unassigned, or pre-existing worktrees are consumer-only31- NEVER create, relocate, adopt, reuse, or remove a consumer worktree3233### 2. Use a harness-native manager3435- Lifecycle requested? First determine whether a harness-native manager claims it36- A native claim for create or remove owns that mutation37- Use exactly one native manager for its claimed lifecycle38- Keep its stable handle and use that manager for later cleanup39- Native-manager failure? Preserve state; NEVER fall back to raw Git or this CLI40- This raw CLI cannot discover native managers. Use harness context, assignment, and native-manager instructions before selecting it4142### 3. Use this raw-Git CLI4344Use it only when all are true:4546- The caller explicitly requests a controller-managed lifecycle47- No native manager claims any requested lifecycle mutation48- The target is a usable non-bare Git repository49- The worktree is not foreign, pre-existing, or consumer-assigned5051Read `references/cli.md` first. Invoke only through:5253```text54uv run --script <skill-dir>/scripts/cli.py <command> ...55```5657Every normal command returns one JSON line on stdout. Parse it; do not infer success from filesystem state.5859## Raw-CLI lifecycle60611. `inspect --repo PATH` before every lifecycle decision; it is read-only622. `acquire` with explicit owner, session actor, task, name, and mode633. Keep the returned owner capability token secret; it is returned once644. Use the ready worktree only after successful `acquire`655. `handoff` before a delegated worker uses the lease; retain its one-time token666. Workers edit only the assigned ready path; they never own lifecycle677. `complete-handoff --quiescent` after every handoff holder stops its task processes688. Check `status` when release eligibility or repository state is uncertain699. `release --quiescent` only with the owner token, no active handoffs, and an explicitly requested cleanup7071`acquire` allocates below `${XDG_DATA_HOME:-~/.local/share}/agents/worktrees`; callers never choose a destination. New branches use `work/<allocated-name>`.7273## Hard no-go actions7475- NEVER mix native management, this CLI, and direct raw-Git lifecycle mutations76- NEVER use `--force`, direct directory deletion, automatic repair, or stale-lock breaking77- NEVER reset, clean, stash, prune, delete branches, commit, or push as lifecycle work78- NEVER release a dirty, primary, foreign, unregistered, mismatched, or uncertain worktree79- NEVER expose owner or handoff tokens in logs, prompts, task output, or issue text80- NEVER run implicit setup; pass only requested setup argv values8182## Failure and recovery8384- Nonzero or `ok:false` means preserve evidence and state85- Failed creation or setup retains a durable failed lease; NEVER auto-clean it86- A conflict, timeout, dirty status, or active handoff is a safe refusal, not a repair request87- Re-run read-only `inspect` or `status` to learn current state88- Use the original manager for recovery. Native-managed state stays native-managed89- Cannot establish ownership, identity, quiescence, or manager authority? Stop lifecycle mutation and report the blocker9091<critical>92Select 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.93</critical>