Herd a worktree
The agents view already isolates each background agent in its own git worktree
under .claude/worktrees/<name>. This skill adds the Laravel-runnable layer the
harness does not: a Herd .test host, a .env rewritten for that host, and
installed dependencies. Run it from inside the worktree you want to serve.
What it does (on --apply)
- Derives a site name
<project>-<worktree>and hosthttp://<site>.test. - Copies
.envfrom the main checkout if the worktree doesn't already have one (worktrees created after first run get.envautomatically, see below). - Rewrites
APP_URL,SESSION_DOMAIN, appends toSANCTUM_STATEFUL_DOMAINS(only if that key exists), setsSESSION_SECURE_COOKIE=false, and setsVITE_DEV_URL=http://localhost:<port>with a per-worktree port (5176-5275, stable per worktree name) so multiple worktree dev servers can run at once. Laravel readsVITE_DEV_URLfrom this root.env; Vite loads env from its own dir, so the skill also writes.env.local(sameVITE_DEV_URL+APP_URL) into every tracked Vite-config dir (e.g.themes/dr/).--downremoves them. - Adds
.envto the main checkout's.worktreeincludeso future worktrees get it copied in automatically (the cheap, always-on half of the setup). herd link <site>— HTTP only (noherd secure, to match Vite).composer install(ifcomposer.json) andbun install(ifpackage.json).php artisan config:clear+cache:clear(ifartisan).
It does not start Vite. Start the frontend yourself with bun run dev when
you need it; it binds to this worktree's port automatically (vite.config.ts
reads VITE_DEV_URL from the .env.local the skill wrote), and the PHP/Twig
side loads dev assets from the same URL via the root .env.
Steps
Run from inside the worktree. The skill is idempotent and safe to re-run, so apply directly (no need to preview first):
bun ~/.claude/skills/herd-worktree/herd.ts --apply
Then open the printed http://<site>.test. That single command copies/rewrites
.env, writes per-worktree .env.local for each Vite project, herd links the
site, and installs dependencies.
Optional variants:
bun ~/.claude/skills/herd-worktree/herd.ts # plan only (changes nothing)
bun ~/.claude/skills/herd-worktree/herd.ts --down # tear down before removing the worktree
bun ~/.claude/skills/herd-worktree/herd.ts --apply --force # run outside .claude/worktrees/
Notes
- Guard: refuses to run outside
.claude/worktrees/unless you pass--force. This prevents it from ever touching your main checkout's.envor Herd site. - Idempotent: re-running
--applyis safe (no duplicate Sanctum domains, etc.). - This is the on-demand half of a hybrid setup. The always-on half is the
.env->.worktreeincludecopy, which needs no skill once seeded. - Source of truth lives in the
.claudebackup repo atskills/herd-worktree/; it is copied to~/.claude/skills/herd-worktree/to be runnable. Re-run the sync after editing.