Skip to content
ISSUE #20 Oct 10, 2025 5 MIN READ

How I Vibe Code With 3 AI Agents Using Git Worktrees (Without Breaking Anything)

You know that feeling when you’re vibe coding with Claude Code and it suggests a “minor database refactor” – then suddenly your entire local database is corrupted?

Or when you want to test Claude Code’s approach versus Codex’s approach, but switching branches means losing all your test data?

I was so tired of this dance.

So I built a solution.

Next.js Worktrees Manager – a bash script that creates completely isolated development environments with their own PostgreSQL databases.

Let me show you exactly how I vibe code with multiple AI agents simultaneously.

.

.

.

The Problem Nobody Talks About

Here’s what happens every single day when you’re vibe coding:

You’re in the zone with an AI coding agent.

Claude Code, Codex, Cursor, Windsurf – doesn’t matter which.

The agent suggests changes.
You accept them.
Then you realize it modified your database schema.

Now what?

git reset --hard?

Sure, that fixes the code. But your database?

Those migrations already ran.
That test data is gone.
Your local environment is now broken.

The worst part?

You want to compare different AI agents’ implementations.

But without git worktrees, that means:

  • Constantly switching branches
  • Re-running migrations
  • Losing test data
  • Fighting port conflicts
  • Wasting hours on environment management instead of coding

Regular git workflows weren’t built for this level of experimentation.

.

.

.

The Solution: Git Worktrees + True Isolation

Next.js Worktrees Manager does one thing brilliantly:

It extends git worktrees with database isolation.

Each worktree gets:

  • Its own working directory (via git worktrees)
  • Its own PostgreSQL database (cloned from your main)
  • Its own port assignment (run multiple dev servers simultaneously)
  • Its own .env configuration

Git worktrees handle the code isolation. My script handles everything else.

.

.

.

Installation (30 Seconds)

git clone https://github.com/nathanonn/next-worktrees-manager.git
cd next-worktrees-manager
chmod +x worktrees.sh

Done.

.

.

.

Let Me Show You The Magic

Say you want three different AI agents to implement authentication.

Here’s the entire process:

./worktrees.sh setup \
  --branches claude-auth,codex-auth,gemini-auth \
  --db-url postgresql://localhost:5432/myapp

Watch what happens:

  1. Creates three worktrees in worktrees/ directory
  2. Clones your database three times
  3. Updates each .env with the correct database URL
  4. Assigns ports 3001, 3002, and 3003

Time elapsed: Less than 60 seconds.

Now run all three simultaneously:

cd worktrees/claude-auth && PORT=3001 npm run dev
cd worktrees/codex-auth && PORT=3002 npm run dev
cd worktrees/gemini-auth && PORT=3003 npm run dev

Open your browser:

  • http://localhost:3001 – Claude’s implementation
  • http://localhost:3002 – Codex’s implementation
  • http://localhost:3003 – Gemini’s implementation

Test them side-by-side.

Break things.

Each environment is completely isolated.

.

.

.

The Cleanup Is Even Better

Every setup creates a group ID like wt-20251008-191431.

When you’re done experimenting:

./worktrees.sh clean --group wt-20251008-191431

[Screenshot 3 placeholder: Cleaning up worktrees and databases with a single command]

One command. All worktrees deleted. All databases dropped. Your main branch untouched.

It’s like those experiments never happened.

.

.

.

Use Cases That Actually Matter

Testing AI Agent Outputs

Stop wondering which AI agent produces better code. Test them simultaneously:

./worktrees.sh setup \
  --branches gpt5-approach,claude-opus-approach,gemini-3-approach \
  --db-url postgresql://localhost/myapp

Run all three.

See which implementation is cleaner.

Make an informed decision.

Feature Variations

Building multiple payment providers?

Keep them isolated:

./worktrees.sh setup \
  --branches stripe-checkout,paypal-checkout,crypto-checkout \
  --db-url postgresql://localhost/ecommerce

No more commenting out code.

No more environment variable juggling.

Production Debugging

Need to reproduce a production bug safely?

./worktrees.sh setup \
  --branches prod-bug-fix \
  --db-url postgresql://localhost/production_copy \
  --setup-cmd "npm run seed:production"

Break things freely.

Your main environment stays clean.

Team Development

Multiple developers. Same codebase. Zero conflicts:

./worktrees.sh setup \
  --branches alice/feature,bob/feature,charlie/fix \
  --db-url postgresql://localhost/team_db

Everyone gets their own database.

No more “waiting for migrations.”

.

.

.

The Features That Matter

Custom Ports

./worktrees.sh setup \
  --branches v1,v2,v3 \
  --db-url postgresql://localhost/db \
  --start-ports 3000,4000,5000

Auto-Prisma

If you use Prisma, it runs prisma generate automatically:

./worktrees.sh setup \
  --branches test \
  --db-url postgresql://localhost/db \
  --auto-prisma on  # Default

Custom Setup

Need to install packages or seed data?

./worktrees.sh setup \
  --branches experiment \
  --db-url postgresql://localhost/db \
  --setup-cmd "npm install && npm run seed"

Force Recreate

Testing the same branch repeatedly?

./worktrees.sh setup \
  --branches test \
  --db-url postgresql://localhost/db \
  --force

.

.

.

Safety Built In

The script protects you from yourself:

  • Local databases only – Can’t accidentally touch remote databases
  • Clean git check – Won’t create worktrees with uncommitted changes
  • Connection handling – Safely terminates active connections
  • Dry run mode – Preview with --dry-run
  • Confirmation required – Bulk cleanup needs --yes

.

.

.

Performance Reality Check

Max 10 branches per setup.

Why?
PostgreSQL connection limits.
But honestly, if you need more than 10 parallel experiments, you have bigger problems.

Database cloning is instant.

PostgreSQL’s CREATE DATABASE ... TEMPLATE uses copy-on-write.

Even gigabyte databases clone in seconds.

.

.

.

Your New Daily Commands

# Create experiment
./worktrees.sh setup --branches feat/test --db-url postgresql://localhost/db

# Check status
./worktrees.sh status --group wt-20251008-191431

# Get start commands
./worktrees.sh start --group wt-20251008-191431  

# Clean up
./worktrees.sh clean --group wt-20251008-191431

# Nuclear option
./worktrees.sh clean --all --yes

.

.

.

Who Actually Needs This

You need this if you:

  • Work with AI coding agents daily
  • Test multiple implementations regularly
  • Value experimental freedom
  • Hate database conflicts
  • Want true environment isolation

You don’t need this if you:

  • Never experiment
  • Work on simple CRUD apps
  • Don’t use PostgreSQL
  • Enjoy manual environment management

.

.

.

The Bottom Line

Stop tiptoeing around your development database.

Stop losing hours to environment setup.

Stop choosing between experimentation and stability.

This script gives you true isolation in under a minute. Break things. Test wildly. Your main branch stays untouched.

Get the script: github.com/nathanonn/next-worktrees-manager

Your future self – vibe coding with three AI agents simultaneously using git worktrees – will thank you.


P.S. – I’ve used this script to test different AI agent implementations. Not once has my main database been corrupted. That peace of mind alone makes vibe coding actually enjoyable again.

Nathan Onn

Freelance web developer. Since 2012 he’s built WordPress plugins, internal tools, and AI-powered apps. He writes The Art of Vibe Coding, a practical newsletter that helps indie builders ship faster with AI—calmly.

Join the Conversation

Leave a Comment

Your email address will not be published. Required fields are marked with an asterisk (*).

Enjoyed this post? Get similar insights weekly.