Skip to content
Back to skills

Git Worktrees

ASecurity

Use when creating, removing, or managing Git worktrees for isolated branch development, parallel tasks, or testing.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 14, 2026
researchgotestinggit

Works with

  • cli

Security analysis

A100/100

Pro scans all 14 files and shows the line behind each finding

Scanned November 14, 2026

npx -y skills add anntnzrb/agents --skill git-worktrees --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Worktrees?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Worktrees
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/anntnzrb-git-worktrees/badge)](https://www.skillsdirectory.com/skills/anntnzrb-git-worktrees)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-worktrees
description: "Use when creating, removing, or managing Git worktrees for isolated branch development, parallel tasks, or testing."
license: AGPL-3.0-or-later
---

# 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:

```text
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

1. `inspect --repo PATH` before every lifecycle decision; it is read-only
2. `acquire` with explicit owner, session actor, task, name, and mode
3. Keep the returned owner capability token secret; it is returned once
4. Use the ready worktree only after successful `acquire`
5. `handoff` before a delegated worker uses the lease; retain its one-time token
6. Workers edit only the assigned ready path; they never own lifecycle
7. `complete-handoff --quiescent` after every handoff holder stops its task processes
8. Check `status` when release eligibility or repository state is uncertain
9. `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

<critical>
Select 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.
</critical>

Files in this skill

  • SKILL.md4.3 KB
  • lib/git_worktrees/__init__.py741 B
  • lib/git_worktrees/cli.py20.4 KB
  • lib/git_worktrees/controller.py14.1 KB
  • lib/git_worktrees/errors.py2 KB
  • lib/git_worktrees/git.py12 KB
  • lib/git_worktrees/models.py3.7 KB
  • lib/git_worktrees/paths.py423 B
  • lib/git_worktrees/service.py35.8 KB
  • pyproject.toml2.6 KB
  • references/cli.md7.3 KB
  • scripts/cli.py355 B
  • tests/test_cli.py26.5 KB
  • uv.lock14.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in research →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.