[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7A0MSRXZWBQZKD0R0P95DD5":3,"skill-same:01M7A0MSRXZWBQZKD0R0P95DD5":161},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":32,"commitSha":33,"skillDirectory":34,"forksCount":14,"repositoryHtmlUrl":35,"repositoryHomepageUrl":6,"ownerHtmlUrl":36,"ownerBlogUrl":37,"ownerDescription":38,"updatedAt":39,"install":40,"resources":52},"01M7A0MSRXZWBQZKD0R0P95DD5","worktree",null,"Git worktree management: create, list, remove isolated working copies with env\u002Fconfig symlinks.","mikalv\u002Fpi-extensions","mikalv","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F195767?v=4","01M7A0AYKYSWGA03G3EJ5H66E5","Mikal","01M7A0AYMMCD4MXKTNY69PZS2H",0,"MIT","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: worktree\ndescription: \"Git worktree management: create, list, remove isolated working copies with env\u002Fconfig symlinks.\"\nlicense: MIT\nuser-invocable: true\nargument-hint: \"create \u003CID> [--base \u003Cbranch>] [--from \u003Cref>] [--pr \u003CN>] [--reuse|--restack|--recover-local] [--replay] | restack continue|skip|abort \u003CID|path> | list | remove \u003CID|path>\"\nmetadata:\n  author: vanillagreen\n  source: vstack\n  repository: \"https:\u002F\u002Fgithub.com\u002Fvanillagreencom\u002Fvstack\"\n  bugs: \"https:\u002F\u002Fgithub.com\u002Fvanillagreencom\u002Fvstack\u002Fissues\"\n  version: \"1.0.0\"\n---\n\n# Worktree Management\n\n> **Problem with this skill?** Run `vstack report` — it files to the owning repo automatically. Do not hand-file.\n\nPortable git worktree manager. Worktrees live outside the repo root by default — `\u003Cparent-of-checkout>\u002F.worktrees\u002F\u003Ccheckout-name>\u002F{id}` — so recursive editor\u002Ffile watchers on the repo never ingest worktree build outputs, and sibling repos cannot collide on a shared parent dir. Projects can override the worktree parent directory with `WORKTREE_BASE_DIR`.\n\nIssue IDs used to derive paths must match `[A-Za-z0-9][A-Za-z0-9._-]*` and must not contain `..`; examples such as `issue-779`, `CC-123`, and `ds-enforcement` are valid. Issue-ID resolution prefers the configured base dir and falls back to the worktree registered for the issue branch, so trees created under an older base-dir convention keep working unmoved (`list`\u002F`remove`\u002F`push`\u002F`restack`\u002F`create --reuse`); there is no auto-migration. Path-argument rules and canonicalization: [references\u002Fconfig.md](references\u002Fconfig.md).\n\n```bash\n.agents\u002Fskills\u002Fworktree\u002Fscripts\u002Fworktree \u003Ccommand> [options]\n```\n\n## Commands\n\n| Command | Description |\n|---------|-------------|\n| `create` | Claim a new issue worktree. Refuses implicit reuse when a worktree, branch, or PR already exists. |\n| `restack` | Guardedly continue, skip, or abort a tool-created paused restack. |\n| `list` | List all worktrees |\n| `remove` | Remove worktree, clean symlinks, prune branches |\n| `cleanup` | Remove worktrees whose branches are merged |\n| `path` | Print worktree path for issue ID |\n| `exists` | Check if worktree exists for issue ID |\n| `check` | Pre-create git state check (JSON: uncommitted, unpushed) |\n| `push` | Push worktree branch with auto-rebase |\n| `codex-setup` \u002F `codex-branch` \u002F `codex-cleanup` | Codex Desktop app-created worktree hooks — [references\u002Fhooks.md](references\u002Fhooks.md) |\n| `claude-setup` \u002F `claude-cleanup` | Claude Code worktree hooks (`WorktreeCreate`) — [references\u002Fhooks.md](references\u002Fhooks.md) |\n\n`push` auto-rebases onto the updated base; after an auto-rebase or a completed reuse\u002Frestack, the push uses a `--force-with-lease` pinned to the observed remote OID and fails closed on remote movement, while `--no-rebase` keeps a plain push. Lease authorization internals, the GitHub HTTPS auth fallback, and app-created-checkout resolution: [references\u002Fconfig.md](references\u002Fconfig.md).\n\n`remove` deletes the worktree before the branch and fails closed up front on a native `git worktree lock`; `cleanup` collects only branches proven merged into `origin\u002F\u003Cdefault>`, never zero-commit branches. Both preserve and name what a partial failure leaves behind — failure semantics and manual recovery: [references\u002Frecovery.md](references\u002Frecovery.md).\n\nBare `create \u003CID>` is a new-work claim, not a discovery command. Every new-branch mode, including `--from`, checks the normalized issue branch, an explicit requested branch, and `BOT_NAME\u002F\u003Cissue>` across worktrees, local\u002Fremote refs, and open PRs. Existing ownership exits 75 and leaves local branches unchanged. Origin remote-head or GitHub PR discovery failure exits 1 before worktree config, branch, or target-path mutation; never interpret an outage as absence. Unreachable secondary remotes are skipped with a warning — they cannot receive other sessions' pushes, so only origin is required for the claim gate; reachable secondary remotes still count as ownership signals. A repository-local normalized-issue claim lock holds the final repeated discovery through `git worktree add`, so concurrent claims cannot both mutate. Inspect or monitor owned work instead of spawning a second implementer. Run issue creates as separate commands and check each result; do not batch them in a shell loop whose final successful command can hide an earlier active-work exit.\n\nAn existing owner may opt in with `create \u003CID> --reuse`, which refreshes setup after rebasing onto `origin\u002F\u003Cdefault>`. Reuse\u002Frestack requires the target's exact canonical path to be registered to this repository's common Git directory; incomplete directories are preserved and exit 75. Use `--restack` only to pause that intentional rebase in a conflict state. To inspect existing remote work whose issue worktree is absent, use `create \u003CID> --pr \u003CN>` or `--base \u003Cbranch>` explicitly.\n\n### `create` flags\n\n| Flag | Effect |\n|------|--------|\n| `--base BRANCH` | Checkout an existing remote branch into the worktree |\n| `--from REF` | Create a new branch (named after ID) starting from REF after the normal ownership claim gate |\n| `--pr NUMBER` | Look up the branch from a GitHub PR number (implies `--base`) |\n| `--reuse` | Explicitly reuse an existing issue worktree and rebase it onto `origin\u002F\u003Cdefault>` |\n| `--restack` | When reusing an existing worktree and its rebase onto `origin\u002F\u003Cdefault>` conflicts, stop in the conflict state for resolution instead of aborting |\n| `--replay` | With `--reuse`\u002F`--restack`: run the same restack as an ordered cherry-pick replay with no rebase porcelain, for execution policies that reject `git rebase` |\n| `--recover-local` | Recreate a missing worktree for the exact local-only issue branch without rebasing or rewriting its commits |\n\n### Recovering a local-only branch after worktree loss\n\nIf an issue worktree was removed outside this tool after commits were made but before the branch was pushed, the exact normalized issue branch can survive locally without any checkout. Recover it explicitly with `create ISSUE_ID --recover-local`. Recovery is not a shortcut around the new-work claim gate: bare `create \u003CID>` continues to exit 75 for the surviving local branch and points the owning session to this explicit mode. Recovery accepts only the exact normalized issue branch and never rebases, resets, deletes, or rewrites it; it fails closed on any ownership signal or unreachable remote — full spec: [references\u002Frecovery.md](references\u002Frecovery.md).\n\n### Reuse rebase conflicts\n\nBare `create` never rebases an existing worktree. After the owning session opts in with `--reuse`, the branch rebases onto `origin\u002F\u003Cdefault>`. If that rebase conflicts, the run aborts the rebase and exits 1 — the worktree is left clean on its pre-rebase state, so there is no conflict left to resolve in place. The error lists the conflicting files (captured before the abort) and the two supported recovery paths:\n\n1. **Resolve in place:** re-run `create \u003CID> --restack`. The rebase re-runs and pauses in the conflict state. Resolve the listed files, stage each with `git -C \u003Cpath> add \u003Cfile>`, then run `worktree restack continue \u003CID>`; repeat if it stops again. If the current commit is already represented by the new base and should be omitted, use `worktree restack skip \u003CID>`. Use `worktree restack abort \u003CID>` to restore the pre-restack branch.\n2. **Discard divergence:** `remove \u003CID>` then `create \u003CID>` recreates the worktree fresh from `origin\u002F\u003Cdefault>`, losing the local commits that conflicted.\n\nWith no conflict, `--restack` completes the same intentional rebase as `--reuse`. The guarded actions validate worktree-local authorization, the tool-created state token, and Git sequencer metadata before acting, and fail closed on missing, stale, or unrelated state — internals: [references\u002Frecovery.md](references\u002Frecovery.md).\n\n### Policy-blocked rebase (cherry-pick replay fallback)\n\nSome execution policies reject top-level `git rebase` porcelain outright (Codex `approval_policy = never`). The rejection names the command, not the goal — never retry the porcelain and never substitute a raw `--force` push. Add `--replay` to the guarded restack instead: `create \u003CID> --reuse --replay` (or `create \u003CID> --restack --replay` to pause on conflicts) produces the identical rebased history from ordered plain cherry-picks, with no rebase porcelain at any level. Conflicts pause the same guarded state with the same controls — `worktree restack continue|skip|abort \u003CID>` — and the finished replay records the same pinned force-with-lease authorization that `worktree push` consumes. The tool refuses a dirty tree up front (never replay over uncommitted changes). If the range contains a merge commit the replay is refused as well — use the rebase engine or reconcile manually.\n\n## Recovering a broken `.agents` link\n\nThe configured symlinks (`WORKTREE_SYMLINKS`, typically `.agents`) point from a worktree back into the main checkout, so a large harness library is shared rather than copied per branch. When one goes missing or turns into a real directory, **route the recovery by shape**.\n\n**`git checkout -- .agents` is never the recovery.** The path holds no tracked content, so there is nothing for git to restore; the command succeeds and changes nothing, which reads as \"recovered\" while the link is still broken.\n\n| Symptom | Recovery |\n|---|---|\n| `.agents` missing, or a real directory instead of a symlink (`test -L .agents` fails) | `worktree fix-links \u003CID\\|PATH>` — **from the main checkout** |\n| A genuinely modified or corrupt **tracked** file | `git checkout -- \u003Cpath>` — run in the checkout the file really lives in |\n\nA tracked file *can* sit under a symlinked path — a project may symlink a directory it also tracks content in — and there `git checkout` from the worktree writes through the link into the main checkout while `assume-unchanged` keeps `git status` clean in both; recover at the real path in the owning checkout ([references\u002Fconfig.md](references\u002Fconfig.md)).\n\n**Run `fix-links` from the main checkout, not from the broken worktree** — the worktree's own copy of this script is reached *through* the link that is broken, so invoking it from there is the one place it may not exist. `fix-links` is also the repair after any operation that can replace a configured symlink with tracked content — a manual rebase or a partially-completed `remove`. Until the link is fixed, do not trust local verification from that tree: [references\u002Frecovery.md](references\u002Frecovery.md).\n\n**Consumers: carry this inline; do not point here.** In a consumer install this section is itself read through `.agents`, so from the worktree whose link is broken it is unreachable exactly when it is needed — a consumer repo's own tracked file (`AGENTS.md` \u002F `CLAUDE.md`) is readable in that state, so that is where the recovery text belongs. Copy it verbatim:\n\n```text\nBroken `.agents` in a worktree (missing, or a real directory): from the MAIN checkout run\n`.agents\u002Fskills\u002Fworktree\u002Fscripts\u002Fworktree fix-links \u003CID|PATH>` — never from the worktree,\nand never `git checkout -- .agents` (the path holds no tracked content, so the command\nchanges nothing while the link stays broken). A genuinely corrupt tracked file is the other\ncase: `git checkout -- \u003Cpath>`, run in the checkout the file really lives in (the main\ncheckout when the path sits under a configured symlink).\n```\n\n## Session guard (ownership leases)\n\n`scripts\u002Fworktree-session-guard` stops cleanup from destroying a worktree a session is still working in. The lease is recorded as a **native Git worktree lock** whose reason line carries the owner and heartbeat, so `git worktree remove [--force]` refuses it and `git worktree prune` never prunes the registration — even after the directory itself is gone.\n\n**Claiming is explicit; the destructive commands are wired.** Owner defaults to `$VSTACK_SESSION_OWNER`, else `$USER`; the workflow sets it to the issue ID:\n\n```bash\nscripts\u002Fworktree-session-guard claim   \u003CPATH> --owner \u003CID>\nscripts\u002Fworktree-session-guard status  \u003CPATH> --owner \u003CID>   # read-only probe\nscripts\u002Fworktree-session-guard release \u003CPATH> --owner \u003CID>\nscripts\u002Fworktree-session-guard sweep --dry-run               # every lease past the TTL\n```\n\n**Exit codes** — `status` answers \"may I work here?\" by exit code alone: 0 lease for this owner, 1 path not registered, 3 unclaimed, 4 locked outside the guard, 75 claimed by a different owner. Use `status`, not `claim`, to probe: `claim` takes or rewrites the lease.\n\n**`--repo` applies only to `release`\u002F`status`\u002F`list`\u002F`sweep`.** `claim` and `refresh` reject it, because the target worktree is itself a checkout of the repository. Passing it makes every claim fail, and a best-effort wrapper around that swallows the error — the guard then looks installed while silently never claiming, with `status` returning 3 as the only symptom.\n\n### Lifecycle\n\n| Command | Behaviour |\n|---|---|\n| `worktree create` | **Never claims.** A fresh worktree is unclaimed. |\n| `worktree create --reuse\\|--restack` | Refuses a foreign lease by name (exit 75); **refreshes** its own in place, so a long reuse cycle cannot age past the TTL and be swept. |\n| `worktree remove` | Releases **its own** lease before removing, so a claiming session can tear down its own tree. A foreign lease is left alone and refuses the removal, naming the owner. |\n| `worktree cleanup` | **Never collects a claimed worktree** — not even one this session claimed, since our own lease still means work is in progress. Every skip is reported; a quiet cleanup means nothing was held back. |\n| `worktree cleanup --stale [--ttl-minutes N]` | Additionally releases and collects leases past the TTL (default 720) — the abandoned-session recovery path. |\n\nClaiming is the caller's job: orch claims in `orch\u002Fworkflows\u002Finitialize.md` once the worktree is the session's, and `remove` releases at teardown. Design rationale and the guard's limits — shared same-issue leases, staleness without liveness, flock availability, what the lock does not block, and the `$USER` owner fallback: [references\u002Fsession-guard.md](references\u002Fsession-guard.md).\n\n## System Dependencies\n\n`git`; authenticated `gh` for new-work PR ownership discovery; `flock` for repository-local per-issue claim serialization (the session guard prefers it and falls back to a `mkdir` mutex without it); Bash 3.2+ (macOS system bash is supported).\n\n## Configuration\n\nSet non-sensitive defaults in committed `vstack.settings.toml` under `[env]`. Existing `.env` and `.env.local` variables still work, and `.env.local` wins for secrets or personal overrides. Setup is driven by `WORKTREE_BASE_DIR` (worktree parent directory), `WORKTREE_SYMLINKS`, `WORKTREE_RELATIVE_SYMLINKS`, `WORKTREE_COPIES`, and `WORKTREE_MKDIRS`. **Symlink untracked paths only** — an entry that shadows tracked files makes git refuse writes in that worktree while `git status` reports clean. Variable semantics, setup-path hardening, tracked-content and `info\u002Fexclude` mechanics, and a worked example: [references\u002Fconfig.md](references\u002Fconfig.md).\n","# Worktree Management\n\n> **Problem with this skill?** Run `vstack report` — it files to the owning repo automatically. Do not hand-file.\n\nPortable git worktree manager. Worktrees live outside the repo root by default — `\u003Cparent-of-checkout>\u002F.worktrees\u002F\u003Ccheckout-name>\u002F{id}` — so recursive editor\u002Ffile watchers on the repo never ingest worktree build outputs, and sibling repos cannot collide on a shared parent dir. Projects can override the worktree parent directory with `WORKTREE_BASE_DIR`.\n\nIssue IDs used to derive paths must match `[A-Za-z0-9][A-Za-z0-9._-]*` and must not contain `..`; examples such as `issue-779`, `CC-123`, and `ds-enforcement` are valid. Issue-ID resolution prefers the configured base dir and falls back to the worktree registered for the issue branch, so trees created under an older base-dir convention keep working unmoved (`list`\u002F`remove`\u002F`push`\u002F`restack`\u002F`create --reuse`); there is no auto-migration. Path-argument rules and canonicalization: [references\u002Fconfig.md](references\u002Fconfig.md).\n\n```bash\n.agents\u002Fskills\u002Fworktree\u002Fscripts\u002Fworktree \u003Ccommand> [options]\n```\n\n## Commands\n\n| Command | Description |\n|---------|-------------|\n| `create` | Claim a new issue worktree. Refuses implicit reuse when a worktree, branch, or PR already exists. |\n| `restack` | Guardedly continue, skip, or abort a tool-created paused restack. |\n| `list` | List all worktrees |\n| `remove` | Remove worktree, clean symlinks, prune branches |\n| `cleanup` | Remove worktrees whose branches are merged |\n| `path` | Print worktree path for issue ID |\n| `exists` | Check if worktree exists for issue ID |\n| `check` | Pre-create git state check (JSON: uncommitted, unpushed) |\n| `push` | Push worktree branch with auto-rebase |\n| `codex-setup` \u002F `codex-branch` \u002F `codex-cleanup` | Codex Desktop app-created worktree hooks — [references\u002Fhooks.md](references\u002Fhooks.md) |\n| `claude-setup` \u002F `claude-cleanup` | Claude Code worktree hooks (`WorktreeCreate`) — [references\u002Fhooks.md](references\u002Fhooks.md) |\n\n`push` auto-rebases onto the updated base; after an auto-rebase or a completed reuse\u002Frestack, the push uses a `--force-with-lease` pinned to the observed remote OID and fails closed on remote movement, while `--no-rebase` keeps a plain push. Lease authorization internals, the GitHub HTTPS auth fallback, and app-created-checkout resolution: [references\u002Fconfig.md](references\u002Fconfig.md).\n\n`remove` deletes the worktree before the branch and fails closed up front on a native `git worktree lock`; `cleanup` collects only branches proven merged into `origin\u002F\u003Cdefault>`, never zero-commit branches. Both preserve and name what a partial failure leaves behind — failure semantics and manual recovery: [references\u002Frecovery.md](references\u002Frecovery.md).\n\nBare `create \u003CID>` is a new-work claim, not a discovery command. Every new-branch mode, including `--from`, checks the normalized issue branch, an explicit requested branch, and `BOT_NAME\u002F\u003Cissue>` across worktrees, local\u002Fremote refs, and open PRs. Existing ownership exits 75 and leaves local branches unchanged. Origin remote-head or GitHub PR discovery failure exits 1 before worktree config, branch, or target-path mutation; never interpret an outage as absence. Unreachable secondary remotes are skipped with a warning — they cannot receive other sessions' pushes, so only origin is required for the claim gate; reachable secondary remotes still count as ownership signals. A repository-local normalized-issue claim lock holds the final repeated discovery through `git worktree add`, so concurrent claims cannot both mutate. Inspect or monitor owned work instead of spawning a second implementer. Run issue creates as separate commands and check each result; do not batch them in a shell loop whose final successful command can hide an earlier active-work exit.\n\nAn existing owner may opt in with `create \u003CID> --reuse`, which refreshes setup after rebasing onto `origin\u002F\u003Cdefault>`. Reuse\u002Frestack requires the target's exact canonical path to be registered to this repository's common Git directory; incomplete directories are preserved and exit 75. Use `--restack` only to pause that intentional rebase in a conflict state. To inspect existing remote work whose issue worktree is absent, use `create \u003CID> --pr \u003CN>` or `--base \u003Cbranch>` explicitly.\n\n### `create` flags\n\n| Flag | Effect |\n|------|--------|\n| `--base BRANCH` | Checkout an existing remote branch into the worktree |\n| `--from REF` | Create a new branch (named after ID) starting from REF after the normal ownership claim gate |\n| `--pr NUMBER` | Look up the branch from a GitHub PR number (implies `--base`) |\n| `--reuse` | Explicitly reuse an existing issue worktree and rebase it onto `origin\u002F\u003Cdefault>` |\n| `--restack` | When reusing an existing worktree and its rebase onto `origin\u002F\u003Cdefault>` conflicts, stop in the conflict state for resolution instead of aborting |\n| `--replay` | With `--reuse`\u002F`--restack`: run the same restack as an ordered cherry-pick replay with no rebase porcelain, for execution policies that reject `git rebase` |\n| `--recover-local` | Recreate a missing worktree for the exact local-only issue branch without rebasing or rewriting its commits |\n\n### Recovering a local-only branch after worktree loss\n\nIf an issue worktree was removed outside this tool after commits were made but before the branch was pushed, the exact normalized issue branch can survive locally without any checkout. Recover it explicitly with `create ISSUE_ID --recover-local`. Recovery is not a shortcut around the new-work claim gate: bare `create \u003CID>` continues to exit 75 for the surviving local branch and points the owning session to this explicit mode. Recovery accepts only the exact normalized issue branch and never rebases, resets, deletes, or rewrites it; it fails closed on any ownership signal or unreachable remote — full spec: [references\u002Frecovery.md](references\u002Frecovery.md).\n\n### Reuse rebase conflicts\n\nBare `create` never rebases an existing worktree. After the owning session opts in with `--reuse`, the branch rebases onto `origin\u002F\u003Cdefault>`. If that rebase conflicts, the run aborts the rebase and exits 1 — the worktree is left clean on its pre-rebase state, so there is no conflict left to resolve in place. The error lists the conflicting files (captured before the abort) and the two supported recovery paths:\n\n1. **Resolve in place:** re-run `create \u003CID> --restack`. The rebase re-runs and pauses in the conflict state. Resolve the listed files, stage each with `git -C \u003Cpath> add \u003Cfile>`, then run `worktree restack continue \u003CID>`; repeat if it stops again. If the current commit is already represented by the new base and should be omitted, use `worktree restack skip \u003CID>`. Use `worktree restack abort \u003CID>` to restore the pre-restack branch.\n2. **Discard divergence:** `remove \u003CID>` then `create \u003CID>` recreates the worktree fresh from `origin\u002F\u003Cdefault>`, losing the local commits that conflicted.\n\nWith no conflict, `--restack` completes the same intentional rebase as `--reuse`. The guarded actions validate worktree-local authorization, the tool-created state token, and Git sequencer metadata before acting, and fail closed on missing, stale, or unrelated state — internals: [references\u002Frecovery.md](references\u002Frecovery.md).\n\n### Policy-blocked rebase (cherry-pick replay fallback)\n\nSome execution policies reject top-level `git rebase` porcelain outright (Codex `approval_policy = never`). The rejection names the command, not the goal — never retry the porcelain and never substitute a raw `--force` push. Add `--replay` to the guarded restack instead: `create \u003CID> --reuse --replay` (or `create \u003CID> --restack --replay` to pause on conflicts) produces the identical rebased history from ordered plain cherry-picks, with no rebase porcelain at any level. Conflicts pause the same guarded state with the same controls — `worktree restack continue|skip|abort \u003CID>` — and the finished replay records the same pinned force-with-lease authorization that `worktree push` consumes. The tool refuses a dirty tree up front (never replay over uncommitted changes). If the range contains a merge commit the replay is refused as well — use the rebase engine or reconcile manually.\n\n## Recovering a broken `.agents` link\n\nThe configured symlinks (`WORKTREE_SYMLINKS`, typically `.agents`) point from a worktree back into the main checkout, so a large harness library is shared rather than copied per branch. When one goes missing or turns into a real directory, **route the recovery by shape**.\n\n**`git checkout -- .agents` is never the recovery.** The path holds no tracked content, so there is nothing for git to restore; the command succeeds and changes nothing, which reads as \"recovered\" while the link is still broken.\n\n| Symptom | Recovery |\n|---|---|\n| `.agents` missing, or a real directory instead of a symlink (`test -L .agents` fails) | `worktree fix-links \u003CID\\|PATH>` — **from the main checkout** |\n| A genuinely modified or corrupt **tracked** file | `git checkout -- \u003Cpath>` — run in the checkout the file really lives in |\n\nA tracked file *can* sit under a symlinked path — a project may symlink a directory it also tracks content in — and there `git checkout` from the worktree writes through the link into the main checkout while `assume-unchanged` keeps `git status` clean in both; recover at the real path in the owning checkout ([references\u002Fconfig.md](references\u002Fconfig.md)).\n\n**Run `fix-links` from the main checkout, not from the broken worktree** — the worktree's own copy of this script is reached *through* the link that is broken, so invoking it from there is the one place it may not exist. `fix-links` is also the repair after any operation that can replace a configured symlink with tracked content — a manual rebase or a partially-completed `remove`. Until the link is fixed, do not trust local verification from that tree: [references\u002Frecovery.md](references\u002Frecovery.md).\n\n**Consumers: carry this inline; do not point here.** In a consumer install this section is itself read through `.agents`, so from the worktree whose link is broken it is unreachable exactly when it is needed — a consumer repo's own tracked file (`AGENTS.md` \u002F `CLAUDE.md`) is readable in that state, so that is where the recovery text belongs. Copy it verbatim:\n\n```text\nBroken `.agents` in a worktree (missing, or a real directory): from the MAIN checkout run\n`.agents\u002Fskills\u002Fworktree\u002Fscripts\u002Fworktree fix-links \u003CID|PATH>` — never from the worktree,\nand never `git checkout -- .agents` (the path holds no tracked content, so the command\nchanges nothing while the link stays broken). A genuinely corrupt tracked file is the other\ncase: `git checkout -- \u003Cpath>`, run in the checkout the file really lives in (the main\ncheckout when the path sits under a configured symlink).\n```\n\n## Session guard (ownership leases)\n\n`scripts\u002Fworktree-session-guard` stops cleanup from destroying a worktree a session is still working in. The lease is recorded as a **native Git worktree lock** whose reason line carries the owner and heartbeat, so `git worktree remove [--force]` refuses it and `git worktree prune` never prunes the registration — even after the directory itself is gone.\n\n**Claiming is explicit; the destructive commands are wired.** Owner defaults to `$VSTACK_SESSION_OWNER`, else `$USER`; the workflow sets it to the issue ID:\n\n```bash\nscripts\u002Fworktree-session-guard claim   \u003CPATH> --owner \u003CID>\nscripts\u002Fworktree-session-guard status  \u003CPATH> --owner \u003CID>   # read-only probe\nscripts\u002Fworktree-session-guard release \u003CPATH> --owner \u003CID>\nscripts\u002Fworktree-session-guard sweep --dry-run               # every lease past the TTL\n```\n\n**Exit codes** — `status` answers \"may I work here?\" by exit code alone: 0 lease for this owner, 1 path not registered, 3 unclaimed, 4 locked outside the guard, 75 claimed by a different owner. Use `status`, not `claim`, to probe: `claim` takes or rewrites the lease.\n\n**`--repo` applies only to `release`\u002F`status`\u002F`list`\u002F`sweep`.** `claim` and `refresh` reject it, because the target worktree is itself a checkout of the repository. Passing it makes every claim fail, and a best-effort wrapper around that swallows the error — the guard then looks installed while silently never claiming, with `status` returning 3 as the only symptom.\n\n### Lifecycle\n\n| Command | Behaviour |\n|---|---|\n| `worktree create` | **Never claims.** A fresh worktree is unclaimed. |\n| `worktree create --reuse\\|--restack` | Refuses a foreign lease by name (exit 75); **refreshes** its own in place, so a long reuse cycle cannot age past the TTL and be swept. |\n| `worktree remove` | Releases **its own** lease before removing, so a claiming session can tear down its own tree. A foreign lease is left alone and refuses the removal, naming the owner. |\n| `worktree cleanup` | **Never collects a claimed worktree** — not even one this session claimed, since our own lease still means work is in progress. Every skip is reported; a quiet cleanup means nothing was held back. |\n| `worktree cleanup --stale [--ttl-minutes N]` | Additionally releases and collects leases past the TTL (default 720) — the abandoned-session recovery path. |\n\nClaiming is the caller's job: orch claims in `orch\u002Fworkflows\u002Finitialize.md` once the worktree is the session's, and `remove` releases at teardown. Design rationale and the guard's limits — shared same-issue leases, staleness without liveness, flock availability, what the lock does not block, and the `$USER` owner fallback: [references\u002Fsession-guard.md](references\u002Fsession-guard.md).\n\n## System Dependencies\n\n`git`; authenticated `gh` for new-work PR ownership discovery; `flock` for repository-local per-issue claim serialization (the session guard prefers it and falls back to a `mkdir` mutex without it); Bash 3.2+ (macOS system bash is supported).\n\n## Configuration\n\nSet non-sensitive defaults in committed `vstack.settings.toml` under `[env]`. Existing `.env` and `.env.local` variables still work, and `.env.local` wins for secrets or personal overrides. Setup is driven by `WORKTREE_BASE_DIR` (worktree parent directory), `WORKTREE_SYMLINKS`, `WORKTREE_RELATIVE_SYMLINKS`, `WORKTREE_COPIES`, and `WORKTREE_MKDIRS`. **Symlink untracked paths only** — an entry that shadows tracked files makes git refuse writes in that worktree while `git status` reports clean. Variable semantics, setup-path hardening, tracked-content and `info\u002Fexclude` mechanics, and a worked example: [references\u002Fconfig.md](references\u002Fconfig.md).\n",{"name":5,"license":15,"metadata":24,"description":7,"argument-hint":30,"user-invocable":31},{"bugs":25,"author":26,"source":27,"version":28,"repository":29},"https:\u002F\u002Fgithub.com\u002Fvanillagreencom\u002Fvstack\u002Fissues","vanillagreen","vstack","1.0.0","https:\u002F\u002Fgithub.com\u002Fvanillagreencom\u002Fvstack","create \u003CID> [--base \u003Cbranch>] [--from \u003Cref>] [--pr \u003CN>] [--reuse|--restack|--recover-local] [--replay] | restack continue|skip|abort \u003CID|path> | list | remove \u003CID|path>",true,"main","fb378999f2dc37c99509f063e9c6c3a6051b3db5","packages\u002Fvstack\u002Fskills\u002Fworktree","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions","https:\u002F\u002Fgithub.com\u002Fmikalv","http:\u002F\u002Fmikalv.net","Working as security architect and programmer. Language agnostic, security focused.","2026-08-31 05:30:23",{"source":8,"skillName":5,"commands":41,"prompt":51,"zipAvailable":31},[42,45,48],{"tool":43,"command":44},"npx","npx skills add mikalv\u002Fpi-extensions --skill worktree",{"tool":46,"command":47},"bunx","bunx skills add mikalv\u002Fpi-extensions --skill worktree",{"tool":49,"command":50},"pnpm","pnpm dlx skills add mikalv\u002Fpi-extensions --skill worktree","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002FSKILL.md",[53,59,63,67,71,75,81,85,89,93,97,101,105,109,113,117,121,125,129,133,137,141,145,149,153,157],{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"README.md","REFERENCE","参考文档",19350,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002FREADME.md",{"path":60,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":61,"sourceHtmlUrl":62},"references\u002Fconfig.md",7999,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Freferences\u002Fconfig.md",{"path":64,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":65,"sourceHtmlUrl":66},"references\u002Fhooks.md",1979,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Freferences\u002Fhooks.md",{"path":68,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":69,"sourceHtmlUrl":70},"references\u002Frecovery.md",4717,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Freferences\u002Frecovery.md",{"path":72,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fsession-guard.md",3826,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Freferences\u002Fsession-guard.md",{"path":76,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":79,"sourceHtmlUrl":80},"scripts\u002Flib\u002Fvstack-env.sh","SCRIPT","脚本",4949,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Fscripts\u002Flib\u002Fvstack-env.sh",{"path":82,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":83,"sourceHtmlUrl":84},"scripts\u002Fworktree",141966,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Fscripts\u002Fworktree",{"path":86,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":87,"sourceHtmlUrl":88},"scripts\u002Fworktree-session-guard",44364,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Fscripts\u002Fworktree-session-guard",{"path":90,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":91,"sourceHtmlUrl":92},"tests\u002Fbash32-portability.test.sh",843,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fbash32-portability.test.sh",{"path":94,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":95,"sourceHtmlUrl":96},"tests\u002Fworktree_atomic_symlink_swap.sh",6194,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_atomic_symlink_swap.sh",{"path":98,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":99,"sourceHtmlUrl":100},"tests\u002Fworktree_base_dir.sh",16012,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_base_dir.sh",{"path":102,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":103,"sourceHtmlUrl":104},"tests\u002Fworktree_create_active_guard.sh",21642,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_create_active_guard.sh",{"path":106,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":107,"sourceHtmlUrl":108},"tests\u002Fworktree_create_restack.sh",29230,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_create_restack.sh",{"path":110,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":111,"sourceHtmlUrl":112},"tests\u002Fworktree_create_secondary_remote.sh",5918,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_create_secondary_remote.sh",{"path":114,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":115,"sourceHtmlUrl":116},"tests\u002Fworktree_exclude_tracked_paths.sh",7274,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_exclude_tracked_paths.sh",{"path":118,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":119,"sourceHtmlUrl":120},"tests\u002Fworktree_for_branch.sh",2754,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_for_branch.sh",{"path":122,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":123,"sourceHtmlUrl":124},"tests\u002Fworktree_materialized_links.sh",5094,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_materialized_links.sh",{"path":126,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":127,"sourceHtmlUrl":128},"tests\u002Fworktree_path_safety.sh",15708,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_path_safety.sh",{"path":130,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":131,"sourceHtmlUrl":132},"tests\u002Fworktree_push_rebase.sh",14091,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_push_rebase.sh",{"path":134,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":135,"sourceHtmlUrl":136},"tests\u002Fworktree_recover_local.sh",17364,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_recover_local.sh",{"path":138,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":139,"sourceHtmlUrl":140},"tests\u002Fworktree_remove.sh",37794,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_remove.sh",{"path":142,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":143,"sourceHtmlUrl":144},"tests\u002Fworktree_restack_replay.sh",24510,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_restack_replay.sh",{"path":146,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":147,"sourceHtmlUrl":148},"tests\u002Fworktree_reuse_shadowed_tracked.sh",5174,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_reuse_shadowed_tracked.sh",{"path":150,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":151,"sourceHtmlUrl":152},"tests\u002Fworktree_session_guard_lifecycle.sh",19108,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_session_guard_lifecycle.sh",{"path":154,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":155,"sourceHtmlUrl":156},"tests\u002Fworktree_session_guard.sh",57097,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_session_guard.sh",{"path":158,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":159,"sourceHtmlUrl":160},"tests\u002Fworktree_symlink_shadows_tracked.sh",3892,"https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fworktree\u002Ftests\u002Fworktree_symlink_shadows_tracked.sh",[162,169,176,183,190,197],{"skillNo":163,"name":164,"nameZh":6,"description":165,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":166,"categories":167,"keywords":168,"publishedAt":19},"01M7A0MN8FKR35HEGY848RMG6M","trading-design","Professional trading UI design system. Load when designing or implementing panels, layouts, typography, color, data display, or interactions for trading applications.","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Ftrading-design\u002FSKILL.md",[],[],{"skillNo":170,"name":171,"nameZh":6,"description":172,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":173,"categories":174,"keywords":175,"publishedAt":19},"01M7A0MJ4B7Q0A1GBJJ1478Q8W","second-opinion","Cross-model second opinion: review, challenge, audit, and consult via an external AI CLI (Claude ↔ Codex).","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fsecond-opinion\u002FSKILL.md",[],[],{"skillNo":177,"name":178,"nameZh":6,"description":179,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":180,"categories":181,"keywords":182,"publishedAt":19},"01M7A0MDP1TBYG2VY62251V0D7","reviewer","Strict review and QA workflows: shared reviewer ethos, scope boundaries, code-review classification, finding JSON schema, and QA-label review lifecycle. Load this skill when reviewing a diff, classifying findings, returning a verdict, or handling a QA-label-triggered review.","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Freviewer\u002FSKILL.md",[],[],{"skillNo":184,"name":185,"nameZh":6,"description":186,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":187,"categories":188,"keywords":189,"publishedAt":19},"01M7A0M8R2XGVQ4G0VMZ75RJ13","project-management","TPM-orchestrated planning, audit, roadmap, and research-driven decomposition. Owns the user-facing wrappers (cycle-plan, audit-issues, roadmap-*, research-*) and the underlying TPM execution workflows.","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fproject-management\u002FSKILL.md",[],[],{"skillNo":191,"name":192,"nameZh":6,"description":193,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":194,"categories":195,"keywords":196,"publishedAt":19},"01M7A0M5AKQFWPCTAJ0Q0AG3A6","price-handling","f64 price patterns for trading systems. Load when: comparing prices, rounding to tick size, formatting for display\u002Fbroker APIs, parsing market feeds, designing price types or SymbolSpec structs.","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Fprice-handling\u002FSKILL.md",[],[],{"skillNo":198,"name":199,"nameZh":6,"description":200,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":201,"categories":202,"keywords":203,"publishedAt":19},"01M7A0M0T2AFK5M02JJD994X0S","orch","PRIMARY AGENT ONLY — single work-item orchestration for Linear or GitHub issues: prepare, delegate implementation, review, submit, merge, and handoff.","https:\u002F\u002Fgithub.com\u002Fmikalv\u002Fpi-extensions\u002Fblob\u002Fmain\u002Fpackages\u002Fvstack\u002Fskills\u002Forch\u002FSKILL.md",[],[]]