cjmellor/mella-marketplace/tree/main/plugins/worktree-ready
worktree-ready
一个 Claude Code mod,会自动准备和清理 Laravel git worktree,以写时复制方式克隆依赖,并通过 Valet 或 Herd 为站点建立链接。
关于这个 mod
worktree-ready 是一个 Claude Code mod,会挂接 EnterWorktree 和 ExitWorktree 工具调用。进入 Laravel worktree 时,它以写时复制方式克隆 vendor、node_modules 和构建产物,复制 .env,仅在锁文件不同时运行 composer/JS 安装,源代码发生变化时重新构建资源,并通过 Laravel Valet 或 Herd 将 worktree 链接为独立的 HTTPS 站点,同时更新 APP_URL。退出时,如果没有需要保留的内容,它会解除站点链接并删除文件夹和分支。包含经过测试的 hooks/lib.ts 纯辅助函数,以及 hooks/register.ts 中的进入/退出流程。需要 macOS APFS 和支持插件模块的 Claude Code 构建版本。
安装
请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。
claude plugin marketplace add cjmellor/mella-marketplace claude plugin install worktree-ready
原文 / README
worktree-ready
Make a new git worktree of a Laravel app ready to use with no hands, and tidy it away when you are done.
worktree-ready is a Claude Code mod. When Claude enters a worktree of a Laravel app, it brings the worktree up to the same state as your main checkout, links it as its own .test site over HTTPS, and shows you the URL. When the worktree is exited, it unlinks the site and removes the folder if the work is finished.
Requirements
- A Claude Code build that loads plugin modules (mods).
- macOS on APFS. Dependencies are cloned with
cp -c, a copy-on-write clone, so the worktree must be on the same volume as the main checkout (worktrees under.claude/worktrees/always are). - Laravel Valet or Herd. Without one the worktree is still set up, it just is not linked.
composer, and your JS package manager, on the PATH.
What happens when a worktree is entered
The mod only acts in a linked worktree that has an artisan file. Each step is skipped when it has nothing to do.
- Clone
vendor,node_modulesandpublic/buildfrom the main checkout with copy-on-write. This takes seconds and shares disk blocks until a file changes.public/hotandbootstrap/cacheare never cloned. - Copy
.envfrom the main checkout, if the worktree has none. The worktree shares main's database. A sqlite database is shared by pointingDB_DATABASEat main's file. - Install only what changed.
composer installruns whencomposer.lockdiffers from main's, and the JS install runs when its lockfile differs. The package manager is picked from the lockfile (bun.lock,pnpm-lock.yaml,yarn.lockorpackage-lock.json). - Build assets only when needed. The
buildscript runs when the worktree'sresources/,package.jsonor Vite, Tailwind, PostCSS or TypeScript config differ from main's working tree, or when main has nopublic/build. - Link and secure. The site is linked as
<project>-<worktree>(for examplekandu-purring-crafting.test), secured, and checked againstlinks. The wordworktreeis never part of the name. A name that already points at a different folder is left alone and reported.APP_URLin the worktree's.envis set to the new URL.
Claude does not get control back until this finishes, as with a SessionStart hook, so its first command in the worktree already has what it needs. Progress shows under the prompt.
A worktree that a session starts in (claude --worktree) is set up the same way.
What happens when it is exited
Whether the exit keeps or removes the worktree, the site is unsecured and unlinked, and the mod checks that it is gone from links.
If the exit kept the worktree, the mod then removes the folder and its branch when there is nothing to lose: no uncommitted changes, and the branch has commits of its own that are merged into the default branch. A worktree you entered and left without committing is kept. Anything else is kept, and you are told why once. The same check runs for leftovers at the start of the next session, along with the links of worktrees whose folder no longer exists. Only worktrees under the project's .claude/worktrees/ that the mod set up are ever removed.
Options
| Option | Default | What it does |
|--------|---------|--------------|
| Site tool | auto | valet, herd or auto. Auto uses whichever is installed and does nothing when both are, with a toast asking you to choose. |
Limits
- A worktree whose branch was squash-merged is reported as not merged, because its commits are not in the default branch's history. It stays until you remove it.
- A session that ends without exiting the worktree leaves it marked active, so it is kept.
- Herd's
linksoutput is assumed to match Valet's table. It has not been tried. - The whole flow was tested against a faked machine. It has not run against a real Herd.
Development
The pure helpers (link names, .env edits, the links table, lockfile and asset checks) are in hooks/lib.ts, and the enter and exit flows in hooks/register.ts. Both are covered by tests that fake the file system, git, composer, the package manager and Valet:
claude plugin validate plugins/worktree-ready
claude plugin test plugins/worktree-ready
License
MIT
