worktree-ports

Resolves stable per-app localhost ports for monorepo git worktrees.

1.2k|117|Updated Mar 22, 2025
One-click install
npx skills add https://github.com/FranciscoMoretti/sparka --skill worktree-ports
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: worktree-ports
Source: https://github.com/FranciscoMoretti/sparka/tree/main/.agents/skills/worktree-ports
Command: npx skills add https://github.com/FranciscoMoretti/sparka --skill worktree-ports

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and assets (resource) components.

What problem does it solve?

Running multiple git worktrees of the same monorepo causes port collisions between local dev servers, forcing developers to guess or hardcode ports. This Skill assigns deterministic, slot-based ports per app so every worktree gets its own non-conflicting localhost URLs.

Core Features & Use Cases

  • Deterministic Port Assignment: Computes each app's port from a worktree slot, a base port, and a per-app offset defined in .worktree-env.json.
  • Environment Variable Injection: Wraps dev commands to export PORT, app URLs, and cross-app URL templates like {apps.chat.url} before the app starts.
  • Runtime Discovery: The bun dev:info --json command reports the active slot and every app's resolved URL so agents never assume a port.
  • Use Case: You have three worktrees of a monorepo with chat, site, and electron apps. Set the slot variable in each worktree's env file, start apps via the root bun dev* scripts, and each worktree serves its apps on its own port range without conflicts.

Quick Start

Ask the agent to run bun dev:info --json and then start the chat app using the resolved worktree URL and port.

Frequently Asked Questions about worktree-ports

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid port conflicts between git worktrees?

Assign each worktree a numeric slot via an environment variable, then compute ports as base plus slot times stride plus a per-app offset. This skill's scripts automate that calculation from a .worktree-env.json config file.

How do I find which port my local app is running on?

Run bun dev:info --json before accessing any local app. It returns the active worktree slot and each app's resolved URL and port, so you never need to assume a hardcoded port.

How do I pass the correct PORT and app URL to a dev server?

Start apps through the root bun dev scripts, which load .env.worktree.local and .env.local before the wrapper runs. The wrapper exports every variable declared under the app's exports, including PORT and cross-app URL templates.

Can one app reference another app's URL in its environment variables?

Yes, use cross-app templates like {apps.chat.url} inside an app's exports in .worktree-env.json. The shared url template itself cannot reference other apps, and unknown template variables are rejected.

Why does the worktree config reject my app offset or slot value?

Offsets must be unique and below the configured range stride, and slots must be non-negative integers. Ports must also fall within 1024-65535, so privileged base ports and out-of-range offsets throw validation errors.