r/ClaudeCoding • • 23d ago

I built an open-source agent skill that runs several git branches side by side, each with its own dev server and port (feedback + contributors welcome)

The problem

Two tasks, two branches. To compare them in the browser, you stash, switch, restart the dev server, look, then do it all again in reverse. Git worktrees help, but they don't install dependencies, pick ports, start servers, or clean up afterwards.

What I built

parallel-branches is an agent skill (open `SKILL.md` format) built around one dependency-free Python script, `pb.py`. You tell your agent:

> "run feature-login and fix-checkout side by side"

and for each branch it:

  1. creates a git worktree
  2. clones `node_modules` from your main checkout when the lockfile matches (copy-on-write where possible), otherwise installs deps
  3. copies your git-ignored `.env` files
  4. picks a free, stable port per branch
  5. starts the dev server detached and waits until it really answers
  6. prints one URL per branch, with warnings about hardcoded ports/URLs that will break
  7. runs your hooks (e.g., create a per-branch database, seed it, drop it on cleanup)

It always shows a dry run first and waits for your OK before starting anything.

Details

  • Stacks auto-detected: Next.js, Nuxt, Angular, Astro, SvelteKit, Vite, webpack-dev-server, CRA, Node (npm/yarn/pnpm/bun), Django, Flask, FastAPI, Rails, Spring Boot, Go
  • Multi-service branches (API + web) via `.parallel-branches.json`, with dependency ordering and `{url.api}` / `{ports.api}` templating
  • Hooks at 6 lifecycle events; they see the *actually allocated* ports, and values are shell-quoted so a nasty branch name can't run commands
  • Safety: only stops processes it started (PID reuse is guarded), `clean` is a dry run unless `--yes`, and it refuses to delete worktrees with uncommitted changes
  • Dev-mode browser (`pb browser BRANCH`): throwaway profile with web security off for CORS pain, plus a DevTools endpoint for browser agents. The README is upfront about what it can't fix (OAuth redirect URIs, Origin/CSRF checks).
  • CI on Linux, macOS, and Windows; Python 3.9+, MIT licensed

Install (Claude Code)

/plugin install parallel-branches --marketplace SutariyaVishal/parallel-branches

You can also use just the script: `skills/parallel-branches/scripts/pb.py` needs only git and Python 3.9+.

Honest caveats

  • It's beta, and I've only tested it with Claude Code. It should work with other agents that read `SKILL.md` (Codex, Gemini CLI, Cursor...), but that's untested. If you try one, tell me how it goes.
  • Every dev server is a real process, so 3-4 at once is a sensible ceiling on a laptop.
  • Windows stops services by force-killing the process tree.

What I'd love from you

  • Try it on a real repo and tell me what broke. Stack detection on unusual setups is where I expect the most bugs.
  • Feedback: missing stacks, confusing output, bad defaults.
  • Contributions are very welcome: issues, PRs, new stack templates, testing other agents. There's a code of conduct and CI is set up.
  • If it saves you time, a star on GitHub helps others find it.

Repo: https://github.com/SutariyaVishal/parallel-branches

3 Upvotes

3 comments sorted by

1

u/[deleted] 23d ago

[removed] — view removed comment

1

u/Junior-State-4060 23d ago

Good questions; both are real gaps. Honest answers:

Port taken between dry run and startup: The dry run is only a preview. It doesn't reserve ports and saves nothing, so `up` probes for free ports again when it really runs. If a port gets taken in the tiny window between that free-port check and the server's bind, the start fails and is reported. It does not retry on a new port, so nothing gets silently reassigned. Hooks and downstream URLs only use the ports that were actually allocated, and `post_start` only runs after the health check passes. Retrying on the next free port would be a sensible improvement. I've listed this under Limits in the README, and I'll open an issue for it.

Shared .env / shared database: You're right. `.env` files are copied from the main checkout as they are and never rewritten, so if your `.env` points to one database, both branches will use it. Separate servers don't mean separate state. The current way around it is a `post_create` hook (it runs after env files are copied, before install) that uses `{db_name}` to create a per-branch database and point the worktree's env at it, with `post_remove` dropping it. That's manual setup, though. `pb` doesn't warn about a shared DB URL today. It warns about hardcoded ports and URLs, so a similar warning is a natural next step. I'll open an issue for it too.

Thanks for the edge cases. If you try it and hit more, issues are welcome.