worktree-plus
v1.1.1
Published
Create git worktrees that actually run - hydrates gitignored paths (node_modules, .env, build caches) from .wt-copy / .wt-symlink manifests.
Maintainers
Readme
worktree-plus
Git worktrees that actually run.
git worktree add checks out tracked files only. So a fresh worktree has no
node_modules, no .env, no build caches — it looks correct and does not run. wtp creates
the worktree and then hydrates it from two manifests you control.
wtp new fix-login # create .worktrees/fix-login + hydrate it
cd .worktrees/fix-login # ready to run
wtp ls # what exists
wtp rm fix-login # refuses if you have uncommitted workInstall
npm i -g worktree-plus # gives you `wtp`
npx -y worktree-plus new fix-login # or don't install it at allRequires Node >= 24.15 and git >= 2.31. No runtime dependencies.
The manifests
Two gitignore-style files — one path per line, # comments and blank lines ignored:
| File | Effect | Use for |
|---|---|---|
| .wt-copy | cp -R into the worktree | .env files, anything the worktree may modify |
| .wt-symlink | ln -s into the worktree | heavy dirs the worktree only reads |
# .wt-copy
.env
apps/api/.env
packages/database/.envEvery entry is relative and resolves against the target repo — one apps/api/.env line
serves every checkout of that repo. Nothing is implicit: a .env travels only if a manifest
names it.
⚠️ A .wt-symlink entry points at the origin repo's real directory, so a write in the
worktree lands in the origin. node_modules is only safe there while the branch does not
change dependencies — a pnpm install in the worktree mutates the origin's tree in place.
Where they are read from
By default both tiers are read and unioned, repo last:
~/.config/wtp/.wt-copy·~/.config/wtp/.wt-symlink— your cross-repo defaults<target repo>/.wt-copy·<target repo>/.wt-symlink— committed, per-repo
--manifest-root <dir> (or $WTP_MANIFEST_ROOT) replaces discovery with that one
directory: either you named the source or the tool found it, never a blend. wtp ls prints
which tiers were used.
Commands
| Command | Does |
|---|---|
| wtp new <name> [--from <ref>] | git worktree add -b <name> .worktrees/<name>, gitignore .worktrees/, hydrate |
| wtp hydrate [path] | re-hydrate an existing worktree — after a dependency install, or one another tool created |
| wtp ls | the worktrees wtp manages; ! marks one whose directory is gone |
| wtp rm <name> [--force] | remove one and the branch it created, refusing if anything outside the manifest is uncommitted |
| wtp prune | git worktree prune |
| wtp doctor [path] [--depth n] | scan for symlink loops and invalid nested node_modules |
| wtp <cmd> --repo <path> | run new/ls/rm/prune/doctor against another repo |
| wtp ls --family | list worktrees across every repo beside this one (read-only) |
--json prints the result as JSON on stdout; every warning and diagnostic goes to
stderr, so piping into jq is always safe.
Exit codes: 0 ok · 1 the operation failed · 2 usage or invalid name · 3 doctor found
something (gate CI on this).
Working across repos
wtp normally acts on the repo you are standing in. Two flags widen that.
--repo <path> points a command at another repo — useful when a script or an agent runs from
one place but the worktree belongs somewhere else:
wtp new fix-login --repo ../api # created and hydrated over there
wtp ls --repo ../api
wtp rm fix-login --repo ../api--family surveys every repo sitting beside this one, so you can see everything at once:
$ wtp ls --family
api
fix-login fix-login /home/me/dev/api/.worktrees/fix-login
web
(none)Discovery is the filesystem, not a config file: one level up, every directory with a .git.
--family-root <dir> (or $WTP_FAMILY_ROOT) surveys somewhere else instead. It is read-only —
ls and doctor accept it, new and rm do not, because a command that mutates one repo
cannot be pointed at twenty. wtp doctor --family still exits 3 if any repo has a finding,
which makes it usable as a one-line CI gate for a whole workspace.
Use it from an AI agent
skill/SKILL.md is a ready-made agent skill — a thin wrapper that teaches an agent the six
commands, the exit codes, and the one dangerous manifest choice. Drop it in wherever your
harness looks for skills:
# Claude Code
mkdir -p ~/.claude/skills/worktree-plus
curl -o ~/.claude/skills/worktree-plus/SKILL.md \
https://raw.githubusercontent.com/kuzco77/worktree-plus/main/skill/SKILL.mdOr, if you installed the package, copy it out of node_modules/worktree-plus/skill/. The
skill shells out to the same wtp you use by hand, so an agent and a human can never drift
onto different behavior.
Library use
const { create, hydrateWorktree, ls, rm, doctor } = require("worktree-plus");
const out = create("fix-login", { cwd: "/path/to/repo" });Every function takes an injectable run(cmd, args) -> { status, stdout, stderr } and returns
a plain JSON-serializable object — the same shape the CLI prints under --json.
Why doctor exists
If a node_modules symlink ends up pointing into itself, pnpm reports
[ELOOP] too many symbolic links encountered and names a package — never the link or the
worktree that caused it. wtp doctor finds the link. Hydration itself refuses to create one:
any entry whose destination parent resolves outside the worktree is skipped before any
mkdir, rm or ln runs, because writing through an escaped parent would corrupt the
origin repo.
Development
npm test # node --test test/*.test.jsFilesystem and git mutations go through the injected run seam so unit tests never touch
disk; test/e2e.test.js then drives real git and a real filesystem to prove the argv works.
License
MIT
