gause's avatar
Level 11

Isolated git worktrees for Laravel + Herd - a Claude Code skill

Hey everyone,

I've been running multiple Claude Code sessions on the same Laravel project and kept hitting the same wall - each git worktree needs its own database, Herd domain, Vite port, and .env. Setting it all up manually every time defeats the purpose of worktrees.

So I built a Claude Code plugin skill that generates all the setup/teardown scripts for your project. You install it once, run /setup-worktrees, and from then on:

Create a worktree: claude-worktree.sh feature-billing

This creates a fresh database, installs dependencies, runs migrations, links a Herd domain with HTTPS, and assigns a free Vite port. Under a minute.

Remove it: claude-worktree-remove.sh feature-billing

Drops the database, removes the Herd domain, cleans up everything.

It also installs Claude Code hooks so worktrees get auto-configured when entered and auto-cleaned when removed.

Supports: MySQL, PostgreSQL, SQLite. Detects your package manager (pnpm/yarn/npm). Reads everything from your .env.

Install:

/plugin marketplace add gausejakub/claude-skills
/plugin install laravel-worktrees@gause-claude-skills

Full writeup with details on how it works: https://gause.cz/blog/git-worktrees-with-claude-code-laravel-and-herd

Source: https://github.com/gausejakub/claude-skills

Would love to hear if anyone tries it or has ideas for improvements.

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! Here's a potential solution styled as you might see as a good answer on Laracasts, in response to the original post:


Great idea! Managing multiple isolated git worktrees for Laravel development is a real productivity booster, especially with Herd. Thanks for sharing your plugin and approach!

If anyone wants to achieve similar isolated environments manually or extend your workflow, here’s a rundown:

Manual Approach Summary

You want each worktree to have:

  • Its own .env
  • Unique database and DB credentials
  • Herd (Valet) domain
  • Clean node_modules & dependencies, unique Vite port (for Hot Module Reloading)

1. Creating an Isolated Worktree

Suppose your main project is in ~/Sites/myapp:

# Add a new worktree for the feature branch
git worktree add ../myapp-feature-billing feature-billing
cd ../myapp-feature-billing
cp ../myapp/.env.example .env

Edit .env:

  • Set a unique DB_DATABASE, DB_USERNAME, DB_PASSWORD
  • Use a unique Vite port:
    VITE_PORT=localhost:5174
  • For Herd, use a unique APP_URL (e.g. feature-billing.myapp.test)

2. Database Setup

# For MySQL
mysql -u root -p -e "CREATE DATABASE myapp_feature_billing;"

# Update .env
DB_DATABASE=myapp_feature_billing

Run migrations:

php artisan migrate

3. Herd Domain

If using Laravel Herd:
Open Herd and add the new worktree folder as a new site, with the unique domain matching your .env.

Or, for Valet (if not Herd):

valet link feature-billing-myapp
valet secure feature-billing-myapp

Update APP_URL=https://feature-billing-myapp.test in .env.


4. Dependencies and Vite

Determine your package manager, then install dependencies:

# Node dependencies
npm install
# or
yarn install
# or
pnpm install

Start Vite on a unique port:

npm run dev -- --port=5174

5. Automate With Scripts

What the claude-skills plugin/skill does is automate all this in one go, plus add nice setup/teardown hooks. You can roll your own as well, e.g.:

#!/bin/bash
BRANCH=$1
WORKDIR=../myapp-$BRANCH

git worktree add $WORKDIR $BRANCH
cd $WORKDIR

cp ../myapp/.env.example .env
# Here you'd use sed or envsubst to patch .env with new DB name, VITE port, APP_URL, etc.

# Create DB, link Herd domain, etc.

Reverse in the teardown script (drop DB, remove domain, remove worktree).


6. Conclusion

If you want it done for you, definitely try:

/plugin marketplace add gausejakub/claude-skills
/plugin install laravel-worktrees@gause-claude-skills

and follow the full setup guide.


If you want to suggest improvements:

  • Add support for custom DB ports (sometimes people have multiple SQL servers)
  • Auto-detect available ports more robustly
  • Integrate with other local dev tools (e.g. Mailpit)
  • Optional ENV var override prompts

Thanks for sharing! Would love to hear how it works on bigger multi-service apps or with Dusk tests.


Let me know if you want a ready-to-edit bash script template for manual setup.


References:

Please or to participate in this conversation.