Worktrees worktrees
Create, find and clean up git worktrees and the leftovers agents keep. Use before starting parallel work in a worktree, after a pull request merges, at the end of a session, and whenever the disk is filling up.
- Our test
- —
- not tested yet
- GitHub stars
- 20k
- elizaos/eliza
- Added by
- 0
- members
- Updated
- Dec 6
- commit e932464
- Content
- 1 file
- no scripts · 11 KB
- License
- MIT
- free to use
What our test found
Not tested yet. Our model tries every skill on a realistic request and scores the result, the most popular skills first. Until then, the safety checks on the right still apply.
name: worktrees description: Create, find and clean up git worktrees and the leftovers agents keep. Use before starting parallel work in a worktree, after a pull request merges, at the end of a session, and whenever the disk is filling up.
Worktrees
Every worktree of a repository is listed in .worktrees.json at the main worktree's root, ignored by git: its path, branch, base, creation time, purpose and the agent that made it. git worktree list is the truth; each vibestack worktrees or vibestack clean adopts a worktree the registry lacks and drops one git no longer has. Both are commands of the vibestack tool: run them as pnpm exec vibestack …, adding --json for a script.
Registration
Registration does not wait for anyone to remember it. vibestack link, the postinstall of every Vibestack project, installs a git post-checkout hook that runs on each git worktree add, whichever agent or person runs it, and records the worktree's branch, creation time and maker: the agent its environment names, else the agent whose directory it is in (~/.codex, ~/.gemini/antigravity, ~/.grok, ~/.cursor, <main>/.claude/worktrees, <main>/.muse/worktrees, which the project's .gitignore ignores), else human at a terminal, else unknown. A worktree made again at a path an old one had gets a fresh entry, and no later checkout changes an entry: git reports a checkout out of an unborn branch (git switch --orphan, or the first one after git worktree add --orphan) as it does a new worktree, and the entry made since the worktree's own git directory stays. The hook never fails git and stays silent. git worktree add --no-checkout runs no hook; the next vibestack worktrees adopts that worktree instead.
What link installs, all in the clone's git directory and never committed:
.git/vibestack-hook, the launcher: this clone'svibestack, with its Node and the Vibestack the main worktree installed baked in, so it runs in a worktree with nonode_modules. Every hook reaches it through one line that does nothing where it is missing, a hook's call does nothing where the Vibestack it names or Node is gone, and a checkout that made no worktree ends before Node starts.linknever writes one that names a missing file, even from a program that bundled it, nor one for an installed Vibestack from before the hook, which it runs once to see.vibestack doctorwarns when the Vibestack it names is gone, as afternode_modulesis deleted (pnpm installputs it back), and when that Vibestack has no hook, as when a worktree upgraded before the main worktree did: upgrade or rebuild it there and runvibestack link.- On git 2.54 or later, the config hook
hook.vibestack-worktrees, which runs beside anypost-checkoutscript and touches none. - On older git,
.git/hooks/post-checkout, only where there is none, or in place of an older copy of Vibestack's own (also in pre-commit'spost-checkout.legacy, while pre-commit's hook is in front to run it). Lines you add to that script stay:link, a newer git anduninstallchange or remove only the marker comment and the line that runs the launcher, and delete the file only when a shebang is all that is left. Another tool's hook is never moved or changed, since husky v4, Git LFS and dispatchers read their own name. With one there, or acore.hooksPathoutside.git(a tracked.githooks/, husky's.husky/_),vibestack doctorwarns and names the one line to add and the file to add it to (for husky,.husky/post-checkout); the line is safe to commit, as it does nothing in a clone without the launcher. A backup that no hook manager runs, like lefthook'spost-checkout.old, does not count.
The hook belongs to the git that ran link: where an app runs an older git than the one on your PATH, the worktrees it makes wait for the next vibestack worktrees to adopt them.
vibestack init and vibestack upgrade add one SessionStart hook per agent to the project's tracked hook files, beside any of the project's own, and change no other command there. It records the session's id on the worktree's entry and, in a linked worktree with no purpose, prints the note command for it, through .git/vibestack-hook:
| Agent | File | Before it runs | |---|---|---| | Claude Code | .agents/claude-settings.json, linked as .claude/settings.json | vibestack link in that worktree, as its pnpm install runs, since the link is not committed | | Codex | .codex/hooks.json | trust the project, then the hook in /hooks | | Antigravity | .agents/hooks.json | nothing | | Cursor and Grok Build's Agents Window | .cursor/hooks.json | trust the workspace | | Gemini CLI | .gemini/settings.json | approve the project's hook when Gemini CLI asks, again after its command changes | | Factory Droid | .factory/hooks.json | trust the folder in the TUI; droid exec runs it untrusted |
Grok Build in the terminal runs both Claude Code's and Cursor's hooks once the project is trusted (/hooks-trust), and reads no SessionStart output: Cursor's records its session, Claude Code's does nothing, and neither asks for a purpose. T3 Code runs Codex and Claude Code, whose hooks it inherits. Grokbot (.grokbot) and Muse (.muse) get no agent hook. The git hook registers every agent's worktrees, but where the session asks for nothing, in Grok Build, Grokbot and Muse, give a worktree its purpose yourself with note as soon as you are in one.
To check it: vibestack doctor shows worktree hook; vibestack worktrees shows the agent of each worktree. vibestack worktrees hook uninstall removes the git hook, the launcher and Vibestack's entries in the agent hook files (commit the files it changed), and sets vibestack.worktreeHook=false in the clone's git config: link installs nothing there again, init and upgrade leave the hook files you committed as they are, and doctor reports it off. git config --local --unset vibestack.worktreeHook and vibestack link turn it back on.
When
| When | Run | |---|---| | Before parallel work | vibestack worktrees, to reuse a worktree that fits; else vibestack worktrees add <name> --purpose "<what it is for>" | | Working in a worktree you did not make with add | Straight away, the note command the SessionStart hook prints, or "$(git rev-parse --path-format=absolute --git-common-dir)/vibestack-hook" worktrees note . "<what it is for>" from anywhere inside it, which needs no install | | After a pull request merges | git fetch --prune, then vibestack clean and vibestack clean --apply | | At the end of a session | vibestack clean, and say in your report what it can reclaim | | The disk is filling up | vibestack clean --idle --orphans --machine; read every line before adding --apply |
Classes
vibestack clean gives each worktree one class and removes only prunable and integrated by default: idle with --idle, and the agents' orphans with --orphans. It never removes the main worktree, the one it runs in, a locked one (an agent holds it), one that another worktree sits inside, one whose ignored files hold a git repository with work found nowhere else, one with uncommitted or untracked changes (whatever status.showUntrackedFiles says), one used in the last hour, or a long-lived branch (main, master, develop, trunk, stable, release/* and the base's own name). Removing a worktree deletes its ignored files too: node_modules, builds and local environment files.
| Class | Means | Removed | |---|---|---| | moved | its repository moved, so git's links to it broke | never: --apply relinks it with git worktree repair | | holds | another worktree of the repository is inside its directory, where removing it would delete that one's files | never | | nested | it would be integrated or idle, but a git repository among its ignored files (a clone under vendor/, say) has changes or commits no remote of its own has; the detail names it | never: push or move that repository, and it is removable again | | offline | its directory is missing but may be on a disk that is not mounted | never | | prunable | its directory is gone for certain | by default, with git worktree remove | | stranded | its directory is gone, but its detached HEAD holds commits no branch, tag or remote has | never: git branch <name> <head> keeps them, and it is prunable after | | integrated | commits were made in it, and its head is in the base branch: merged, cherry-picked, squashed (merging it changes nothing), or a merged pull request's head. A fresh checkout of the base is not | by default, with git worktree remove, and its branch | | idle | clean, every commit pushed, untouched for 14 days (--days) | with --idle; the branch stays | | gone | its upstream was deleted but its commits are not in the base | never: read it and decide | | orphans | a directory under ~/.codex/worktrees, ~/.gemini/antigravity/worktrees, ~/.grok/worktrees or ~/.cursor/worktrees that holds no clone and whose every .git names a repository no longer at its path for certain: not one this repository can relink, nor one on an unmounted disk. A repository moved without its worktrees looks the same from another one: run vibestack clean --apply in it first, which relinks them | with --orphans, unless a git repository inside it has changes or commits no remote of its own has: then it is listed as kept, with that repository, until it is pushed or moved |
Sizing orphans and the rest of the machine is slow, so it waits for a flag: --orphans sizes the orphans, and --machine also sizes what else fills the disk (transcripts, sessions, Android emulator images, Gradle caches, the pnpm store and, on a Mac, the iOS Simulator's devices and Xcode's DerivedData), each with the command that frees it. --machine --apply deletes only stale entries of Vibestack's own cache (e2e-* checkouts and logs older than 7 days, program builds abandoned for an hour) and none of the rest; tell the user what they take.
Habits
- Create a worktree with
vibestack worktrees add, or in your agent's own place (claude --worktree, Codex's worktrees). Never in/tmpor a session's scratch directory: it is lost on reboot and leaves git a dead entry. - Give each worktree a purpose, so whoever finds it knows whether it is done:
addrecords it, andnotedoes for one your agent made. - Never
rm -rfa worktree, and nevergit worktree pruneafter moving a repository:git worktree repairrelinks it.git worktree removerefuses one with changes;vibestack clean --applyuses it. - Remove your worktree once its pull request merges.
vibestack cleannever deletes a remote box's sandbox: in a repository enabled for remote boxes, runvibestack-remote gcaftervibestack clean --apply, and leavegc --yesto the user ().vibestack doctorcounts the stale worktrees; zero is the goal.